前面那个帖子我们用ggplot来画分半小提琴图,今天我们练习用ggunchained包里面的geom_split_violin包来实现,会更方便和简单。
#library(devtools)
#install_github("JanCoUnchained/ggunchained")
library(ggunchained)
ggplot(data_new, aes(x = Genes,y = Values, fill = group))+
geom_split_violin(trim = T,colour="white", scale = 'width')+
scale_fill_manual(values = c("#1ba7b3","#dfb424"))
只通过geom_split_violin就实现了分半小提琴的画法。
![](https://img.haomeiwen.com/i24339453/bf095dfd454aaf8d.png)
像前面一样,我们把其它的元素也加进去。
ggplot(data_new, aes(x = Genes,y = Values, fill = group))+
geom_split_violin(colour="white", scale = 'width')+
scale_fill_manual(values = c("#1ba7b3","#dfb424"))+
stat_summary(fun = mean,
fun.min = function(x){quantile(x)[2]},
fun.max = function(x){quantile(x)[4]},
geom = "pointrange",
#geom = 'errorbar',
size=0.5,
position = position_dodge(width = 0.2))+
stat_compare_means(data = data_new, aes(x = Genes,y = Values),
symnum.args=list(cutpoints = c(0, 0.001, 0.01, 0.05, 1),
symbols = c("***", "**", "*", "-")),
label = "p.signif",
label.y = max(data_new$Values),
hide.ns = F)+
theme_bw()+
xlab("")+
ylab("log2(CPM)")+
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "top",
#legend.key = element_rect(fill = c("#1ba7b3","#dfb424")),
legend.justification = "right")
![](https://img.haomeiwen.com/i24339453/797d6fe4a22f23fe.png)
网友评论