The idea here is to draw a legend for each geom
with the same aesthetic. In the example below the legend generated assumes that these two different layers are in the same scale, resulting in this map.
I want, as a result, that the legend in the graph is separated in two, so I can change these with a scale_fill_*
for each layer.
I'm aware of this solution: https://stackoverflow.com/a/24874007/11056037, but I'm looking for a more elegant and scalable way to do this.
library(tidyverse)
library(sf)
library(geobr)
mun <- map(11:12, read_municipality) %>%
map(mutate, index = seq_along(code_muni), .before = geom)
mun[[2]] <- mun[[2]] %>%
mutate(index = index + 100)
mun <- mun %>%
map(
~mutate(.x, index = cut(index, quantile(index), include.lowest = TRUE))
)
ggplot() +
geom_sf(data = mun[[1]], aes(fill = index)) +
geom_sf(data = mun[[2]], aes(fill = index))
Thanks.