在 geom_boxplot 中取消对齐过度绘制的异常值

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

我有一个向量,其中有一些重要的异常值,总共 5 个。只有 3 个异常值是不同的。因此,相同的值会在 geom_boxplot 中过度绘制:

df <- data.frame(
  Ratio = c(rep(1,100), rep(0:1, 100), 4.5, 4.5, 3.5, 3.5, 7),
  ID = 1:305
)

df  %>%
  ggplot(aes(y = Ratio)) +
  # boxplot:
  geom_boxplot(
    width = 0.2,
  )

如何使所有 5 个异常值在图中可见?

r ggplot2
1个回答
0
投票

类似的东西

df  %>%
  ggplot(aes(y = Ratio, x=0)) +
  # boxplot:
  geom_boxplot(
    width = 0.2,
    outlier.alpha = 0 # To make default outliers invisible
  ) +
  geom_jitter(
    data = df %>% filter(Ratio > 2), # Adjust cutoff as desired
    width = 0.01, 
    height = 0
  )

给予

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