事情的起因是我要复现一个文章的堆叠小提琴图,只不过堆叠小提琴用的是Split小提琴图,不仅展示细胞中基因的表达,也将分组展示了。首先堆叠小提琴图Seurat VlnPlot函数就可以完成:
library(Seurat)
library(dittoSeq)
library(ggplot2)
makers <- c('Ltf',"Ngp",'Ccl6','Srgn','S100a9','Mmp8',
'Cstdc4', "Ccl6",'Il1b','Chn2','Stfa2l1',
'Retnlg','Olfm4','Cd177','Top2a','Stmn1')
VlnPlot(mouse_data, features = makers,
stack=T,pt.size=0,
flip = T,
add.noise = T)+#横纵轴不标记任何东西
theme(axis.text.y = element_blank(), #不显示坐标刻度
axis.ticks.y = element_blank(),
axis.title = element_blank(),
axis.text.x = element_text(colour = 'black',size = 10,angle = 90),
legend.position = 'none')
展示分组:
VlnPlot(mouse_data, features = makers,
stack=T,pt.size=0,
split.by = 'orig.ident',
flip = T,
add.noise = T)+#横纵轴不标记任何东西
theme(axis.text.y = element_blank(), #不显示坐标刻度
axis.ticks.y = element_blank(),
axis.title = element_blank(),
axis.text.x = element_text(colour = 'black',size = 10,angle = 90),
legend.position = 'top',
legend.title=element_blank(),
legend.box.background = element_blank(),
legend.text = element_text(color="black",size=10),
legend.spacing.x=unit(0.2,'cm'),
legend.key.width=unit(0.4,'cm'),
legend.key.height=unit(0.4,'cm'),
legend.background=element_blank())
做Split小提琴图:
VlnPlot(mouse_data, features = makers,
stack=T,pt.size=0,
flip = T,
add.noise = T,
split.by = 'orig.ident',
split.plot = T)+#横纵轴不标记任何东西
theme(axis.text.y = element_blank(), #不显示坐标刻度
axis.ticks.y = element_blank(),
axis.title = element_blank(),
axis.text.x = element_text(colour = 'black',size = 10,angle = 90),
legend.position = 'none')
最近沉迷于写函数,所以写一个堆叠的函数,拼图无缝衔接,图还是很好看的,这里解决了ggplot拼图无缝衔接,网上有些函数很复杂,且没用。**本来这个帖子已经写完,然后刚好小伙伴问了一个问题,我就先抛出了,结果又有人提出加显著性的要求。
#如果要添加两组之间的显著性检验,就需要添加test=T参数,siglable和testmethod都可以自己选择
Split_Vln_stacked(mouse_data, feature = makers, split.by = 'orig.ident',
split.plot = T, pt.size = 0, size = 10,
cols = c("limegreen", "navy"),
sig_label = 'p.signif',test = T,test_method = 't.test')
#split不添加显著性,只需要test=F即可
Split_Vln_stacked(mouse_data, feature = makers, split.by = 'orig.ident',
split.plot = T, pt.size = 0, size = 10,
cols = c("limegreen", "navy"),
test = F)
#正常堆叠图,test=F,split.plot=F
Split_Vln_stacked(mouse_data, feature = makers,
split.plot = F, pt.size = 0, size = 10,
cols = dittoColors(), test = F)
此外,有了这个启发,我们是不是可以对一些基本的图进行无缝拼接呢,堆叠展示跟更体现效果,颜值也是拉满。这里以折线图为例子:
接下来我们讲讲这个堆叠函数的思路:更多精彩请至KS科研分享与服务公众号