我在R中用ggmap/ggplot2 2绘制地图上填充的等高线图有困难。
我的数据有规律地以z值表示降雨的lat/lon坐标。
> head( flood )
lat lon rain
1 22.51916 -105.9318 1.486188e-05
2 22.59956 -105.9318 1.735962e-05
3 22.67996 -105.9318 2.024598e-05
4 22.76037 -105.9318 2.357599e-05
5 22.84077 -105.9318 2.741153e-05
6 22.92117 -105.9318 3.182212e-05在用ggmap获取基础地图之后,我正在尝试绘制充满雨的等高线
map = ggmap( baseMap ) +
geom_contour( data = flood, aes( x = lon, y = lat, z = rain ) ) +
scale_fill_continuous( name = "Rainfall (inches)", low = "yellow", high = "red" ) 这给了我一个错误
Error in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0如果我做了
map = ggmap( baseMap ) +
geom_contour( data = flood, aes( x = lon, y = lat, z = rain, fill = ..level.. ) ) +
scale_fill_continuous( name = "Rainfall (inches)", low = "yellow", high = "red" ) 我得到这个地块时没有实际的填充。

我一直试图跟踪这个职位和这个职位,但我无法正确地解决我的问题。我不太了解ggplot/R,但到目前为止,我还能勉强通过它。..level..。卑劣?
我认为这个职位可能是有关联的,但我不能将修正推广到等高线图上。
发布于 2014-01-22 18:29:51
如果没有更有代表性的数据集,就不可能进行测试(您能提供链接吗?)
尽管如此,试着:
## not tested..
map = ggmap( baseMap ) +
stat_contour( data = flood, geom="polygon",
aes( x = lon, y = lat, z = rain, fill = ..level.. ) ) +
scale_fill_continuous( name = "Rainfall (inches)", low = "yellow", high = "red" ) 问题是geom_contour不尊重fill=...。您需要将stat_contour(...)与geom="polygon" (而不是"line")结合使用。
https://stackoverflow.com/questions/21290230
复制相似问题