How do I prevent the FeatureHeatmap function from the Seurat package, from sorting my data groups in alphabetical order when plotting data? How can I prevent a function from sorting my data groups (factors) in alphabetical order without affecting the integrity of the data? I am analysing single cell RNA sequencing data using Seurat 2.3.4. I want to be able to visualise the expression of two genes, Gene1 and Gene2 across cell clusters using the FeatureHeatmap() function from Seurat. I have assigned to the metadata slot of my Seurat object the factors or conditions being tested in the experiment. However on the resulting FeatureHeatmap plot, the data are sorted and grouped in alphabetical order to my disfavour. I have attempted a solution given on stackoverflow such as the one below:

conditions &lt;- c(rep("WTNaClctrl", 1229), 
               rep("WTBlu", 1328),
               rep("ILKOBlu", 349))


conditions &lt;- as.data.frame(conditions)

seurat_object@meta.data$conditions &lt;- factor(conditions$conditions, levels=unique(conditions$conditions))


When I use the FeatureHeatmap() function, the plot still sorts the data groups in alphabetical order:

FeatureHeatmap(seurat_object, features.plot = c("Gene1", "Gene2"), 
               pt.size = 0.25,  
               group.by = "conditions",
               max.exp = 3)


This plot gets produced: 

I would like groupings not to appear in alphabetical order as such:


As previously suggested StackExchange, I have tried to upgrade my Seurat object to Seurat V3:

UpdateSeuratObject(Seurat_object): 
Object representation is consistent with the most current Seurat version.

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’.


Thank you in advance for any suggestions.
I had this same issue. I reordered the levels and that worked for most functions, but would switch back with the FeatureHeatmap. Turns out there is a line in the function that changes it to a character. 

I ended up making a "new" function and just changed that one line from:

data.plot$ident &lt;- as.character(x = object@ident)


to:

data.plot$ident &lt;- object@ident


Once that was fixed, the order that I assigned worked out just fine.