本地文件 s41564-021-00997-7.pdf
论文
Protective role of the Arabidopsis leaf microbiota against a bacterial pathogen
image.png
今天的推文来重复一下论文中的figure6a
image.png
今天的推文先画黑白格的热图,关于添加线段注释和左侧的绿色热图放到下期推文介绍
首先是示例数据集
image.png
读取数据
代码语言:javascript复制library(readxl)
library(tidyverse)
df<-read_excel("41564_2021_997_MOESM14_ESM.xlsx",
n_max = 40)
这里用到了n_max
参数,是因为数据文件的结尾还有一行数据,这里我不想读入,最方便的办法是直接手动删掉,不想删就指定读取的行数
宽格式数据转换为长格式
代码语言:javascript复制df %>%
select(-Func_name) %>%
pivot_longer(!Func_id) -> dfa
赋予因子水平
代码语言:javascript复制dfa$Func_id<-factor(dfa$Func_id,
levels = df$Func_id)
dfa$name<-factor(dfa$name,
levels = rev(colnames(df)[3:16]))
dfa$value<-as.character(dfa$value)
dfa %>%
mutate(new_col=case_when(
value == "0" ~ "0",
value == "1" ~ "1",
value == "2" ~ "2",
value == "3" ~ ">2",
value == "4" ~ ">2"
)) %>%
mutate(new_col=fct_relevel(new_col,c(0,1,2,">2")))-> dfb
最后是作图代码
代码语言:javascript复制library(ggplot2)
ggplot(data=dfb,aes(x=Func_id,y=name))
geom_tile(aes(fill=new_col),
color="black")
theme_bw()
theme(panel.border = element_blank(),
panel.grid = element_blank(),
axis.title = element_blank(),
#legend.title = element_blank(),
axis.text.x = element_text(angle=90,vjust=0.5))
scale_fill_manual(values = c("#ffffff","#b8b8b8",
"#4b4b4b","#242424"))
labs(fill="Genes")
image.png