I am trying to create a grouped violin plot (see figure), where I am plotting 3 levels for four categorical variables. The plot comes out fine given the data other than the fact that the boxes are the same colour as the wider violin plots behind making them difficult to view. Ideally I would like all the boxes to remain white throughout. I understand that the reason the boxes are changing colour is in response to the fill
that I have chosen. I am wondering if there is a way to separate the fill for the geom_violin
from the geom_boxplot
.
Here is the stripped down code I am using
p <- ggplot(df, aes(x=metric, y=value, fill=variable))+
geom_violin(width=0.9, position=position_dodge(0.75), bw=1.5)+
geom_boxplot(width=0.3, outlier.shape = NA, position=position_dodge(0.75))+
scale_fill_manual(values=c("gray50", "gray75", "gray100"),
breaks=c("res.error.random", "res.error.increase", "res.error.decrease"),
labels=c("random cost", "overestimated", "underestimated"))