1

I am trying to overlay data on top of a map of Canada, however I can't adjust the zoom as I would like. In the map, I want to be able to see the lines for each province anong with its name (so using map("world", "Canada") isn't desirable)

I have tried altering the zoom, but one is too zoomed out and the other is too zoomed in:

qmap(location = "Canada", zoom = 3)

enter image description here

qmap(location = "Canada", zoom = 4)

enter image description here

I have tried researching on how to crop the image but have been unsuccessful

Thank you!

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
jarvsh2929
  • 23
  • 1
  • 4
  • Do you need to use `ggmap` to create this map? Also, what is the spatial range of your data? Having an entire map of Canada may not be suitable if the data are concentrated to one area. – ccapizzano Jun 08 '17 at 19:20

1 Answers1

3

You can approach this using either the maps and mapsdata packages or continue with ggmap. It just depends on how much detail you want.

library(raster)
library(maps)
library(mapdata)
canada<-getData("GADM",country="CAN",level=1)

plot(canada,xlim=c(-141,-53),ylim=c(40,85),col="gray80",border="gray40",axes=T,las=1)
invisible(text(getSpPPolygonsLabptSlots(canada),labels=as.character(substr(canada$HASC_1,4,5)), 
               cex=0.75, col="black",font=2))

enter image description here

Using ggmap, you can specify a bounding box when grabbing your spatial data. It still overplots some of the area you are interested in (i.e., plots most of the US). Therefore, reapplying the bounding box values to the ggmap function cuts down the viewable area.

library(ggmap)

lats<-c(40,85)
lons<-c(-141,-53)
bb<-make_bbox(lon=lons,lat=lats,f=0.05)
cda<-get_map(bb,zoom=3,maptype="terrain")
ggmap(cda)+xlim(lons)+ylim(lats)+theme_bw()+labs(x="Longitude",y="Latitude")

enter image description here

ccapizzano
  • 1,556
  • 13
  • 20