简体   繁体   中英

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: 变焦= 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:

变焦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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM