前面那個(gè)帖子我們用ggplot來畫分半小提琴圖,今天我們練習(xí)用ggunchained包里面的geom_split_violin包來實(shí)現(xiàn),會(huì)更方便和簡(jiǎn)單。
#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就實(shí)現(xiàn)了分半小提琴的畫法。

像前面一樣,我們把其它的元素也加進(jìn)去。
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")
