I think this is a combination of poor documenation, plus a bug in ggmap.
Explanation
If you look at the example on Google Documentation you see that styles are separated by &style=
&style=feature:road.local%7Celement:geometry%7Ccolor:0x00ff00&style=feature:landscape%7Celement:geometry.fill%7Ccolor:0x000000&style=element:labels%7Cinvert_lightness:true
So in your example, if you wanted your two styles
style1 <- c(feature = "poi.medical", element = "geometry", color = "red")
style2 <- c(feature = "poi.park", element = "geometry", color = "blue")
This woud look something like
&style=feature:poi.medical|element:geometry|color:red&style=feature:poi.park|element:geometry|color:blues
In ?get_googlemap
, for the style
argument it says
character string to be supplied directly to the api for the style argument or a named vector (see examples)
And in the source code we see that it can also supposedly handle lists. So if we create a list out of our styles we get
style <- list(style1, style2)
Which, when run through the get_googlemap
gives the url
map <- get_googlemap("new york city",
zoom = 12,
maptype = "roadmap",
style = style)
...&style=style=c(%22poi.medical%22,%20%22geometry%22,%20%22red%22)&style=c(%22poi.park%22,%20%22geometry%22,%20%22blue%22)&sensor=false
Which is also incorrect.
And similarly for a concatenated vector of styles we get an incorrectly formatted URL
style <- c(style1, style2)
map <- get_googlemap("new york city",
zoom = 12,
maptype = "roadmap",
style = style)
...&style=feature:poi.medical%7Celement:geometry%7Ccolor:red%7Cfeature:poi.park%7Celement:geometry%7Ccolor:blue&sensor=false
Solution
Force it to use a &sytle=
value as the first (unnamed) element in the 2nd (and subsequent) style vector, and concatenate them using c()
, rather than list()
style1 <- c(feature = "poi.medical", element = "geometry", color = "red")
style2 <- c("&style=", feature = "poi.park", element = "geometry", color = "blue")
style <- c(style1, style2)
map <- get_googlemap("new york city",
zoom = 12,
maptype = "roadmap",
style = style)
plot(map)
And now a separate plug for my gooleway package, where you can specify the style using JSON, and the map is interactive
library(googleway)
style <- '[{"featureType": "poi.park","elementType": "geometry","stylers": [{"color": "#00FF00"}]},{"featureType":"poi.medical","elementType":"geometry","stylers":[{"color":"#FF00FF"}]}]'
map_key <- "you_need_an_api_key"
google_map(key = map_key, location = c(40.7128, -74.0059),
zoom = 13, height = 800,
styles = style)