<p>I don't think this is possible in Seurat v2, but in v3 you can change the factor levels of the grouping variable to change the plot order:</p>

<pre><code>library(Seurat)

FeaturePlot(object = pbmc_small,
            features = head(VariableFeatures(pbmc_small), 2),
            split.by = 'groups')
</code></pre>

<p><a href="https://i.sstatic.net/c51So.png" rel="noreferrer"><img src="https://i.sstatic.net/c51So.png" alt="enter image description here"></a></p>

<p>Change the order:</p>

<pre><code>pbmc_small<span class="math-container">$groups &lt;- factor(pbmc_small$</span>groups, levels = c('g2', 'g1'))

FeaturePlot(object = pbmc_small,
            features = head(VariableFeatures(pbmc_small), 2),
            split.by = 'groups')
</code></pre>

<p><a href="https://i.sstatic.net/Rg2BG.png" rel="noreferrer"><img src="https://i.sstatic.net/Rg2BG.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2019-01-18T14:26:57.893Z
Thanks a lot. However the function `VariableFeatures` is not present in my Seurat package. I get the error: `Error in VariableFeatures(object) : 
  could not find function "VariableFeatures"` **@TimStuart**
Charles
CC BY-SA 4.0
2019-01-18T14:37:15.883Z
Yes, that function is part of Seurat v3. This answer will only work for v3
TimStuart
CC BY-SA 4.0
2019-01-18T15:34:20.087Z
How do I get the Seurat V3 package? My computer is having issue downloading it automaticaally, so I wish to download the Seurat V3 package manually and then load it. Thanks. **@TimStuart**
Charles
CC BY-SA 4.0
2019-01-18T15:36:02.540Z
Will it also be advisable that I move to Seurat V3 at this level or I may need to restart my analyses afresh and repeat all steps with Seurat V3?
Charles
CC BY-SA 4.0
2019-01-18T16:30:56.827Z
You can install v3 using devtools: `devtools::install_github(repo = 'satijalab/seurat', ref = 'release/3.0')`. I don't know how much effort it is for you to repeat analyses with Seurat v3, but you can also just update the Seurat object using `UpdateSeuratObject`. See here for more information: https://satijalab.org/seurat/essential_commands.html
TimStuart
CC BY-SA 4.0
2019-01-20T15:11:52.583Z
I obtain this: `devtools::install_github(repo = 'satijalab/seurat', ref = 'release/3.0')` : `package ‘curl’ successfully unpacked and MD5 sums checked:
Error: (converted from warning) cannot remove prior installation of package ‘curl’`. `UpdateSeuratObject(object):
Object representation is consistent with the most current Seurat version.`   
The `FeatureHeatmap()` actually uses the alphabetical order of the conditions which I provided in the metadata slot. Is there a possibility to reorder the factor levels without harming the integrity of the data in the Seurat object?
Charles
CC BY-SA 4.0
2019-01-21T14:33:55.307Z
Can you confirm Seurat v3 has actually been installed and loaded before running `UpdateSeuratObject`?
TimStuart
CC BY-SA 4.0
2019-01-18T14:04:22.837Z
2019-01-18T14:04:22.837Z
TimStuart
<p>I am analysing singe cell sequence data and I have followed this tutorial, <a href="https://satijalab.org/seurat/pbmc3k_tutorial.html" rel="nofollow noreferrer">https://satijalab.org/seurat/pbmc3k_tutorial.html</a> to perform QC and various differential analyses using the Seurat package on my data up till now.</p>

<p>How can I rearrange on the resulting plot, the order in which the groups of my samples appear when I use the <code>FeatureHeatmap()</code> function to visualise the differential gene expression of Gene1 and Gene2 across the cell clusters?</p>

<pre><code>FeatureHeatmap(object = object, features.plot = c("Gene1", "Gene2"), 
               group.by = "Conditions",
               pt.size = 0.25, key.position = "top",
               max.exp = 3)
</code></pre>

<p>produces:
<a href="https://i.sstatic.net/HsHVd.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/HsHVd.png" alt="enter image description here"></a></p>

<p>but I want:
<a href="https://i.sstatic.net/QFkwQ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QFkwQ.png" alt="enter image description here"></a></p>

<scrnaseq><seurat><ggplot2>
How to set the position of groups in a Seurat object on a FeatureHeatmap plot
# How to set the position of groups in a Seurat object on a FeatureHeatmap plot

(Asked by: username_0 on 2019-01-18)

I am analysing singe cell sequence data and I have followed this tutorial, https://satijalab.org/seurat/pbmc3k_tutorial.html to perform QC and various differential analyses using the Seurat package on my data up till now.
How can I rearrange on the resulting plot, the order in which the groups of my samples appear when I use the FeatureHeatmap() function to visualise the differential gene expression of Gene1 and Gene2 across the cell clusters?
FeatureHeatmap(object = object, features.plot = c("Gene1", "Gene2"), 
               group.by = "Conditions",
               pt.size = 0.25, key.position = "top",
               max.exp = 3)

produces:

but I want:

**Tags:** scrnaseq, seurat, ggplot2

---

## 1 answers

### Answer by username_1 on 2019-01-18. Score: 5

I don't think this is possible in Seurat v2, but in v3 you can change the factor levels of the grouping variable to change the plot order:
library(Seurat)

FeaturePlot(object = pbmc_small,
            features = head(VariableFeatures(pbmc_small), 2),
            split.by = 'groups')


Change the order:
pbmc_small$groups <- factor(pbmc_small$groups, levels = c('g2', 'g1'))

FeaturePlot(object = pbmc_small,
            features = head(VariableFeatures(pbmc_small), 2),
            split.by = 'groups')

> **Comments:**
> **username_0**: Thanks a lot. However the function `VariableFeatures` is not present in my Seurat package. I get the error: `Error in VariableFeatures(object) :    could not find function "VariableFeatures"` **@TimStuart**  
> **username_1**: Yes, that function is part of Seurat v3. This answer will only work for v3  
> **username_0**: How do I get the Seurat V3 package? My computer is having issue downloading it automaticaally, so I wish to download the Seurat V3 package manually and then load it. Thanks. **@TimStuart**  
> **username_0**: Will it also be advisable that I move to Seurat V3 at this level or I may need to restart my analyses afresh and repeat all steps with Seurat V3?  
> **username_1**: You can install v3 using devtools: `devtools::install_github(repo = 'satijalab/seurat', ref = 'release/3.0')`. I don't know how much effort it is for you to repeat analyses with Seurat v3, but you can also just update the Seurat object using `UpdateSeuratObject`. See here for more information: https://satijalab.org/seurat/essential_commands.html  
> **username_0**: I obtain this: `devtools::install_github(repo = 'satijalab/seurat', ref = 'release/3.0')` : `package ‘curl’ successfully unpacked and MD5 sums checked: Error: (converted from warning) cannot remove prior installation of package ‘curl’`. `UpdateSeuratObject(object): Object representation is consistent with the most current Seurat version.`    The `FeatureHeatmap()` actually uses the alphabetical order of the conditions which I provided in the metadata slot. Is there a possibility to reorder the factor levels without harming the integrity of the data in the Seurat object?  
> **username_1**: Can you confirm Seurat v3 has actually been installed and loaded before running `UpdateSeuratObject`?  

---

