使用ggplot2在地图上绘制热力图
######*****绘制热力图代码*****#######
interval <- seq(0, 150000, 25000)[-2]
#设置价格区间
newpri <- cut(data1$price, interval, labels = F)
#设置价格为因子类型
newpri <- factor(newpri, levels = 1:5, labels = c("25000", "50000", "75000", "100000", "125000"))
#设置因子顺序
data1$newpri <- newpri
#添加到数据框中
ggmap(beijing) +
stat_bin2d(aes(LONG, LAT, fill = newpri), data = data1, size = 0.5, alpha = 0.5) + #绘制热力图
labs(title = "北京二手房单价", x = '经度', y = '纬度') + #添加标题
scale_fill_manual("单价(元)",
values = c("#64f830", "#adda30", "#d1b930", "#e89230", "#fa5030"),
breaks = c("125000", "100000", "75000", "50000", "25000")) #设置热力图渐进颜色
|
请发表评论