Is there a way to add subtitles to leaflet legends? The following example produces a functioning legend. However, is there a way to combine the subgroups to the same legend?
I could imagine this could be solved by injecting custom CSS-code to the legend by the className
parameter (default className = "info legend"
). But I'm a complete novice to CSS.
https://www.rdocumentation.org/packages/leaflet/versions/2.1.1/topics/addLegend
Helpful might as well be this work, done for the spacing to the NA-class (https://github.com/rstudio/leaflet/issues/615#issuecomment-656035992)
To illustrate what I would like to have I created different legend entries, but they are not properly connected.
library(leaflet)
colors <- colorFactor(palette="viridis",
domain=gadmCHE@data$NAME_1, na.color="transparent")
Deutsch <- gadmCHE[c(1:6,9:12,14:20,22,25:26),]
Italienisch <- gadmCHE[c(21),]
Französisch <- gadmCHE[-c(1:6,9:12,14:22,25:26),]
gadmCHE %>% leaflet() %>% addTiles() %>%
addPolygons(fillColor = ~colors(NAME_1), fillOpacity = 1) %>%
addLegend(position = "topright", pal = colors, values = Deutsch@data$NAME_1, title = "Deutsch")%>%
addLegend(position = "topright", pal = colors, values = Italienisch@data$NAME_1, title = "Italiensch")%>%
addLegend(position = "topright", pal = colors, values = Französisch@data$NAME_1, title = "Französisch")
I actually would need to replicate the following. Please bear with me as
I'm aware it would be better to shorten the legend entries, but that has quite some legacy attached to it. It is unlikely I'll be successful on that.
The attribution of the Cantons to different language regions is not... correct.
It further is not exactly what I would like to show, as in my case, the whole legend entry cannot be made shorter (i.e. a, Senkrecht durchwaschene Böden, Normal durchlässig, sehr tiefgründig)