小编Luk*_*uer的帖子

ggplot2 - 使用 geom_boxplot 生成带有自定义胡须的水平箱线图时出错

出于教育目的,我尝试使用 ggplot2 生成与点图结合的水平箱线图。但是,我想生成一个在 2.5% 和 97.5% 百分位数处带有须线的自定义箱线图,而不是geom_boxplot. 因此,我决定使用以下代码:

y <- rnorm(100)
df = data.frame(y)
df_boxplot <- data.frame(
  x_coord = 0.5,
  y0 = quantile(y, 0.025),
  y25 = quantile(y, 0.25),
  y50 = median(y),
  y75 = quantile(y, 0.75),
  y100 = quantile(y, 0.975)
)
# Vertical orientation with custom whiskers works
ggplot() +
  geom_boxplot(data = df_boxplot,
    aes(x = x_coord, ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100),
    stat = "identity"
  ) +
  geom_jitter(data = df, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 boxplot

1
推荐指数
1
解决办法
193
查看次数

标签 统计

boxplot ×1

ggplot2 ×1

r ×1