简体   繁体   English

如何使用 ggplot2 创建分组累积频率图

[英]How to create a grouped cumulative frequency graph with ggplot2

I'm working with a dataset of elemental concentrations, and I want to compare the cumulative frequency graphs of elemental concentrations in two places, like I did using plot() in this image , but with ggplot.我正在使用元素浓度数据集,我想比较两个地方元素浓度的累积频率图,就像我在这张图片中使用 plot() 一样,但使用 ggplot。 Here is a dummy dataset这是一个虚拟数据集

df<-data.frame("Zone"=c(rep("A",10),rep("B",9)),"Con"=c(rnorm(10,5,2),rnorm(9,7,2.5)))

I've managed to make a cumulative frequency graph for both zones together in this clumsy way:我设法以这种笨拙的方式为两个区域制作了一个累积频率图:

ggplot(df,aes(x=cumsum(rep(1,19)),y=sort(Con)))+geom_point()

But I can't figure out how to make it for both zones separately.但我不知道如何分别为两个区域制作它。 Thanks in advance.提前致谢。

I think you'd like to use stat_ecdf from ggplot2:我想你想使用stat_ecdf中的 stat_ecdf:

ggplot(df, aes(Con, color = Zone)) + stat_ecdf(geom = "point")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM