2017-02-16 152 views
0

我想绘制箱线图:如何避免在ggplot2 boxplot中重叠?

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

但箱线图显示出每类中的重叠。 enter image description here

如何添加框之间的距离?

+1

是的,增加位置= position_dodge(1)做的诀窍... – AndreiR

回答

0

只是尝试以下变种

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

随着position=dodge你可以设置箱线图之间的距离 希望这有助于

最佳

Pavlo