如何使用R ggplot stat_summary绘制中位数和四分位数?

san*_*oku 4 statistics r ggplot2

如何将此统计摘要图中的上下点更改为25%四分位数和75%四分位数?

ggplot(data = diamonds) + stat_summary(
mapping = aes(x = cut, y = depth),
fun.ymin = min,
fun.ymax = max,
fun.y = median
Run Code Online (Sandbox Code Playgroud)

mpa*_*nco 8

重写G5W的解决方案,使用geom函数代替stat函数:

ggplot(data = diamonds) +
  geom_pointrange(mapping = aes(x = cut, y = depth),
                  stat = "summary",
                  fun.min = function(z) {quantile(z,0.25)},
                  fun.max = function(z) {quantile(z,0.75)},
                  fun = median)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


G5W*_*G5W 7

ggplot(data = diamonds) + stat_summary(
  mapping = aes(x = cut, y = depth),
  fun.ymin = function(z) { quantile(z,0.25) },
  fun.ymax = function(z) { quantile(z,0.75) },
  fun.y = median)
Run Code Online (Sandbox Code Playgroud)

钻石