ggmap 在第二个透明背景 google 地图上分层

ggmap layering on a second transparent background google map

我正在尝试使用 inset_ggmap

在仅包含道路的第二张 google 地图上分层,但未成功
m <- ggmap(dt_map_b) +
  geom_polygon(data = map_data, 
               aes(fill = outcomes,
                   x = long, 
                   y = lat.x, 
                   group = group),
               alpha = 0.5) +
  inset_ggmap(dt_map_r)

一切正常,但当我关闭地形特征的可见性时,我发现它全部回到下方,遮住了我的初始图像

我知道可以更改地图的背景颜色 with the google api 但是可以从 ggmap 更改背景颜色吗?也许通过更改添加到 URL?

的内容
  m <- leaflet(outcomes_map) %>%

  addMapPane("base_map", zIndex = 410) %>%    # Level 1: base
  addMapPane("polygons", zIndex = 420) %>%    # Level 2: polygons
  addMapPane("waters", zIndex = 430) %>%      # Level 3: waters
  addMapPane("roads", zIndex = 440) %>%       # Level 4: roads
  addMapPane("labels", zIndex = 450) %>%      # Level 5: labels

    # adds in the base map

    addTiles(urlTemplate = base_map,
             options = pathOptions(pane = "base_map")) %>%

    # adds in the polygons containing the loaded data

    addPolygons(color = ~pal5(rank),
                weight = 1,
                fillOpacity  = 1,
                options = pathOptions(pane = "polygons")) %>%

    # adds in the other layers for aesthetics like roads, water, and place labels

    addTiles(urlTemplate = water_map,
             options = pathOptions(pane = "waters")) %>%

    addTiles(urlTemplate = road_map,
             options = pathOptions(pane = "roads",
                                   opacity = 0.75)) %>%

    addTiles(urlTemplate = label_map,
             options = pathOptions(pane = "labels")) %>%

      setView(lng = -80.843297, lat = 35.225256, zoom = 11)

        # you can export as either an interactive map or a static image

        mapshot(m, url = file.path(graph_export_path,"alrighty.html"))

        mapshot(m, file = file.path(graph_export_path,"alrighty.png"))

事实证明,使用 leaflet 和 mapshot() 更容易完成。您真正需要做的就是为您感兴趣的功能制作几个不同的图层,然后创建窗格以按照您想要的顺序组织它们。您需要设置一个 mapbox 帐户并使用 api 拉入地图,但这在 R 文档的传单中非常简单。这样您就可以对地图的外观进行更多自定义!