本文主要展示如何利用R语言绘制来自nature期刊ABO genotype alters the gut microbiota by regulating GalNAc levels in pigs(Hui Yang, et al,2022)[1]一文中的Extended Data Fig.4b。该图形式为箱线图,并添加了Wilcoxon检验结果的p值。如下图所示:
1、图形绘制
library(dplyr)
library(ggplot2)
library(ggsignif)
data %>% mutate(across(all_of(c("genotyping", "group")), factor)) #factor
data$genotyping <- factor(data$genotyping) #factor
level <- c("F6_D25","F7_D25","F6_D120","F7_D120","F6_D240","F7_D240","F6_IC","F7_IC","F6_CC","F7_CC","F7_IM","F7_CM") #level
data$group <- factor(data$group, levels = level) #factor
head(data)
# id Otu476 genotyping group
#1 4844 5.296459 AO F6_CC
#2 4978 5.112443 AO F6_CC
#3 5254 4.059229 AO F6_CC
#4 5003 3.718711 AO F6_CC
#5 5309 3.543929 AO F6_CC
#6 5252 3.159236 AO F6_CC
str(data)
#'data.frame': 4565 obs. of 4 variables:
# $ id : int 4844 4978 5254 5003 5309 5252 4992 5138 4999 4846 ...
# $ Otu476 : num 5.3 5.11 4.06 3.72 3.54 ...
# $ genotyping: Factor w/ 3 levels "AA","AO","OO": 2 2 2 2 2 2 2 1 2 2 ...
# $ group : Factor w/ 12 levels "F6_D25","F7_D25",..: 9 9 9 9 9 9 9 9 9 9 ...
#定义颜色
my.palette <- c("#660066","#660066","#ff3300","#ff3300","#009933","#009933","#0099cc","#0099cc","#333399","#333399","#ff33cc","#cc6633")
#定义比较组
my.comparisons <- list(c("AA", "AO"), c("AA", "OO"), c("AO", "OO"))
#绘图
ggplot(data, aes(x = genotyping,y = Otu476)) + # 1200*800
geom_boxplot(aes(fill = group, color = group), notch = TRUE, outlier.alpha = 0.2, alpha = 1) + #fill与color映射
ggsignif::geom_signif(comparisons = my.comparisons, test = "wilcox.test", map_signif_level = FALSE,
step_increase = 0.2, size = 0.2, textsize = 4, margin_top = -0.5,
tip_length = 0.03, vjust = -0.2) +
facet_wrap(~group, scales = "free") +
theme_bw() +
scale_fill_manual(values = my.palette) +
scale_color_manual(values = my.palette) +
theme(panel.grid = element_blank(),
axis.text = element_text(size = 10, color = "black"),
axis.title = element_text(size = 15),
axis.line = element_line(color = "black", size = 1),
strip.text = element_text(size = 12, color = "black"),
legend.position = "none") +
labs(x = "Deletion genotyping", y = "OTU476 relative abundance (%)")
该图基础为分面形式的箱线图,主要使用到geom_boxplot()、facet_wrap() 等函数。此外,对于Wilcoxon检验,可使用ggsignif包中的geom_signif() 函数来进行结果标记。
2、其他
其他绘图方法可进一步阅读公众号其他文章。
如有帮助请多多点赞哦!
参考资料
Yang, H., Wu, J., Huang, X. et al. ABO genotype alters the gut microbiota by regulating GalNAc levels in pigs. Nature 606, 358–367 (2022). : https://doi.org/10.1038/s41586-022-04769-z
文章转载自日常分享的小懒猫,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。