分面小提琴图
2022-06-08 本文已影响0人
一只小脑斧
教程来自 https://mp.weixin.qq.com/s/Gr05DMadYnp5yLUEQ2HIoQ 感谢老俊俊哥
数据大概长这个样子
有三列
group:high,low
BIOSYNTHESIS:数值变量
donor_tumour_stage_at_diagnosis:分期 1 2 3
#加载包
library(tidyverse)
library(ggpubr)
library(ggsci)
library(introdataviz)
#画图
################分三组
# plot
ggplot(df,aes(x = group,y =BIOSYNTHESIS,fill=donor_tumour_stage_at_diagnosis )) +
# split violin分小提琴
geom_split_violin(alpha = .5, trim = F,color = NA,width = 1) +
# mean point加均值点
stat_summary(fun = "mean", geom = "point",position = position_dodge(0.2)) +
# errorbar
stat_summary(fun.data = "mean_sd", geom = "errorbar", width = .15,
size = 0.3,
position = position_dodge(0.2)) +
theme_bw(base_size = 16) +
theme(axis.text.x = element_text(angle = 90,color = 'black',hjust = 1),
legend.position = 'top') +
scale_fill_brewer(palette = 'Set1') +
scale_fill_jco(name = '') +
theme(panel.grid=element_blank())+#去掉网格
#ylim(1,8) +
# 添加显著性标记
stat_compare_means(aes(group=donor_tumour_stage_at_diagnosis),
method = "anova",#三组
symnum.args=list(cutpoints = c(0, 0.001, 0.01, 0.05, 1),
symbols = c("***", "**", "*", "NS")),label = "p.signif")
three2.png
分三个有点丑呀,,ԾㅂԾ,,
################分两组
# plot
ggplot(df,aes(x = donor_tumour_stage_at_diagnosis,y =BIOSYNTHESIS,fill=group)) +
# split violin分小提琴
geom_split_violin(alpha = .5, trim = F,color = NA,width = 1) +
# mean point加均值点
stat_summary(fun = "mean", geom = "point",position = position_dodge(0.2)) +
# errorbar
stat_summary(fun.data = "mean_sd", geom = "errorbar", width = .15,
size = 0.3,
position = position_dodge(0.2)) +
theme_bw(base_size = 16) +
theme(axis.text.x = element_text(angle = 90,color = 'black',hjust = 1),
legend.position = 'top') +
scale_fill_brewer(palette = 'Set1') +
scale_fill_jco(name = '') +
theme(panel.grid=element_blank())+#去掉网格
#ylim(1,8) +
# 添加显著性标记
stat_compare_means(aes(group=group),
symnum.args=list(cutpoints = c(0, 0.001, 0.01, 0.05, 1),
symbols = c("***", "**", "*", "NS")),label = "p.signif")
paired.png