3

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

but I want: enter image description here

Charles
  • 537
  • 6
  • 21

1 Answers1

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

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

TimStuart
  • 674
  • 3
  • 7
  • 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 Jan 18 '19 at 14:26
  • 1
    Yes, that function is part of Seurat v3. This answer will only work for v3 – TimStuart Jan 18 '19 at 14:37
  • 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 Jan 18 '19 at 15:34
  • 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 Jan 18 '19 at 15:36
  • 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 Jan 18 '19 at 16:30
  • 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 Jan 20 '19 at 15:11
  • 1
    Can you confirm Seurat v3 has actually been installed and loaded before running UpdateSeuratObject? – TimStuart Jan 21 '19 at 14:33