ggplot2 - does stat_summary produce ..y..? How wou

2019-06-24 19:27发布

  1. Curious - why doesn't stat_summary produce any new variables? Would seems very useful to have access to the y values, or am I missing something?
  2. If I used stat_summary to get the mean of all y's at a given x, is there some way to identify the new y (the means) that is the max/min of all new y's? So lets say I want points for all means, but then I want to color the highest mean point and the lowest mean point with different colors. How would I do that?

标签: r ggplot2
1条回答
叼着烟拽天下
2楼-- · 2019-06-24 19:49

As Brandon says, I strongly recommend to summarize data by yourself before using ggplot, but you can access the summarized "y" like this:

d <- data.frame(expand.grid(x=1:4, rep=1:3), y=rnorm(4*3))
ggplot(d, aes(x, y)) + 
  stat_summary(mapping=aes(colour=factor(ifelse(min(..y..)==..y.., 1, ifelse(max(..y..)==..y.., 3, 2))
)), fun.y=mean, geom="point")

maybe this is difficult to understand though.

查看更多
登录 后发表回答