Search code examples
rgoogle-mapsggplot2ggmap

Adjust font size in map plots in ggmap


I am trying to plot a number of points on a map of Germany, using the ggmap package, which works great. However, I would like to make some specific changes and do not know how to or if that is at all possible.

To make the maps, I do the following (d is a data frame with longitudes and latitudes):

map <- get_map(location = c(10.25828, 51.11484), zoom = 6, maptype = "terrain")
p <- ggmap(map)
p <- p + scale_x_continuous(limits = c(6.09500,14.95306)) + scale_y_continuous(limits = c(47.39889,55.01250)+c(0,-0.1)) 
p <- p + xlab("Longitude") + ylab("Latitude")

On that map, I then plot some points. Now, if I set zoom = 6 as above, then the map is very detailed, and lots of city names are printed, along with some white lines for the roads. This makes the map look a bit too "crowded". Here is what the map looks like: zoom = 6

The size of the pdf is also quite large which is not very practical if I want to have multiple maps.

On the other hand, if I set zoom = 5, then the background is less detailed, less roads etc are shown, and the file is smaller. However, the printed font of the city and country names is too large. Here is what it looks like:

zoom 6

So my question is: Can is somehow get a map with details as in zoom = 5, but with the font size of country and city names as in zoom = 6?

Thanks in advance


Solution

  • If you change from get_map to get_googlemap, you can pass a string to the style argument which will get passed to the Google Static Maps API. See the documentation, and a crucial reference.

    I don't think you can change text size, but you can simplify roads and remove certain labels like so:

    map <- get_googlemap(center = c(10.25828, 51.11484), zoom = 6, maptype = "terrain", 
                         style = 'feature:road|element:all|visibility:simplified&style=feature:administrative.locality|element:labels|visibility:off')
    

    which returns

    simplified map of Germany

    If you want more labels, it's probably easier to insert them later in R. Adjust as you like.