跟着Nature Communication学作图:R语言ggpubr包画箱线图并添加显著性P值
2023-02-19 12:27:38 时间
论文
Microbiomes in the Challenger Deep slope and bottom-axis sediments
https://www.nature.com/articles/s41467-022-29144-4#code-availability
对应代码链接
https://github.com/ucassee/Challenger-Deep-Microbes
论文里提供了大部分图的数据和代码,很好的学习材料,感兴趣的同学可以找来参考,今天的推文重复一下论文中的Figure1b
论文中提供的代码是用ggpubr这个R包实现的,如果比较着急要结果可以使用这个R包来作图,如果是学习为目的,还是推荐ggplot2的基础
部分数据集截图
image.png
读取数据集
dat<-read.delim("data/20220602/NCfigure1b.txt",
header = TRUE,
check.names = FALSE,
sep="\t")
head(dat)
带有百分号读取进来是字符,我们把它转换成数字
library(tidyverse)
dat %>%
mutate(`Novel 16s miTags (%)` = dat$`Novel 16s miTags (%)` %>% parse_number()) -> dat01
对表示分组的文本进行处理
dat01 %>%
mutate(group=case_when(
Group == "Bottom-axis" ~ "Bottom",
Group == "Slope" ~ "Slope",
Group == "Mariana Water" ~ "Mariana Water",
TRUE ~ "Deep sea"
)) -> dat02
赋予因子水平
dat02$group <- factor(dat02$group,
levels=c("Bottom", "Slope","Deep sea", "Mariana Water"),
ordered=TRUE)
table(dat02$group)
作图代码
p1<- ggboxplot(dat02, x="group", y="Novel 16s miTags (%)",
fill = "group", width = 0.5,
xlab = "",
palette = c("#F8766D","#00BFC4","#FEFF99","#B14A87"))+
ylab(label = "Novel 16S miTags (%)")+
#scale_y_continuous(labels = scales::percent)+
guides(fill=F)+
scale_x_discrete(labels = c("Bottom\naxis\n(n=17)",
"Slope\n(n=20)",
"Deep\nsed\n(n=20)",
"Mariana\nwater\n(n=7)"))+
theme(axis.text = element_text(size=10,family="serif"))+
stat_compare_means(comparisons=p1_comparisons,
label.y = c( 48, 53,40, 58),
method = "wilcox.test",size=3) # Add pairwise comparisons p-value
p1
image.png
试一下论文中提供的拼图代码
library(cowplot)
aligned_plots<- align_plots(p1, p1,align="h")
ggdraw( xlim = c(0, 1.1), ylim = c(0, 0.30))+
draw_plot(aligned_plots[[1]], x=0,y=0, width=0.5, height = 0.28)+
draw_plot(aligned_plots[[2]], x=0.50,y=0, width = 0.5, height = 0.28)
相关文章
- AI城管占道经营监测识别系统
- 人员超员识别系统
- IDM是一款强大的下载工具 idm多个版本(电脑、手机、浏览器插件都有)
- 关于PDF神器,也许是史上最全的整理pdf编辑器全版本下载
- 功能强大的PDF编辑工具--Adobe Acrobat Pro DC2021
- PDF编辑器Adobe Acrobat Pro DC2021安装教程来啦~PDF编辑器全版本下载
- 【算法竞赛】AtCoder Beginner Contest 284 D, F
- Linux登录时自动显示CPU硬盘内存使用信息(彩色进度条)
- LLVM 工具系列 - Address Sanitizer 基本原理介绍及案例分析(1)
- LLVM 工具系列 - Address Sanitizer 实现原理(2)
- C++ Postfix Completion VSCode 插件
- 主路由和二级路由设置同一局域网
- umi4 多环境配置改变
- C 语言实现冒泡排序 BubbleSort
- ClickHouse 引擎在行为分析场景下的 JOIN 优化
- C语言中数组长度的计算详解
- 嵌入式:ARM定时器
- 真正“搞”懂HTTP协议07之body的玩法(实践篇)
- Tiktok下载及注册教程
- 信息安全技术 云计算服务安全指南