Frequency and cumulative frequency curve on the same graph in R

可紊 提交于 2019-12-06 10:12:49
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)))

or

Add a cumulative frequency column

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!