Search code examples
rgoogle-mapsggplot2ggmap

ggmap in R - keep google copyright information on cropped map


I was wondering if anyone knows how to keep the google copyright information on maps plotted (with a new scale) by ggmap in R?

For example:

library(ggmap)
library(ggplot2)

# download basemap
ggmap::register_google(key="xxx") # insert your hey here xxx
ggmap::ggmap_show_api_key()
base_map <- get_googlemap(center = c(lon= -2.325278, lat=54.6000000), zoom = 5, style = 'element:labels|visibility:off',color= "bw")

When I plot base_map without changing the scale the copyright information is inserted at the bottom of the plot as so:

ggmap(base_map, extent = "panel")

map_with_copyright_info)

However, when I plot base_map with a new x and y axis to zoom into mainland Britain. I also crop off the copyright info. As below:

ggmap(base_map, extent = "panel")+
  scale_x_continuous(limits = c(-7, 3), expand = c(0, 0)) +
  scale_y_continuous(limits = c(49.5, 59), expand = c(0, 0))

map_zoom_noCopyright

Does anyone know how I can get the second plot but with the copyright information that I need for publication?

I have tried to change the zoom= argument in the get_googlemap() function but it always seems to either cut the top or bottom off the UK and I need to be able to see the whole area for when I plot my data.

Thank you so much for your help in advance!


Solution

  • I used a lot ggmap, and this type of problem I could not solve then in an elegant way. But there is a way to achieve something like what you want (doing kind of manually). With geom_rect making the lightbox, and with geom_text writing the copyright information.

    ggmap(base_map, extent = "panel")+
      scale_x_continuous(limits = c(-7, 3), expand = c(0, 0)) +
      scale_y_continuous(limits = c(49.5, 59), expand = c(0, 0)) +
      geom_rect(ymin = 49.5,ymax = 49.7, fill = 'white', alpha = 0.1, xmin = -3.35, xmax = 3) +
      geom_text(y = 49.6, x = -0.2, size = 2.5,
                 label = 'Map data ©2020 GeoBasis-DE/BKG (©2009), Google, Inst. Geogr Nacional') 
    ggsave('Map.jpg', width = 7, height = 9, units = 'in')
    

    The size and limits of geom_rect and geom_text must be edited manually according to the size of the save file. In this example, I provide the ggsave I used for it and plot in a nice way.