Seurat: Customize colors for DoHeatmap function in v3

Created on 10 Jan 2019  路  7Comments  路  Source: satijalab/seurat

Hello,
I really appreciate your efforts to make such useful tool for single cell RNA seq.
I've been using v2 for the whole time and now adjusting to v3.

I've found that DoHeatmap function has changed a bit. Previously, we were able to set colors manually through col.low ~col .high, but I've found it's missing in v3. Is it deprecated?

If so, how can I set colors manually for DoHeatmap function?

Most helpful comment

Hi,

Since DoHeatmap returns a ggplot object in Seurat v3, you can manipulate the colors by specifying the color scale. For example

library(ggplot2)
DoHeatmap(object = pbmc_small) + scale_fill_gradientn(colors = c("blue", "white", "red"))

You can also easily apply color schemes provided by other packages, such the viridis color palettes.

library(viridis)
DoHeatmap(object = pbmc_small) + scale_fill_viridis()

All 7 comments

Hi,

Since DoHeatmap returns a ggplot object in Seurat v3, you can manipulate the colors by specifying the color scale. For example

library(ggplot2)
DoHeatmap(object = pbmc_small) + scale_fill_gradientn(colors = c("blue", "white", "red"))

You can also easily apply color schemes provided by other packages, such the viridis color palettes.

library(viridis)
DoHeatmap(object = pbmc_small) + scale_fill_viridis()

Hi, I think it's currently not possible to change the color of group bar, right?

DoHeatmap(object = pbmc_small) + scale_color_manual(values=cbPalette)

No, unfortunately it's not currently possible to change those colors though we would welcome a PR for that feature if anyone's interested in implementing.

Single a google search defaults to this I thought i'd add this in case someone would be interested

DoHeatmap

group.colors = c("red", "blue") adds colors to the bar.

Does anyone know if you can sort the groups (columns) in the heatmap specifically in doheatmap?

@lwhitmore You can do this by changing the order of levels of the variable that you want to sort by.

levels(factor(object@variable_to_sort))
> levels: 1,2,3
object@variable_to_sort <- factor(object@variable_to_sort, levels=c(3,2,1))
levels(object@variable_to_sort)
> levels: 3,2,1

Follow the @andrewwbutler idea , we can do the following

mapal <- colorRampPalette(RColorBrewer::brewer.pal(11,"RdBu"))(256)
DoHeatmap(pbmc_small, 
          angle = 90,size = 3)+
  scale_fill_gradientn(colours = rev(mapal))
Was this page helpful?
0 / 5 - 0 ratings

Related issues

RuiyangLiu94 picture RuiyangLiu94  路  3Comments

milanmlft picture milanmlft  路  3Comments

Biogitte picture Biogitte  路  3Comments

whitleyo picture whitleyo  路  3Comments

rajasreemenon picture rajasreemenon  路  3Comments