【R畫圖學(xué)習(xí)18.4】分半小提琴圖---geom_split_violin

前面那個(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")


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容