在徐凌老师的 Nat Com 文章 Genome-resolved metagenomics reveals role of iron metabolism in drought-induced rhizosphere microbiome dynamics 中有这么一张补充图,介绍了本研究中涉及到的处理和取样的时间线。
这种图通常被称为时间热图或时间线图,结合了颜色块、标签和标记,我们按照以下步骤进行绘图:
下面我们尝试用R复现此图
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
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))
除了展示上面的信息,你还可以额外生成一列 Note 用于文字标记,或通过调整点的高度位置来将组学数据展示在图形以外。