【问题标题】:How to overlay an osmar shape over a ggmap with R?如何用 R 在 ggmap 上覆盖 osmar 形状?
【发布时间】:2016-06-04 12:05:59
【问题描述】:

我在使用 R 将 osmar 形状覆盖在 ggmap 上时遇到问题。

我得到了 osmar 对象(在本例中是威斯康星州密尔沃基的 Lake Park):

lp<-get_osm(relation(6044259), full=T)

我把它转换成一个形状:

lpp<-as_sp(lp, "lines")

这看起来不错,我看到了公园的轮廓:

[plot(lpp)][1]

然后我尝试将其覆盖在地图上:

area.points <- fortify(lpp)
mapImage <- get_map(location = c(lon = -87.89, lat = 43.05),  color = "color",           source = "google",  zoom = 13)
ggmap(mapImage) + geom_path(aes(x=long,y=lat), data=area.points, color=colors[9], alpha=0.5)+labs(x="Longitude", y="Latitude")

当我绘制地图和公园的区域覆盖图时,它并没有清晰地绘制公园轮廓,但似乎也在每个点之间绘制了一条线。

ggmap output

【问题讨论】:

    标签: r google-maps osmar


    【解决方案1】:

    在 geom_path 的 aes 部分添加 group=group 解决了这个问题:

    ggmap(mapImage) + geom_path(aes(x=long,y=lat,group=group), data=area.points, 
                                color=colors[9], alpha=0.5)+
                      labs(x="Longitude", y="Latitude")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多