2017-04-18 35 views
0

我已經使用https://mapstyle.withgoogle.com/自定義了使用ggmap的樣式。我的問題是如何將JSON集成到我的R代碼中。ggmap的自定義地圖樣式

我嘗試下面的代碼無濟於事:

map <- get_googlemap(center = 'London', zoom = 15, 
        style = c('element:labels|visibility:off', 'feature:road.local|visibility:off')) 
ggmap(map) 

它與單純卻不能在一起的兩種風格的命令。我的代碼中的錯誤在哪裏?

回答

0

我不清楚自己ggmap是如何接收樣式的,但get_googlemap有一個參數可以將字符串注入發送到Google Maps API的URL中。基於Google Maps docs,您的字符串看起來格式正確,用於注入。您可以將這些樣式規格中的每一個摺疊成單個字符串,並將其分配給參數inject而不是style

所以

stylestr <- sprintf("&style=%s", c("element:labels|visibility:off", "feature:road.local|visibility:off") %>% paste(collapse = "")

將產生可以作爲你的inject參數字符串&style=element:labels|visibility:off&style=feature:road.local|visibility:off

。 (我用sprintfpaste,以方便添加樣式規格的整體轉換。)

0

我已經開發出一種新的封裝ggmapstyles,這應該有助於解決這個問題:https://github.com/mikey-harper/ggmapstyles

包,您可以選擇設計從Snazzy Maps,並使用樣式從頁面是將網址複製到樣式簡單:

devtools::install_github("mikey-harper/ggmapstyles") 
library(ggmapstyles) 

map <- get_snazzymap(center = 'London', 
        mapRef = "https://snazzymaps.com/style/61/blue-essence") 
ggmap(map) 

enter image description here

如果你沒有找到你喜歡的設計,你可以免費加入Snazzy Maps,並在Web瀏覽器中製作自己的定製設計。