Add shapefile to ggmap

Viewed 2604

Somewhat similar to the issue described here I am having troubles aligning a shapefile and ggmap object.

  1. My shapefile consists of local area boundaries in Victoria, Australia, and I am trying to overlay them on top of a google map of the state (Victoria).

    The source shapefile has the following PROJ4 string (extracted from the prj file)

    [+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs]
    

    which corresponds to EPSG:4283.

    Here's the summary of my shapefile object sp:

    > summary(sp)
    Object of class SpatialPolygonDataFrame
    Coordinates:
            min        max
    x  96.81677 159.109219
    y -43.74051  -9.142176
    Is projected: FALSE
    proj4string:
    [+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs]
    
  2. I convert the shapefile to match google's pseudo Mercator projection (at least that's what I think I'm doing)

    sp <- spTransform(sp, CRS("+proj=longlat +init=epsg:3857"))
    

    and turn sp into a fortified dataframe df.sp.

  3. I then use

    map <- get_map("Victoria", zoom = 7, maptype = "terrain", source = "google")
    

    to get a google terrain map of Victoria, and (gg)plot them

    ggmap(map) + geom_polygon(data = df.sp, aes(x = long, y = lat, group = group)) + coord_equal() + theme_map()
    

Map of Victoria

It's clear from the resulting plot that shapefile coordinates and googlemap coordinates don't overlap. Am I doing something wrong with the coordinate transformation? How do I properly match shapefile and googlemap coordinates? I would appreciate any help/insight into this matter.

1 Answers
Related