繁体   English   中英

用R / ggplot / ggmap填充等高线图

[英]Filled contour plot with R/ggplot/ggmap

我在使用g中的ggmap / ggplot2在地图上绘制填充的等高线图时遇到了问题。

我的数据是规则间隔的纬度/经度坐标,其中az值表示降雨量

> 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了解不多,但到目前为止我已经能够绊倒它了。 ..等级是什么意思?

我认为这篇文章可能是相关的,但我无法概括修复工作等高线图。

没有更具代表性的数据集就不可能进行测试(你能提供链接吗?)。

不过,试试:

## 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”)一起使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM