【问题标题】:The legend colors are not perfectly similar to color of polygons图例颜色与多边形颜色并不完全相似
【发布时间】:2019-06-19 01:42:54
【问题描述】:

我正在使用小册子功能在闪亮的框架内创建交互式地图。除了传说之外,一切看起来都很棒。图例的颜色有些褪色,因此不能完美地代表多边形的颜色。怎么解决?

    renderLeaflet ({

    pal8 <- c("#FFFFE5", "#D9F0A3", "#78C679", "#006837") 
  bins=quantile(mapdata_1()$Per), na.color = "#808080",  alpha = FALSE, reverse = F)
   pal <- colorFactor(palette = pal8, domain =NULL, levels=(mapdata_1()$cat), ordered = TRUE, na.color = "#808080",  alpha = FALSE, reverse = F)

     leaflet (mapdata_()) %>% 

                      addProviderTiles("CartoDB.Positron") %>% 
                     clearControls() %>%
                     clearShapes()%>%
                        addPolygons(fillColor = ~pal(cat)) %>% 



                                   addTiles() %>%

      setView(-82.706838, 40.358615, zoom=7) %>%

                        addLegend(position = "bottomright",
                         values = ~cat,

                         pal = pal,
                         title = (paste("%",input$Age_Group_map, input$sex_map, "in", input$Year_map)) ,
                       labFormat = labelFormat(
                      ))

        })

【问题讨论】:

  • 看起来部分问题是图例是透明的,当您在addLegend 中设置opacity = 1.0 时会发生什么?
  • 效果很好!非常感谢。

标签: r shiny leaflet legend


【解决方案1】:

图例默认是透明的,这会影响颜色的外观。更改 opacity 参数以解决此问题:

addLegend(position = "bottomright",
          values = ~cat, 
          pal = pal,
          opacity = 1.0,
          title = (paste("%",input$Age_Group_map, 
                         input$sex_map, "in", input$Year_map)) ,
          labFormat = labelFormat())

【讨论】:

    猜你喜欢
    • 2019-07-25
    • 1970-01-01
    • 2011-09-25
    • 2015-08-20
    • 2015-12-27
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    • 1970-01-01
    相关资源
    最近更新 更多