使用强化()或扫帚::整齐()产生类似多边形的输出上ggmap绘制线shape文件

问题描述 投票:0回答:1

我使用ggmapbroom::tidy功能来加强它(转换成数据帧)绘制shape文件到GoogleMap的,但由于某些原因行shape文件显示为谷歌地图上的多边形。我不知道是什么原因造成的。 shape文件可以下载here

下面是我的代码:

library(rgdal)
library(rgeos)
library(ggplot2)
library(ggmap)
library(broom)
Route_shape <- readOGR(dsn = "Kaputa-Mporokoso.shp")
  crs(Route_shape) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" 
    myMap <- get_map(location=Route_shape@bbox,
                       source="google", maptype="roadmap", crop=FALSE,colour = class)
      # Reformat shape for mapping purposes
      Route_shape_df <- broom::tidy(Route_shape)
      # Final map figure
      p <- ggmap(myMap) +
        geom_line(data = Route_shape_df, aes(x = long, y = lat, group=group),
                  colour = "red") 
p

我得到以下输出enter image description here

r shapefile ggmap broom
1个回答
1
投票

我设法解决这个问题 - 希望这会帮助别人谁与进口线shape文件挣扎,因为我没有看到它在其他地方SO。

geom_line()更换geom_path()

Route_shape <- readOGR(dsn = "Kaputa-Mporokoso.shp")
  crs(Route_shape) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" 
    myMap <- get_map(location=Route_shape@bbox,
                       source="google", maptype="roadmap", crop=FALSE,colour = class)
      # Reformat shape for mapping purposes
      Route_shape_df <- broom::tidy(Route_shape)
      # Final map figure
      p <- ggmap(myMap) +
        geom_path(data = Route_shape_df, aes(x = long, y = lat, group=group),
                  colour = "red") 
p

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.