I want to adapt the width of the box in the category \"random\" to the same width of the other boxes in the plot. It is now a single group, whereas the other groups contain
Starting in ggplot2 3.0.0 there is a preserve argument in position_dodge() that allows the width of a single element to be preserved. There is also a second dodging function, position_dodge2(), which changes how elements are spread over the plotting area with overlap.
If you want to have all boxes the same width with the single box centered on its x tick, you can use preserve = "single" in position_dodge2().
ggplot(TablePerCatchmentAndYear, aes(x = NoiseType, y = POA, fill = TempRes)) +
geom_boxplot(lwd = 0.05, position = position_dodge2(preserve = "single") ) +
ylim(-1.25, 1) +
theme(legend.position='bottom') +
scale_fill_discrete(name = '')
If you want to have all boxes the same width and mirror the dodging for the single element group with the other groups you can add preserve = "single" to position_dodge().
ggplot(TablePerCatchmentAndYear, aes(x = NoiseType, y = POA, fill = TempRes)) +
geom_boxplot(lwd = 0.05, position = position_dodge(preserve = "single") ) +
ylim(-1.25, 1) +
theme(legend.position='bottom') +
scale_fill_discrete(name = '')