ggplot2 - 做stat_summary产生..y ..?我将如何在y上子集? [英] ggplot2 - does stat_summary produce ..y..? How would I subset on y?
本文介绍了ggplot2 - 做stat_summary产生..y ..?我将如何在y上子集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 好奇 - 为什么stat_summary不生成任何新变量?如果我使用stat_summary获得给定x的所有y的均值,那么有没有一些方法可以用来获得y值,或者我错过了什么? 找出所有新y的最大/最小值的新y(手段)?所以我们可以说我想要所有手段的点数,但是我想用不同颜色给最高平均点和最低平均点着色。我将如何做到这一点?正如布兰登所说,我强烈建议通过以下方式来总结数据: 你可以像这样访问汇总的y:
- 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?
d < - data.frame(expand .grid(x = 1:4,rep = 1:3),y = rnorm(4 * 3))
ggplot(d,aes(x,y))+
stat_summary(mapping = aes (color = factor(ifelse(min(.. y ..)== .. y ..,1,ifelse(max(.. y ..)== .. y ..,3,2))
$)),fun.y = mean,geom =point)
尽管理解。
解决方案
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.
这篇关于ggplot2 - 做stat_summary产生..y ..?我将如何在y上子集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文