R 软件如何绘制热力图
1、运行环境RStudio。打开数据集,这里以txhousing数据为例,选取city、year、sales三列数据。

2、设置基层图。fill设置为sales,sales值越大热度越高。library(ggplot2)p<-ggplot(data=txhousing,aes(x=year,y=city,fill=sales))

4、geom_raster也可以达到相同的效果,设置参数interpolate = TRUE。geom_raster(aes(fill = density), interpolate = TRUE)

6、添加参数binwidth = c(0.01,0.01)。p+geom_raster()+stat_bin2d(binwidth = c(0.01,0.01),colour="grey")可以根据实际需要进行设置。
