R 避免在ggplot2中使用geom_点进行打印覆盖
在ggplot2中,geom_点默认为在当前打印上打印。例如,在调用geom_箱线图后调用geom_点会导致在箱线图上绘制的点:R 避免在ggplot2中使用geom_点进行打印覆盖,r,ggplot2,data-visualization,R,Ggplot2,Data Visualization,在ggplot2中,geom_点默认为在当前打印上打印。例如,在调用geom_箱线图后调用geom_点会导致在箱线图上绘制的点: ggplot(iris, aes(x = "All", y = Sepal.Length)) + geom_boxplot() + geom_point(aes(color=Species), position = "jitter") 是否有一种方法可以将点分别绘制到侧面,而不是在箱线图上 在我的特殊情况下,我想这样做是因为点模糊了绘图(即使有透明度等)
ggplot(iris, aes(x = "All", y = Sepal.Length)) +
geom_boxplot() +
geom_point(aes(color=Species), position = "jitter")
是否有一种方法可以将点分别绘制到侧面,而不是在箱线图上
在我的特殊情况下,我想这样做是因为点模糊了绘图(即使有透明度等),这不是示例数据集的问题。您可以通过为箱线图和点提供单独的x值来分别绘图:
ggplot(iris, aes(y = Sepal.Length)) +
geom_boxplot(aes(x="Boxplot")) +
geom_point(aes(x="Points", color=Species),
position = position_jitter(width=0.15, height=0))
另一种选择是按物种使用箱线图:
ggplot(iris, aes(y = Sepal.Length)) +
geom_boxplot(aes(x="All Data"), width=0.5) +
geom_boxplot(aes(x="By Species", colour=Species), width=0.5,
position=position_dodge(width=0.6))
下面是两个图的样子: