Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active October 14, 2021 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdsumner/7703f1cd631853b493731509306a52a8 to your computer and use it in GitHub Desktop.
Save mdsumner/7703f1cd631853b493731509306a52a8 to your computer and use it in GitHub Desktop.

get a range of ggmap that crosses longitude 180

library(ggmap)
mapwest <- get_map(location = c(left = -180, bottom = -40,right = -120,top = 20), source = "google", maptype = "terrain")
mapeast <- get_map(location = c(left = 110, bottom = -40,right = 180,top = 20), source = "google", maptype = "terrain")

## combine the images together (and then we'll reconstruct their class/metadata)
map <- as.raster(cbind(as.matrix(mapeast), as.matrix(mapwest)))

## get the class/metadata
atts <- attributes(mapeast)
## and modify it (in this case we only need long = -120 which is 240E)
bb <- atts$bb
bb$ur.lon <- 240
## put the metadata back together
atts$bb <- bb
## put the class/metadata back on the new image (not the formal way to construct but we're brave/foolish)
atts$dim <- dim(map)
attributes(map) <- atts


ggmap(map)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment