library(pheatmap) # 本次所使用的热图绘制包,如果没有安装包,记得提前安装好
library(vegan) #vegan包待会可以用来标准化和中心化数据
data<-read.table("matrice_final_hhz_gene_cov5.csv",header=T,sep=",",row.names=1)
#View(data) #查看数据
df <- as.data.frame(data) #将数据转化为data.frame格式
library(dplyr)
library(ggplot2)
df %>%
mutate(x=1:nrow(.)) %>%
# select(1:10,x) %>%
select(1:ncol(.),x) %>%
reshape2::melt(,id.vars="x") %>%
mutate(pav=case_when(
value == 0 ~ "Absence",
# TRUE ~ "Presence"
TRUE == 1 ~ "Presence"
)) -> dfa
dfa %>% count(pav)
png(file = "pavheatmap.png",
##根据实际矩阵大小调整
# width = 10000,
# height = 6000,
family = "serif")
ggplot(data=dfa,aes(x=x,y=variable))+
geom_tile(aes(fill=pav))+
scale_fill_manual(name=" Presence or Absence",
values=c("#316879","#ff9a8d")) +
theme_classic() +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank()) +
theme(axis.title.y=element_blank(),
axis.text.y=element_text(angle = 0,
hjust = 1,
),
axis.ticks.y=element_blank()) +
theme(legend.position="bottom") +
theme(text = element_text(size = 12))
dev.off()
![](https://img.haomeiwen.com/i25274977/ad107327c9d15495.png)
结果
网友评论