频率和累积频率曲线上中的R相同的曲线图(Frequency and cumulative frequ

2019-09-16 08:27发布

有一种方法(与ggplot或否则R)绘制频率和累积频率曲线在单个列(两列)即,使用直线的其他使得给定四分位上都可以所示的曲线中的一个顶部? 我希望我明确这一点..

您可以使用此数据..

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")

Answer 1:

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)))

要么

添加累积频率列

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~.)



文章来源: Frequency and cumulative frequency curve on the same graph in R