热线电话:13121318867

登录
2019-04-24 阅读量: 1494
使用ggplot2中geom_tile画热力图

#####使用melt整理数据格式

mydata_cor.m <-melt(mydata_cor)

> head(mydata_cor.m)

Var1 Var2 variable value

1 mpg mpg value 1.0000000

2 disp mpg value -0.8475514

3 hp mpg value -0.7761684

4 drat mpg value 0.6811719

5 wt mpg value -0.8676594

6 qsec mpg value 0.4186840

绘制

p_cor <-ggplot(mydata_cor.m, aes(Var1, Var2)) +

geom_tile(aes(fill = value),colour = "white")

p_cor + scale_fill_gradient(name="Value", low = "white",high = "red") +

theme(axis.text.x = element_text(vjust = 0.5, hjust = 0.5, angle = 90))+

coord_fixed(ratio=1)+

theme(axis.text= element_text(size = 8,family="ARL"))+

theme(plot.margin = unit(c(0.1,0,0,0), unit="mm"))+

labs(x = "Var1", y = "Var2", title = "correlation")+

theme(plot.title = element_text(size = 13,hjust = 0.5,family = "ARL" ))+

theme(legend.key.width=unit(3,'mm'),legend.key.height=unit(3,'cm'))+

theme(legend.title = element_text(size = 8))

0.0000
3
关注作者
收藏
评论(0)

发表评论

暂无数据