- 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?
- 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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.