Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 为什么“cumsum”不';在ggplot的组或面内不工作?_R_Ggplot2 - Fatal编程技术网

R 为什么“cumsum”不';在ggplot的组或面内不工作?

R 为什么“cumsum”不';在ggplot的组或面内不工作?,r,ggplot2,R,Ggplot2,借鉴 x以下是我如何用一行代码(ddply和mutate)处理这个问题: df Read?stat\u bin。它返回一个data.frame,您可以使用.count..访问其中一个data.frame列。我已经阅读了?stat_bin。正如ggplot文档中经常发生的那样,它没有说明如何让组应用统计函数。“查看层”一行在ggplot2帮助页面周围随意分布,您得到了什么?层是可笑的简短。基本上,您不能。请记住,ggplot的基本设计原则之一是将数据处理成正确的形状,然后调用ggplot。 x &

借鉴


x以下是我如何用一行代码(ddply和mutate)处理这个问题:


df Read
?stat\u bin
。它返回一个data.frame,您可以使用
.count..
访问其中一个data.frame列。我已经阅读了?stat_bin。正如ggplot文档中经常发生的那样,它没有说明如何让组应用统计函数。“查看层”一行在ggplot2帮助页面周围随意分布,您得到了什么?层是可笑的简短。基本上,您不能。请记住,ggplot的基本设计原则之一是将数据处理成正确的形状,然后调用ggplot。
x <- data.frame(A=replicate(200,sample(c("a","b","c"),1)),X=rnorm(200))
ggplot(x,aes(x=X,color=A)) + stat_bin(aes(y=cumsum(..count..)),geom="step")
df <- data.frame(x=rnorm(1000),kind=sample(c("a","b","c"),1000,replace=T),
         label=sample(1:5,1000,replace=T),attribute=sample(1:2,1000,replace=T))

dfx <- ddply(df,.(kind,label,attribute),mutate,cum=rank(x)/length(x))

ggplot(dfx,aes(x=x))+geom_line(aes(y=cum,color=kind))+facet_grid(label~attribute)