0

I want to plot the boxplot:

library("ggplot2")
p <- ggplot(mpg, aes(class, hwy))
p + geom_boxplot(aes(colour = drv))

but the boxplot showed overlapped within each class. enter image description here

How can I add distance between boxes?

Feng Tian
  • 1,559
  • 1
  • 18
  • 27

1 Answers1

2

just try following variant

library("ggplot2") dodge <- position_dodge(width = 0.9) p <- ggplot(mpg, aes(class, hwy)) p+geom_boxplot(aes(fill = drv),position=dodge)

With position=dodge you can set the distance between boxplots Hope this helps

Best

Pavlo

Pavlo
  • 56
  • 6