0

I can achive Plotting multiple maps with ggmap which is also possible with faceting as described in Kale & Wickham (2013) R Journal paper. But I would like to plot a multiple series of maps that pan around particular, zoomed areas of the city. This is sort of achievable if I look at the city coordinates obtained with geocode() function and roughly figure out what I need to subtract or add from longitude/latitude on each side of pan the view. Such solution is far from ideal. Let me illustrate with an example (note: multiplot function used from Cookbook For R).

library(ggmap)
library(RgoogleMaps)

#getting Bristol lat/long
BRS <- geocode("Bristol, UK")

#get the first (central) map from the coordinates
BristolMapCenter <- ggmap(get_map(c(lon=BRS$lon, lat=BRS$lat), zoom = 15))

#get the second map panned to the right by adding approx. 0.015 to longitude
BristolMapRight <- ggmap(get_map(c(lon=BRS$lon+0.015, lat=BRS$lat),zoom = 15))

#multiplot function
multiplot(BristolMapCenter, BristolMapRight, cols=2)

enter image description here

As you can see this is far from ideal as there is overall (I don't want overlap, I want "lined up continuation"), if not to say clunky, especially if I want to get a larger panning of the surrounding areas (lets say 9-12 maps), do it for multiple cities, plot some data on the top of it, and still have enough time in my life to grab a pint on the sun. So I wonder if there is any fast, sleek and automatic way to get those panned maps based on specific central coordinates?

Community
  • 1
  • 1
Geek On Acid
  • 6,330
  • 4
  • 44
  • 64
  • I'm not sure I understand your goal. You want multiple maps showing different areas of a city. Is the idea that the maps, if plotted directly adjacent would "line up" nicely? Or do you want some amount of overlap as in your example? Do you essentially want a big map that's cut up into little squares? – Gregor Thomas Jun 24 '15 at 15:40
  • @Gregor I want multiple maps showing different areas of a city that "line up" without the overlap. – Geek On Acid Jun 24 '15 at 15:47
  • And, just to be clear, why not just use a single big map? – Gregor Thomas Jun 24 '15 at 15:48
  • @Gregor Because I want to plot data on the top of those maps and I want to have a flexibility to adjust the level of zoom to create various versions of the "multiple mapped panning". So for instance, I would have one series of multiples with `zoom=10`, and another, more fine, with `zoom=15`. I also want flexibility with the kind of data I want to add to each multiply - i.e. some data would be present only on the selected multiplies. – Geek On Acid Jun 24 '15 at 15:52

1 Answers1

2

Starting with your code:

library(ggmap)
library(RgoogleMaps)

#getting Bristol lat/long
BRS <- geocode("Bristol, UK")

#get the first (central) map from the coordinates
BristolMapCenter <- ggmap(get_map(c(lon=BRS$lon, lat=BRS$lat), zoom = 15))

we can extract the absolute ranges covered by the map at this zoom level:

z15width = sapply(BristolMapCenter$data, function(x) abs(diff(range(x))))

And then add multiples of this to your BRS coordinates.

BristolRight = ggmap(get_map(c(lon = BRS$lon + z15width["lon"],
                               lat = BRS$lat), zoom = 15))

These should line up nicely.

multiplot(BristolMapCenter, BristolRight, cols = 2)

enter image description here

You can move in any orthogonal direction by integer multiples of z15width, and things should continue to line up. And of course, you get a different width at a different zoom. You could write a script to calculate the width for many different zoom values and store that somewhere and reference it later.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294