GGplot2 如何更改每个箱线图组的离群值形状?

问题描述 投票:0回答:1

我想通过形状区分每个箱线图的异常值。例如,箱线图 1 使用十字,箱线图 2 使用圆形等。 我试图通过这样做来实现这一目标

ggplot(diamonds, aes(x = cut, y = price)) + geom_boxplot(outlier.shape = c(0, 1, 2, 3, 4))

只要简单地做

ggplot(diamonds, aes(x=cut, y=price, shape=cut)) + geom_boxplot()

这两个选项都失败了。如何为每个箱线图实现不同的异常值形状?

r ggplot2 boxplot
1个回答
0
投票

您可以使用

outlier.shape
参数必须通过
NULL
来分配它们,如下所示:

library(ggplot2)
ggplot(diamonds, aes(x=cut, y=price, shape = cut)) + 
  geom_boxplot(outlier.shape=NULL)

创建于 2023-10-27,使用 reprex v2.0.2

© www.soinside.com 2019 - 2024. All rights reserved.