I'm trying to retrieve a tile of Downtown Los Angeles from Google Maps using
ggplot2, specifically the function
get_googlemaps, and then I want to overlay a shapefile over it displaying the boundary of Downtown Los Angeles. (The shapefile is from the LA Times, here) I clipped the shapefile to only show DTLA by doing this to retain the attributes:
downtown <- readOGR(".","neighborhoods.shp") downtown@data$id <- rownames(downtown@data) downtown.points <- fortify(downtown,region="id") downtown.df <- join(downtown.points,downtown@data,by="id")`
I then clipped out everything that wasn't DTLA by subsetting
downtown.df <- downtown.df[downtown$slug="downtown",]
downtown.df plots fine with
ggplot(downtown.df, aes(x=long,y=lat)) + geom_polygon(fill=NA, color="black") + coord_fixed().
Then I go to get the DTLA map using ggmap.
dtlamap <- get_googlemap(location = c(lon=-118.250347,lat=34.044899), zoom=14, maptype="roadmap", style="element:labels|visibility:off| style=feature:administrative.land_parcel| visibility:off|style=feature:administrative.neighborhood |visibility:off") ggmap(dtlamap)
The map that appears is correct, but the latitude and longitude are warped. The latitude range is 29.74 to 29.78 and the longitude range is -95.39 to -95.34. So when I try to plot
downtown.df on top of it, it doesn't display because the coordinates are off.
The polygon for the DTLA shp file is in the WDS84 system and I assume the Google Maps is too, or it wouldn't have pulled up the correct map...?
I looked at this google group answer here but I can't get the solution to work for me using