用R / ggplot / ggmap填充轮廓图 [英] Filled contour plot with R/ggplot/ggmap

查看:256
本文介绍了用R / ggplot / ggmap填充轮廓图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在R中使用ggmap / ggplot2在地图顶部绘制填充轮廓图。



我的数据是有规律地间隔纬度/经度坐标az值表示降雨量

 > (洪水)
lat lon雨
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)

这给我一个错误

 单位错误(tic_pos.c,mm):'x'和'单位'必须有长度> 0 

如果我这样做

pre > 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)

没有实际的填充,我得到这个图。

I一直试图遵循这篇文章
这篇文章,但我无法为我的理解问题。我对ggplot / R知之甚少,但到目前为止,我已经能够蹒跚而行。什么是..level ..是什么意思?



我认为可能是相关的,但我不能一概而论的修复工作轮廓图。


解决方案

如果没有更具代表性的数据集(您能否提供链接?),无法测试。

尽管如此,请尝试:

  ##未经测试.. 
map = ggmap(baseMap)+
stat_contour(data = flood,geom =polygon,
aes(x = lon,y = lat,z = rain,fill = ..level ..))+
scale_fill_continuous(name =降雨(英寸),低=黄,高=红)

问题是geom_contour不尊重 fill = ... 。你需要使用 stat_contour(...) geom =polygon(而不是line)。

I'm having trouble plotting a filled contour plot on top of a map with ggmap/ggplot2 in R.

My data are regularly spaced lat/lon coordinates with a z value indicating rainfall

> 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

After getting the base map with ggmap, I'm trying to overplot filled contours of rain

map = ggmap( baseMap ) + 
    geom_contour( data = flood, aes( x = lon, y = lat, z = rain ) ) +
    scale_fill_continuous( name = "Rainfall (inches)", low = "yellow", high = "red" ) 

This gives me an error of

Error in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0

If I do

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" ) 

I get this plot without the actual fill.

I've been trying to follow this post and this post, but I can't get it right for my problem. I don't know much about ggplot/R, but I've been able to stumble through it so far up to now. What does ..level.. mean?

I think this post may be related, but I can't generalize the fix to work for contour plots.

解决方案

It's impossible to test without a more representative dataset (can you provide a link?).

Nevertheless, try:

## 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" ) 

The problem is that geom_contour doesn't respect fill=.... You need to use stat_contour(...) with geom="polygon" (rather than "line").

这篇关于用R / ggplot / ggmap填充轮廓图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆