今天我們學(xué)做一下NC文章的小提琴圖,有小提琴圖,也有散點,其實看過之前系列文章的人如果能夠聯(lián)想,可以想到這個圖是(ggplot分組散點圖-坐標(biāo)軸截斷-添加四分位圖-顯著性檢驗)和(ggplot批量繪制小提琴圖并添加趨勢連線)的結(jié)合。只不過這篇文章的圖有個特點是散點分布和小提琴圖形狀一致,在畫散點的時候利用geom_quasirandom 代替geom_jitter即可。

image.png

image.png
原文提供了原始作圖數(shù)據(jù),可去官網(wǎng)下載。
示例數(shù)據(jù)和注釋代碼已上傳群文件,免費獲取可加群!
作圖:
讀入數(shù)據(jù)
setwd("D:/KS項目/復(fù)現(xiàn)NC")
A <- read.csv("Fig3f.csv", header = T)
A$Integrated.density <- 0.001*A$Integrated.density
library(ggplot2)
library(ggbeeswarm)
library(ggpubr)
A$Biological.replicate <- as.factor(A$Biological.replicate)
計算平均值、sd等:
library(dplyr)
B <- A %>%
group_by(Treatment) %>%
mutate(upper = quantile(Integrated.density, 0.75),
lower = quantile(Integrated.density, 0.25),
mean = mean(Integrated.density),
median = median(Integrated.density),
sd = sd(Integrated.density))
ggplot作圖:
ggplot(A,aes(x=Treatment,y=Integrated.density))+
geom_violin(width =0.8,fill='#EDEDED',color='#EDEDED')+
geom_quasirandom(aes(color=Biological.replicate),width = 0.4,size=2.5)+
scale_color_manual(name = 'Rep.',
values = c('#FFD7A8','#F2A9A9','#BAB099'),
labels = c('1','2','3'))+
theme_classic()+
labs(x=" ",
y=expression('Integrated density (x'~10^3~')'))+
theme(axis.title.y = element_text(colour = 'black',size = 16),
axis.text = element_text(colour = 'black',size = 14),
axis.line = element_line(size = 1),
legend.title = element_text(size = 14),
legend.text = element_text(size = 14))+
guides(color=guide_legend(override.aes = list(size=4)))+
geom_errorbar(data=B, aes(ymin = mean-sd,
ymax = mean+sd),width = 0.2,size=0.5)+
stat_summary(fun = "mean",
geom = "crossbar",
mapping = aes(ymin=..y..,ymax=..y..),
width=0.4,
size=0.3)+
stat_summary(aes(fill=Biological.replicate), geom="point",
fun = mean, shape=21, size=6,stroke=1.3)+
scale_fill_manual(values = c('#FFAF51','#E65454','#756233'))+
geom_signif(data=A,
aes(xmin=1, xmax=2, annotations="0.3008367",
y_position=310),
textsize = 5,tip_length = c(0, 0),
manual=TRUE, size = 0.5)+
guides(fill=guide_legend(title = 'Mean'))

image.png
結(jié)果基本是一致的,不同之處在于誤差線,我是按照mean±sd,和原文有出入。其次Mean的圖例,這里沒有修改,不知有啥好辦法,原文只有一個圈,其實用annotate函數(shù)可以加上。
更多精彩請關(guān)注我的公眾號《KS科研分享與服務(wù)》