1

我无法用 R 在 ggmap 上覆盖 osmar 形状。

我得到了 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输出

4

1 回答 1

1

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

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")
于 2016-06-04T12:14:13.173 回答