单细胞分析2020寒假-毕业论文R语言seurat包

Seurat中小提琴图,热图顺序的调整

2020-01-09  本文已影响0人  生信编程日常

改变小提琴横坐标的顺序

seurat.object_copy <- seurat.object
my_levels <- c(set_your_order_of_clusters)
Idents(seurat.object_copy) <- factor(Idents(seurat.object_copy), levels= my_levels)
VlnPlot(seurat.object_copy, features = c("some_gene"))

因为顺序变了,要是想保持原来每个样本对应的颜色的话,也要改变小提琴的颜色.如:
原始的样子

VlnPlot(=combined,features = T,log = F,slot = "data",pt.size = 0)
image.png

改变顺序

combined_copy <- combined
My_levels <- c('pluripotency','mesendoderm','mesoderm','endoderm')
Idents(combined_copy) <- factor(Idents(combined_copy), levels= My_levels)
image.png

重新匹配颜色

VlnPlot(=combined_copy,features = T,log = F,slot = "data",pt.size = 0)+scale_fill_manual(values = c("#C77CFF","#7CAE00","#00BFC4","#F8766D")))

如果不知道原来的颜色:

library(scales)
show_col(hue_pal()(4)) 

Heatmap调整热图颜色为scale_fill_gradientn()

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

Heatmap调整上面bar的颜色

DoHeatmap(subset(combined_copy,downsample = 100), features = combined.markersTop50$gene,label = F,group.bar.height = 0.1,group.colors = c("#C77CFF","#7CAE00","#00BFC4","#F8766D"))

调整group顺序

combined_copy$integrated_merge_cluster <- factor(x =NC_TBXTKO_TCF7KO.combined_copy$integrated_merge_cluster, levels = c('mesoderm','endoderm','pluripotency','mesendoderm'))
DoHeatmap(subset(NC_TBXTKO_TCF7KO.combined_copy,downsample = 100), features = NC_TBXTKO_TCF7KO.combined.markersTop50$gene,label = F,group.bar.height = 0.1,group.by ="integrated_merge_cluster")
image.png
如果要修改gene的顺序的话,修改level后重新运行FindAllMarkers.
参考:
https://github.com/satijalab/seurat/issues/454

欢迎关注~

公众号二维码.jpg
上一篇下一篇

猜你喜欢

热点阅读