I am plotting a shapefile into a googlemap using ggmap
and broom::tidy
function to fortify it (convert to a dataframe), but for some reason the line shapefile appears as a polygon on the google map. I have no idea what is causing it.
The shapefile can be downloaded here
Below is my code:
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