我正在使用ggmap
和broom::tidy
函数将shapefile绘制到googlemap中,以对其进行加强(转换为数据框),但是出于某种原因,line shapefile在Google Map上显示为多边形。我不知道是什么原因造成的。
可以下载shapefile 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
答案 0 :(得分:0)
我设法解决了这个问题-希望这可以帮助那些难以导入线shapefile的人,因为我在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