在徐凌老师的 Nat Com 文章 Genome-resolved metagenomics reveals role of iron metabolism in drought-induced rhizosphere microbiome dynamics 中有这么一张补充图,介绍了本研究中涉及到的处理和取样的时间线。
这种图通常被称为时间热图或时间线图,结合了颜色块、标签和标记,我们按照以下步骤进行绘图:
- 数据准备:整理你的数据,确保每个时间点的数据都在正确的位置。
- 确定颜色:为不同的部分如Water applied/No water applied和不同Omics选择颜色。
- 绘制基础图形:首先,绘制一个时间线图形,区分“Control”和“Drought”。
- 添加颜色块:根据数据在相应的时间点添加颜色块。
- 添加标记:如红点和绿点,表示“Metagenome”和“16S rRNA amplicon seq”等。
- 添加图例:确保图例清晰,与图中使用的颜色和标记一致。
- 优化和调整。
下面我们尝试用R复现此图
1生成示例数据
代码语言:javascript复制data <- data.frame(
Category = c(rep("Control", 18), rep("Drought", 18)),
TimePoint = rep(paste0("TP", 0:17), 2),
Water = c(rep("Water applied", 18), rep("No water applied", 5), rep("Water applied", 13)),
Metagenome = c(rep(1, 9), rep(NA, 9), rep(NA, 5), rep(1, 13)),
Transcriptome = c(rep(NA, 4), rep(1, 5), rep(NA, 9), rep(NA, 5), rep(1, 4), rep(NA, 9))
)
# 示例数据前六行
Category TimePoint Water Metagenome Transcriptome
1 Control TP0 Water applied 1 NA
2 Control TP1 Water applied 1 NA
3 Control TP2 Water applied 1 NA
4 Control TP3 Water applied 1 NA
5 Control TP4 Water applied 1 1
6 Control TP5 Water applied 1 1
2作图
代码语言:javascript复制library(ggplot2)
# 将TimePoint转换为有序因子
data$TimePoint <- factor(data$TimePoint, levels = paste0("TP", 0:17))
# 预定义颜色和其他属性
fill_colors <- c("Water applied" = "#7BAF8A", "No water applied" = "#D17F39")
color_values <- c("Metagenome" = "#9C281B", "Transcriptome" = "#343D5B")
# 使用ggplot2绘制图形
ggplot(data, aes(x = TimePoint, y = Category, fill = Water))
geom_tile(color = "black", size = 0.5)
geom_point(data = subset(data, !is.na(Metagenome)), aes(color = "Metagenome"), size = 5,
position = position_nudge(y = 0))
geom_point(data = subset(data, !is.na(Transcriptome)), aes(color = "Transcriptome"), size = 5,
position = position_nudge(y = -0.1))
scale_fill_manual(values = fill_colors)
scale_color_manual(values = color_values)
guides(fill = guide_legend(override.aes = list(color = NA)))
labs(title = "Time point (in weeks)", fill = "", color = "", x = NULL)
theme_minimal()
theme(
axis.title.y = element_blank(),
panel.grid.major = element_blank(),
axis.line.x = element_blank(),
axis.text.x = element_text(face = "bold", size = 9,vjust = 12),
axis.text.y = element_text(face = "bold", size = 10),
plot.title = element_text(face = "bold", hjust = 0.5,vjust = -5))
3小结
除了展示上面的信息,你还可以额外生成一列 Note 用于文字标记,或通过调整点的高度位置来将组学数据展示在图形以外。