基于ggplot的热力图绘制
library (ggplot2)
library (reshape2)
setwd("D:/example/") #设定数据的存放路径
data1<-read.csv('a4.csv',header = TRUE) #读取文件
data2<- melt (data1, id="Month") #转化成长数据集
data2$variable= factor(data2$variable, levels=c('EL10_TMP','EL14_TMP','EL18_TMP','EL10_PRE','EL14_PRE','EL18_PRE','EL10_PDSI','EL14_PDSI','EL18_PDSI')) #设置顺序
data2$Month= factor(data2$Month, levels=c('P.Jun','P.Jul','P.Aug','P.Sep','P.Oct','P.Nov','P.Dec','C.Jan','C.Feb','C.Mar','C.Apr','C.May','C.Jun','C.Jul','C.Aug','C.Sep','C.Oct')) ## 设置顺序
p1<-ggplot(data2,aes(x=Month,y=variable,fill=value)) #热力图绘制
p2<-p1+geom_raster()+ scale_fill_gradient2(low="red", high="darkgreen", mid="white") #填充不同的颜色
基于pheatmap包的绘制
library(pheatmap)
library(RColorBrewer)
setwd("D:/example/")
data1<-read.csv('a4.csv',header = TRUE)
pheatmap(data1)
p3<-pheatmap(data1,
color=brewer.pal(11,"PRGn"),
cellwidth = 20,
cellheight = 10,
cluster_rows = FALSE,
cluster_cols = FALSE,
labels_row=c('P.Jun','P.Jul','P.Aug','P.Sep','P.Oct','P.Nov','P.Dec','C.Jan','C.Feb','C.Mar','C.Apr','C.May','C.Jun','C.Jul','C.Aug','C.Sep','C.Oct'),
fontsize = 12,
#display_numbers = TRUE,
number_color = "black",
)
暂无数据