I'm making a boxplot in which x
and fill
are mapped to different variables, a bit like this:
ggplot(mpg, aes(x=as.factor(cyl), y=cty, fill=as.factor(drv))) +
geom_boxplot()
As in the example above, the widths of my boxes come out differently at different x
values, because I do not have all possible combinations of x
and fill
values, so .
I would like for all the boxes to be the same width. Can this be done (ideally without manipulating the underlying data frame, because I fear that adding fake data will cause me confusion during further analysis)?
My first thought was
+ geom_boxplot(width=0.5)
but this doesn't help; it adjusts the width of the full set of boxplots for a given x
factor level.
This post almost seems relevant, but I don't quite see how to apply it to my situation. Using + scale_fill_discrete(drop=FALSE)
doesn't seem to change the widths of the bars.