Let me reproduce the reproducible example presented by Kevin Ears in this question :
set.seed(123) dat <- data.frame( x=rep( c(1, 2, 3, 4), times=25 ), y=rnorm(100), gp=rep(1:2, each=50) ) p <- ggplot(dat, aes(x=factor(x), y=y)) p + geom_boxplot(aes(fill = factor(gp)))

Then, following Arun’s advice, I tested (position = position_dodge(.)) , But with geom_boxplot instead of geom_bar , and it worked.
In this case, there is no need to change the width of the boxes.
So, changing the last line of the above code to:
p + geom_boxplot(aes(fill = factor(gp)),position=position_dodge(1))
did the trick.

Andre Silva
source share