我正在尝试根据美国城市的数据点在R中创建一个热图,每个城市的GDP产生“热量”,较高的GDP为红色,而较低的GDP为绿色,现在得到的只是热图取决于城市本身的密度。
这是我的代码:
ggmap(map)
/+ geom_density2d(data = Metro_data, aes(x = Metro_data$Long, y = Metro_data$Lat), size = 0.1)
/+ stat_density2d(data = Metro_data, aes(x = Metro_data$Long, y = Metro_data$Lat, fill = ..level.., alpha = ..level..), size = 0.01,
bins = 16, geom = "polygon")
/+ scale_fill_gradient(low = "green", high = "red")
/+ scale_alpha(range = c(0, 0.9), guide = FALSE)
/+ geom_point(aes(x = Metro_data$Long, y = Metro_data$Lat), data = Metro_data, col = "black", alpha = 1, size=1, shape = ifelse(Metro_data$Coastal.=="TRUE", 15, 17))
这就是它的作用:enter image description here
抱歉,如果我的格式很糟糕,这是我第一次在这里发布!