原文链接:多组热图绘制教程
- 加载R包
library(tidyverse)
library(scales)
library(RColorBrewer)
- 加载数据
dat <- read.csv("data_input.csv",header = T)
head(dat)
list <- unique(dat$Metabolism)
list <- as.data.frame(list)
list$color <- brewer.pal(length(unique(list$list)), "Dark2")
##'@创建一个空的储存
plot_list <- list()
d <- list$list[6]
- 绘图
for (d in list$list) {
#d = "CO-Oxidation"
dat_lol <- dat %>%
filter(Metabolism == !!d)
## 设置颜色
list_temp <- list %>%
filter(list == !!d)
(
p1 <-
ggplot(dat_lol , aes(Gene_name, Class)) +
geom_tile(aes(fill = mean_tax), colour = "black") +
scale_fill_gradient(
low = "white",
high = list_temp$color,
limits = c(0, 100)
) +
#scale_x_discrete(guide = guide_axis(n.dodge = 2))+
theme_minimal() +
coord_fixed(ratio = 1) +
labs(x = NULL, y = NULL, fill = "Propotion of MAGs (%)") +
theme(
text = element_text(size = 12, colour = "black"),
axis.text.x = element_text(angle = 45, hjust = 1)
)
)
name = d
name <- gsub(" ", "_", name)
name <- gsub("/", "_", name)
name <- paste("Figures/Fig_3a_", name, ".pdf", sep = "")
ggsave(name, p1)
plot_list[[d]] = p1
}
- 查看图形
plot_list$`Carbon metabolism`
小杜的生信筆記 ,主要发表或收录生物信息学教程,以及基于R分析和可视化(包括数据分析,图形绘制等);分享感兴趣的文献和学习资料!!