读图
该图为患者使用药物(左侧,7例患者,14例样本)或机械通气(右侧,4例患者,8例样本)前后α多样性的患者内差异(检验方法:双侧Wilcoxon符号秩检验)。
示例数据及作图前准备
由于作者给开源的数据设置了权限,这里就对ggpubr自带的ToothGrowth数据集进行添加一列编号信息作为示例数据。
导入数据
# 导入数据并查看数据集格式 library(ggpubr) data <- read.csv("test.csv") head(data) # id列用于配对
> head(data) len supp id 1 4.2 VC 1 2 11.5 VC 2 3 7.3 VC 3 4 5.8 VC 4 5 6.4 VC 5 6 10.0 VC 6
绘制
ggpaired(data, x="supp", y="len", fill="supp",id = "id", add="jitter",line.color = "gray", line.size = 0.4, palette=c("#83B8D7","#354B99"), xlab="my test", ylab="supp", title = "supp-length", legend.title="supp") + # 秩和检验 stat_compare_means(method="wilcox", paired = T, comparisons=list(c("OJ", "VC"))) + theme_bw() + # 设置主次网格线 theme(panel.grid.major = element_line(colour = "gray97"), panel.grid.minor = element_line(colour = "gray97")) + # 设置轴标题和图标标题 theme(axis.title = element_text(face = "bold"), plot.title = element_text(size = 14, face = "bold"), legend.title = element_text(face = "bold")) # 保存图片 ggsave(filename = "test.pdf", device="pdf", height=6, width=6, useDingbats=FALSE)
结果展示