Adjust font size in map plots in ggmap

2019-07-19 05:04发布

问题:

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:

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:

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

回答1:

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

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



回答2:

As far as i know most map services include the labels in the rendered map tiles. I never had this problem in r, but with other map services. Rendering with smaller labels using a customizable map service should be possible, but ggmap only offers CloudMade maps which might be a bit too expensive.

I would recommend using a different library if possible, maybe the one described at r-bloggers.com they use a custom made map from MapBox a free service (up to a certain limit) i would recommend.