服务热线
178 0020 3020
R语言之ggplot2画热图
library(ggplot2)
require(reshape2)
require(scales)
data<-read.csv("E:/PNG/R2/R2-8-热图/2.csv",header = T)
data1<-melt(data,id.vars=c("ID"))##id.vars保证ID列不会被merge,会保留完整。
mytheme<- theme(plot.title=element_text(face="bold.italic",family="Times",size=12))+
theme(axis.title = element_text(size=9))+
theme(legend.title = element_text(size=9))+
theme(axis.text.x = element_text(face = "bold",size=6))+
theme(axis.text.y = element_text(face = "italic",colour = "darkred",size=6))
p<-ggplot(data1,aes(x=variable,y=ID))+
geom_tile(aes(fill=value),color="white")+##color="white"写在aes()里面小方框为红色,写在外面,方框呈白色。
scale_fill_gradient(low = "yellow",high = "blue")+
labs(title="R2-03-18",x="",y="miRNA ID",fill="label")+
mytheme
ggsave(p,filename="E:/PNG/R2/R2-8-热图/R2-03-18-heatmap.png",width=4,height=4)
library(ggplot2)
require(reshape2)
require(scales)
data<-read.csv("E:/PNG/R2/R2-8-热图/2.csv",header = T)
data1<-melt(data,id.vars=c("ID"))
mytheme<- theme(plot.title=element_text(face="bold.italic",family="Times",size=12))+
theme(axis.title = element_text(size=9))+
theme(legend.title = element_text(size=9))+
theme(axis.text.x = element_text(face = "bold",size=6))+
theme(axis.text.y = element_text(face = "italic",colour = "darkred",size=6))
p<-ggplot(data1,aes(x=variable,y=ID))+
geom_tile(aes(fill=value),color="white")+
scale_fill_gradient(low = "yellow",high = "blue")+
labs(title="R2-03-19",x="",y="miRNA ID",fill="label")+
geom_text(aes(label=round(value,3)),size=3)+
mytheme
ggsave("E:/PNG/R2/R2-8-热图/R2-03-19-heatmap.png",width=4,height = 4)
附件