旭日图简介
旭日图(Sunburst Chart),其实是一种特殊的饼图或环状图,常用于展示数据的多层数据结构关系。
标签:#微生物组数据分析 #MicrobiomeStatPlot #旭日图 #R语言可视化 #sunburst plot
作者:First draft(初稿):Defeng Bai(白德凤);Proofreading(校对):Ma Chuang(马闯) and Jiani Xun(荀佳妮);Text tutorial(文字教程):Defeng Bai(白德凤)
源代码及测试数据链接:
https://github.com/YongxinLiu/MicrobiomeStatPlot/项目中目录 3.Visualization_and_interpretation/SunBurst_Chart
或公众号后台回复“MicrobiomeStatPlot”领取
下图是Ana Rita Brochado团队2024年发表在Nature Microbiology(Brenzinger et al., 2024)上的一篇论文用到的旭日图。题目:The Vibrio cholerae CBASS phage defence system modulates resistance and killing by antifolate antibiotics. https://doi.org/10.1038/s41564-023-01556-y
图 1 | 研究中测试的化合物库的组成。
化合物按目标(在抗菌药物的情况下,内环)和化合物类别(外环)进行分类。
结果
文中试图通过评估野生型(WT)霍乱弧菌和CBASS操纵子缺失(ΔCBASS)菌株在94种小分子(包括抗生素、人类药物、人类内源性代谢产物和食品添加剂)存在下的细菌生长,系统地研究CBASS对抗微生物活性的影响(图1b和补充表1)。
源代码及测试数据链接:
https://github.com/YongxinLiu/MicrobiomeStatPlot/
或公众号后台回复“MicrobiomeStatPlot”领取
软件包安装
# 基于CRAN安装R包,检测没有则安装
p_list = c("dplyr", "ggplot2", "formattable")
for(p in p_list){if (!requireNamespace(p)){install.packages(p)}
library(p, character.only = TRUE, quietly = TRUE, warn.conflicts = FALSE)}
# 加载R包 Load the package
suppressWarnings(suppressMessages(library(dplyr)))
suppressWarnings(suppressMessages(library(ggplot2)))
实战
绘制饼图
参考:
https://mp.weixin.qq.com/s/xUQM-1h-OeeWGjJlRw3d_g
# 构建数据
# Load data
count_data <- data.frame(
class = c("1st", "2nd", "3rd", "Crew"),
n = c(325, 285, 706, 885),
prop = c(14.8, 12.9, 32.1, 40.2)
)
# 计算标签位置
# Label positions
count_data <- count_data %>%
arrange(desc(class)) %>%
mutate(lab_ypos = cumsum(prop) - 0.5 * prop)
# 使用ColorBrewer中的调色板
# Set color
mycols <- c("#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3")
# 绘制的饼图
# Pie plot
p_pie1 <- ggplot(count_data, aes(x = "", y = prop, fill = class)) +
geom_bar(width = 1, stat = "identity", color = "black", size = 0.5) +
coord_polar("y", start = pi/4) +
geom_text(aes(y = lab_ypos, label = paste0(prop, "%")), color = "black", size = 3.5) +
scale_fill_manual(values = mycols) +
theme_void() +
theme(legend.position = "right")
# 绘制空心饼图(甜甜圈图)
# Draw a hollow pie chart (donut chart)
p_pie2 <- ggplot(count_data, aes(x = 2, y = prop, fill = class)) +
geom_bar(stat = "identity", color = "black", size = 0.5) +
coord_polar(theta = "y", start = pi/4) +
geom_text(aes(y = lab_ypos, label = paste0(prop, "%")), color = "black", size = 3.5) +
scale_fill_manual(values = mycols) +
theme_void() +
xlim(1, 3) +
theme(legend.position = "right")
ggsave('results/donut_chart.pdf', p_pie2)
使用ggplot2包作图
参考:
https://mp.weixin.qq.com/s/19clA4xZqoAl7KuY96ZJjQ?search_click_id=9261072915409092102-1714444702544-1010392356
# 加载数据
# Load data
df <- read.table("data/data.txt", header = TRUE, check.names = FALSE, sep = "\t")
# 定义百分比转换函数
# Define percentage conversion function
convert_to_percent <- function(x) {
return(paste0(round(x * 100, 1), "%"))
}
# 分别计算group1、group2、group3的数据
# Calculate the data of group1, group2, and group3 respectively
get_data <- function(group_col, data) {
data_group <- aggregate(value ~ get(group_col), data, sum)
data_group$Rel <- data_group$value / sum(data_group$value)
data_group$per <- convert_to_percent(data_group$Rel)
colnames(data_group)[1] <- group_col
data_group <- data_group %>%
mutate(
ymax = cumsum(Rel),
ymin = c(0, head(ymax, -1)),
labelposition = (ymax + ymin) / 2
)
return(data_group)
}
data1 <- get_data("group1", df)
data2 <- get_data("group2", df)
data3 <- get_data("group3", df)
# 设定颜色
# Set color
mycolors1 <- c("#66c2a5", "#fc8d62", "#8da0cb", "#e78ac3", "#a6d854")
mycolors2 <- c("#ffd92f", "#e5c494", "#b3b3b3")
mycolors3 <- c("#e41a1c", "#377eb8")
# 绘制第一个圆环图
# Plot First circle
p1 <- ggplot(data1, aes(ymax = ymax, ymin = ymin, xmax = 3, xmin = 2)) +
geom_rect(aes(fill = group1), color = "white") +
geom_text(aes(x = 2.5, y = labelposition, label = paste0(group1, "\n(", per, ")")),
size = 4, color = "black") +
coord_polar(theta = "y") +
theme_void() +
scale_fill_manual(values = mycolors1) +
theme(legend.position = "none")
#p1
# 增加中间空白区域
# Add the blank space
p2 <- p1 + ylim(0, 1.1)
#p2
# 绘制双环图(内环 + 外环)
# Draw a double ring plot (inner ring + outer ring)
p3 <- ggplot() +
geom_rect(data = data2, aes(ymax = ymax, ymin = ymin, xmax = 2, xmin = 0, fill = group2), color = "white") +
geom_rect(data = data1, aes(ymax = ymax, ymin = ymin, xmax = 3.5, xmin = 2, fill = group1), color = "white", alpha = 0.6) +
geom_text(data = data2, aes(x = 1, y = labelposition, label = paste0(group2, "\n(", per, ")")),
size = 4, color = "black") +
geom_text(data = data1, aes(x = 2.75, y = labelposition, label = paste0(group1, "\n(", per, ")")),
size = 3, color = "black") +
coord_polar(theta = "y") +
theme_void() +
scale_fill_manual(values = c(mycolors2, mycolors1)) +
theme(legend.position = "none") +
xlim(0, 3.5)
#p3
# 增加空白区域
# Add the blank space
p4 <- p3 + ylim(0, 1.1)
#p4
# 绘制三环旭日图
# Draw a three-ring sunburst plot
p5 <- ggplot() +
geom_rect(data = data3, aes(ymax = ymax, ymin = ymin, xmax = 2, xmin = 0, fill = group3), color = "white") +
geom_rect(data = data2, aes(ymax = ymax, ymin = ymin, xmax = 3.5, xmin = 2, fill = group2), color = "white", alpha = 0.6) +
geom_rect(data = data1, aes(ymax = ymax, ymin = ymin, xmax = 5, xmin = 3.5, fill = group1), color = "white", alpha = 0.3) +
geom_text(data = data3, aes(x = 1, y = labelposition, label = paste0(group3, "\n(", per, ")")),
size = 3.5, color = "black") +
geom_text(data = data2, aes(x = 2.75, y = labelposition, label = paste0(group2, "\n(", per, ")")),
size = 3, color = "black") +
geom_text(data = data1, aes(x = 4.25, y = labelposition, label = paste0(group1, "\n(", per, ")")),
size = 3, color = "black") +
coord_polar(theta = "y") +
theme_void() +
scale_fill_manual(values = c(mycolors3, mycolors2, mycolors1)) +
theme(legend.position = "none") +
xlim(0, 5)
#p5
# 增加空白区域
# Add the blank space
p6 <- p5 + ylim(0, 1.1)
#p6
ggsave('results/Three_ring_sunburst_plot.pdf', p6)
排版combo plots
library(cowplot)
width = 89
height = 59
p0 = plot_grid(p_pie1 ,p_pie2, p1, p2, p3, p4, p5, p6,
labels = c("A", "B", "C", "D", "E", "F", "G", "H"), ncol = 4)
ggsave("results/SunBurst_plot01.pdf", p0, width = width * 3, height = height * 3, units = "mm")
使用此脚本,请引用下文:
Yong-Xin Liu, Lei Chen, Tengfei Ma, Xiaofang Li, Maosheng Zheng, Xin Zhou, Liang Chen, Xubo Qian, Jiao Xi, Hongye Lu, Huiluo Cao, Xiaoya Ma, Bian Bian, Pengfan Zhang, Jiqiu Wu, Ren-You Gan, Baolei Jia, Linyang Sun, Zhicheng Ju, Yunyun Gao, Tao Wen, Tong Chen. 2023. EasyAmplicon: An easy-to-use, open-source, reproducible, and community-based pipeline for amplicon data analysis in microbiome research. iMeta 2: e83. https://doi.org/10.1002/imt2.83
Copyright 2016-2024 Defeng Bai baidefeng@caas.cn, Chuang Ma 22720765@stu.ahau.edu.cn, Jiani Xun 15231572937@163.com, Yong-Xin Liu liuyongxin@caas.cn
猜你喜欢
iMeta高引文章 fastp 复杂热图 ggtree 绘图imageGP 网络iNAP
iMeta网页工具 代谢组MetOrigin 美吉云乳酸化预测DeepKla
iMeta综述 肠菌菌群 植物菌群 口腔菌群 蛋白质结构预测
10000+:菌群分析 宝宝与猫狗 梅毒狂想曲 提DNA发Nature
一文读懂:宏基因组 寄生虫益处 进化树 必备技能:提问 搜索 Endnote
16S功能预测 PICRUSt FAPROTAX Bugbase Tax4Fun
生物科普: 肠道细菌 人体上的生命 生命大跃进 细胞暗战 人体奥秘
写在后面
为鼓励读者交流快速解决科研困难,我们建立了“宏基因组”讨论群,己有国内外6000+ 科研人员加入。请添加主编微信meta-genomics带你入群,务必备注“姓名-单位-研究方向-职称/年级”。高级职称请注明身份,另有海内外微生物PI群供大佬合作交流。技术问题寻求帮助,首先阅读《如何优雅的提问》学习解决问题思路,仍未解决群内讨论,问题不私聊,帮助同行。
点击阅读原文