gpt4 book ai didi

r - R中同一张图上的频率和累积频率曲线

转载 作者:行者123 更新时间:2023-12-02 07:07:05 29 4
gpt4 key购买 nike

有没有一种方法(在 R 中使用 ggplot 或其他方式)在单列(两行)中绘制频率和累积频率曲线,即一列在另一列的顶部,以便可以使用直线在两条曲线上显示给定的四分位数线?我希望我对此很清楚..

您可以使用这些数据..

mydata<-structure(list(speed = c(10, 15, 20, 25, 30, 35, 40, 45, 50),frequency = c(0, 1, 5, 10, 20, 10, 6, 3, 0)), .Names = c("speed","frequency"), row.names = c(NA, -9L), class = "data.frame")

最佳答案

mydata<-structure(list(speed = c(10, 15, 20, 25, 30, 35, 40, 45, 50),frequency = c(0, 1, 5, 10, 20, 10, 6, 3, 0)), .Names = c("speed","frequency"), row.names = c(NA, -9L), class = "data.frame")


library(ggplot2)

qplot(data=mydata,
x=speed,
y=frequency,
geom=c("point", "line"))+
geom_line(aes(y=cumsum(frequency)))

enter image description here

添加累积频率列

mydata$sum.freq<-with(mydata, cumsum(frequency))

library(reshape)
qplot(data=melt(mydata, id.vars="speed"),
x=speed,
y=value,
geom=c("point", "line"), facets=variable~.)

enter image description here

关于r - R中同一张图上的频率和累积频率曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10030547/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com