How to use R ggplot stat_summary to plot median an

2019-05-11 19:19发布

how to change the lower and upper point in this stat summary plot to 25% quartile and 75% quartile?

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

)

2条回答
劫难
2楼-- · 2019-05-11 19:43

Rewritting G5W's solution, using the geom function instead of the stat function:

ggplot(data = diamonds) +
  geom_pointrange(mapping = aes(x = cut, y = depth),
                  stat = "summary",
                  fun.ymin = function(z) {quantile(z,0.25)},
                  fun.ymax = function(z) {quantile(z,0.75)},
                  fun.y = median)

enter image description here

查看更多
一纸荒年 Trace。
3楼-- · 2019-05-11 19:47
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)
查看更多
登录 后发表回答