Goal:
Plot stat_summary
points with full opacity over box plots with variable alpha.
MWE:
################################################################################
# !Important!
# Assume that `palette1` is already defined, and shared between multiple figures
################################################################################
ncols = length(unique(mtcars$gear))
palette1 = scales::hue_pal()(ncols)
names(palette1) = sort(unique(mtcars$gear))
p = ggplot(mtcars, aes(x=as.factor(gear), y=mpg,fill=as.factor(gear),alpha=as.factor(cyl))) +
geom_boxplot() +
scale_alpha_discrete(range = c(0.1, 0.8),guide = guide_legend(override.aes = list(fill = "black"))) +
rotate_x_text(45) +
facet_grid(~gear,scale="free") +
stat_summary(fun=mean, geom="point", shape=5, size=5,position = position_dodge(.75),stroke=1.5)
set_palette(p, palette1)
Current Behavior:
The reduced opacity of stat_summary
points makes them hard to see.