Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-18T14:26:57.893Z
Answers.Text: 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**
Answers.UserDisplayName: Charles
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-18T14:37:15.883Z
Answers.Text: Yes, that function is part of Seurat v3. This answer will only work for v3
Answers.UserDisplayName: TimStuart
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-18T15:34:20.087Z
Answers.Text: 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**
Answers.UserDisplayName: Charles
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-18T15:36:02.540Z
Answers.Text: 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?
Answers.UserDisplayName: Charles
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-18T16:30:56.827Z
Answers.Text: 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
Answers.UserDisplayName: TimStuart
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-20T15:11:52.583Z
Answers.Text: 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?
Answers.UserDisplayName: Charles
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-21T14:33:55.307Z
Answers.Text: Can you confirm Seurat v3 has actually been installed and loaded before running `UpdateSeuratObject`?
Answers.UserDisplayName: TimStuart
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-18T14:04:22.837Z
Answers.LastActivityDate: 2019-01-18T14:04:22.837Z
Answers.UserDisplayName: TimStuart
Body: <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>
  
Tags: <scrnaseq><seurat><ggplot2>
Title: How to set the position of groups in a Seurat object on a FeatureHeatmap plot
ThreadText: # 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:
  [![enter image description here](https://i.sstatic.net/HsHVd.png)](https://i.sstatic.net/HsHVd.png)
  
  but I want:
  [![enter image description here](https://i.sstatic.net/QFkwQ.png)](https://i.sstatic.net/QFkwQ.png)
  
  **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')
  
  ```
  
  [![enter image description here](https://i.sstatic.net/c51So.png)](https://i.sstatic.net/c51So.png)
  
  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')
  
  ```
  
  [![enter image description here](https://i.sstatic.net/Rg2BG.png)](https://i.sstatic.net/Rg2BG.png)
  
  > **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"` **@username_1**  
  > **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. **@username_1**  
  > **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`?  
  
  ---
  
  