图例颜色与多边形颜色并不完全相似

问题描述 投票:0回答:1

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

    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(
                      ))

        })
r shiny r-leaflet
1个回答
2
投票

图例默认是透明的,这会影响颜色的外观。更改

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())
© www.soinside.com 2019 - 2024. All rights reserved.