美文网首页
【R画图学习18.4】分半小提琴图---geom_split_v

【R画图学习18.4】分半小提琴图---geom_split_v

作者: jjjscuedu | 来源:发表于2022-11-20 10:35 被阅读0次

前面那个帖子我们用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就实现了分半小提琴的画法。

像前面一样,我们把其它的元素也加进去。

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")

相关文章

网友评论

      本文标题:【R画图学习18.4】分半小提琴图---geom_split_v

      本文链接:https://www.haomeiwen.com/subject/bukbxdtx.html