So, I made a graph using ggplot2 and I used alpha to achieve a gradient. I would like to somehow visualize the use of alpha in the legend. As can be seen in the plot, I just get empty boxplot-legend-items. I am not even sure why it shows alpha in a discrete way, since I give it an integer variable for scaling it. I would like the legend to display alpha in a continous or discrete way and the color gray (like, from medium to dark gray) or in another way making sense. How can I do this? I always struggle with alpha legends somehow.
Here is the current plot:
Here is some dummy data and the code:
fluct_all <- data.frame(
"type" = rep(c("tls", "tls_rgb", "tls_geo", "tls_rgb_geo"), each=50),
"fold" = rep(1:5, 10),
"test_acc" = rnorm(200))
ggplot(fluct_all, aes(x = type, y = test_acc, alpha = fold, fill = type, group = interaction(type, fold))) +
stat_boxplot(geom = "errorbar", alpha = 1, width = 0.2, position = position_dodge(0.9)) +
geom_boxplot(outlier.alpha = 0, outlier.size = 0, fill = "white", alpha = 1, position = position_dodge(0.9)) +
geom_boxplot(outlier.alpha = 0.01, outlier.size = 0.75, position = position_dodge(0.9)) +
scale_fill_manual(
# values = color_scale_class,
name = "Input Data\nCombination",
labels = c("TLS", "TLS & GEO", "TLS & RGB", "ALL")
) +
theme_light() +
# theme(
# text = element_text(size = 14, family = "Calibri"),
# legend.title = element_text(family = "Calibri", size = 16),
# legend.key.width = unit(0.75, "cm"),
# legend.key.height = unit(1, "cm"),
# legend.text = element_text(family = "Calibri", size = 14)
# ) +
scale_x_discrete(labels = c("TLS", "TLS & GEO", "TLS & RGB", "ALL")) +
xlab("") +
ylab("Test Accuracy\n") +
scale_alpha_continuous(range = c(0.5, 1), name = "\nFold")

