Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我使用以下代码:
data(mtcars) ggplot(mtcars, aes(x=factor(cyl), y=mpg)) + geom_jitter(aes(colour=factor(gear)), width = 0.1) + geom_boxplot(aes(fill=factor(gear)), alpha=0.6)
结果如下:
但我希望 geom_jitter 中的彩色点直接位于相应(!)箱线图的后面。有没有办法做到这一点?
解决方案是 aosmith 和他的链接提到的 position_jitterdodge。
library(ggplot2) data(mtcars) ggplot(mtcars, aes(x=factor(cyl), y=mpg, fill=factor(gear), colour=factor(gear))) + geom_point(position = position_jitterdodge()) + geom_boxplot(alpha=0.6)
结果如下所示: