我使用ggmap
和broom::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
我设法解决这个问题 - 希望这会帮助别人谁与进口线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