Is it possible to create one single legend of a numeric colour variable, which is coloured and filled along a gradient of colours but has different alpha levels for fill and col?
Below is an example, which shows it producing 2 legends.
I could turn one of the legends off. But ideally I would be able to produce a single legend which showed the col as well as the fill with the appropriate transparency with both
library(dplyr)
library(ggplot2)
library(palmerpenguins)
plot_data <- penguins %>%
group_by(species) %>%
summarise(across(c(body_mass_g, flipper_length_mm), ~mean(., na.rm = TRUE)))
ggplot(plot_data) +
geom_col(aes(x = species, y = body_mass_g,
col = flipper_length_mm,
fill = flipper_length_mm)) +
scale_color_gradientn(colors = viridis::viridis(20)) +
scale_fill_gradientn(colors = scales::alpha(viridis::viridis(20), 0.25))