<p>DimPlot returns a ggplot object, so ggplot functions can be applied to it. You can change the legend position like this:</p>
<pre><code>DimPlot(data) + theme(legend.position = &quot;top&quot;)
# or
DimPlot(data) + theme(legend.position = c(.1, .9))
</code></pre>

CC BY-SA 4.0
2023-01-06T17:15:17.163Z
Thank you so much, problem solved. I was trying to solve it from DimPlot() method.
cst
CC BY-SA 4.0
2023-01-06T10:55:17.423Z
2023-01-06T10:55:17.423Z
Cloudberry
<p>I have a Seurat object and plotted the Dimplot for UMAP visualization for 2 variables, as shown in the image below.</p>
<p><a href="https://i.sstatic.net/2gj8q.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2gj8q.png" alt="enter image description here" /></a></p>
<p>Now, the problem is that I want the group by variables such as <code>Non-responder and Responder</code> and <code>anti-CLTA4, anti-CLTA4+PD1, anti-PD1</code> on the top of the UMAP plot and not on the right side. My desired output would look like the following.</p>
<p><a href="https://i.sstatic.net/imshU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/imshU.png" alt="enter image description here" /></a></p>
<p>The timely help is highly appreciated, many thanks.</p>

CC BY-SA 4.0
2023-01-05T15:48:17.587Z
If you plan to export the graph anyway, the easiest way could be to edit it with a vector graphics program. The other option is to save the `ggplot` object returned by `Dimplot()` and modify it to suit your needs.
Cloudberry
CC BY-SA 4.0
2023-01-06T04:09:42.280Z
Could you please provide an example of Seurat `DimPlot()` to `ggplot` ? @Cloudberry
cst
<scrnaseq><seurat><ggplot2>
How to change the position of groups colors in DimPlot of Seurat
# How to change the position of groups colors in DimPlot of Seurat

(Asked by: username_0 on 2023-01-05)

I have a Seurat object and plotted the Dimplot for UMAP visualization for 2 variables, as shown in the image below.

[![enter image description here](https://i.sstatic.net/2gj8q.png)](https://i.sstatic.net/2gj8q.png)

Now, the problem is that I want the group by variables such as `Non-responder and Responder` and `anti-CLTA4, anti-CLTA4+PD1, anti-PD1` on the top of the UMAP plot and not on the right side. My desired output would look like the following.

[![enter image description here](https://i.sstatic.net/imshU.png)](https://i.sstatic.net/imshU.png)

The timely help is highly appreciated, many thanks.

**Tags:** scrnaseq, seurat, ggplot2
> **Comments:**
> **username_1**: If you plan to export the graph anyway, the easiest way could be to edit it with a vector graphics program. The other option is to save the `ggplot` object returned by `Dimplot()` and modify it to suit your needs.  
> **username_0**: Could you please provide an example of Seurat `DimPlot()` to `ggplot` ? @Cloudberry  

---

## 1 answers

### Answer by username_1 on 2023-01-06. Score: 3 | Accepted answer

DimPlot returns a ggplot object, so ggplot functions can be applied to it. You can change the legend position like this:
DimPlot(data) + theme(legend.position = "top")
# or
DimPlot(data) + theme(legend.position = c(.1, .9))

> **Comments:**
> **username_0**: Thank you so much, problem solved. I was trying to solve it from DimPlot() method.  

---

