【问题标题】:Frequency and cumulative frequency curve on the same graph in RR中同一图表上的频率和累积频率曲线
【发布时间】:2012-04-05 14:29:11
【问题描述】:

有没有办法(在 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")

【问题讨论】:

    标签: r plot ggplot2 frequency-distribution cumulative-frequency


    【解决方案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~.)
    

    【讨论】:

    • 谢谢@Etienne。我实际上希望它们在两行中,而不是在同一个图表上,但具有相同的 x 轴(速度)。
    猜你喜欢
    • 2021-06-02
    • 1970-01-01
    • 2012-06-24
    • 2012-10-16
    • 1970-01-01
    • 2016-04-30
    • 2016-08-06
    • 1970-01-01
    • 2020-01-14
    相关资源
    最近更新 更多