R语言 ggplot 画热图 P值
print(temp)
#使用reshape2包中melt函数将矩阵转换为ggplot需要的data.frame。
#注意:若是所有行名列名都是数字就会转换成matrix
下面展示一些 代码
。
// 使用scales包中melt函数将矩阵转换为ggplot需要的data.frame
library(reshape2)
temp_1<-melt(temp)
// ggplot画图
ggplot(temp_1, aes(as.factor(Var1), Var2)) +
geom_tile(aes(fill = value),colour = "white") +
scale_fill_gradient(name="p-value", low = "red",high = "white",breaks=c(0,0.05,1)) +
theme(axis.text.x = element_text(vjust = 0.5, hjust = 0.5, angle = 90))+
coord_fixed(ratio=1)+
theme(axis.text= element_text(size = 5,family="ARL"))+
theme(plot.margin = unit(c(0.1,0,0,0), unit="mm"))+
labs(x = "position", y = "motif", title = "difference distribution")+ ##调整坐标轴名字
theme(plot.title = element_text(size = 8,hjust = 0.5,family = "ARL" ))+
theme(legend.key.width=unit(3,'mm'),legend.key.height=unit(1,'cm'))+
theme(legend.title = element_text(size = 8)) #调整legend title的字号
做出的图大概是这样,我是将p值大于0.05都调成白色,然后有个简单的排序