如何使用ggplot根据点的自身值制作热图?

时间:2015-10-18 00:38:31

标签: r plot ggplot2 ggmap

假设我有一个包含3列空间网格的数据框:

> pressureData
       lon   lat  pressure
1   -113.8 -21.2 1000.0000
2   -111.2 -21.2 1000.0000
3   -108.8 -21.2 1000.0000
4    -93.8 -21.2 1000.0000
5    -91.2 -21.2 1000.0000
6    -76.2 -21.2  997.2222
7    -73.8 -21.2  999.9306
8    -71.2 -21.2  990.2778
9    -68.8 -21.2  809.5139
10   -66.2 -21.2  673.2639

我想使用ggplot()和ggmap()在地图上绘制它们。到目前为止,我有这样的事情: enter image description here

我使用的代码是:

myMap = ggmap(mylocation) + 
        geom_point(aes(x = lon, y = lat, show_guide = TRUE, colour = pressure), 
        data = pressureData, alpha = .5, size = 5, shape = 15)  + 
        scale_color_gradient(low = "beige", high="blue") 

地图看起来还不错,我可以大致分辨出哪个地区压力较小,但我希望我的结果看起来像热图。

-----------------------更新--------------------

myMap = ggplot(pressureData) +
        aes(x = lon, y = lat, z = pressure, fill = pressure) +
        geom_tile() + 
        geom_contour(color = "white", alpha = 0.8) 
myMap

enter image description here

我修改了我的代码并获得了上述结果,但是当我想在等高线图下添加我的地图时,我收到了一个错误:

myMap = ggplot(pressureData) +
        aes(x = lon, y = lat, z = pressure, fill = pressure) +
        geom_tile() + 
        geom_contour(color = "white", alpha = 0.8) +
        ggmap(mylocation)

Error in p + o : non-numeric argument to binary operator
In addition: Warning message:
Incompatible methods ("+.gg", "Ops.data.frame") for "+"

我怀疑两个图形的大小差异会导致这个问题,但我该如何解决?

0 个答案:

没有答案