Plotting cumulative counts in ggplot2

前端 未结 2 574
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 20:58

There are some posts about plotting cumulative densities in ggplot. I\'m currently using the accepted answer from Easier way to plot the cumulative frequency distribution in

2条回答
  •  悲&欢浪女
    2020-12-23 21:12

    You can apply row_number over the groups, and utilize that as the Y aesthetic in a geom_step or other geometry. You'll just have to sort by X, or the values will appear as they do in the data frame, unordered.

    ggplot(x %>% 
             group_by(A) %>% 
             arrange(X) %>% 
             mutate(rn = row_number())) + 
      geom_step(aes(x=X, y=rn, color=A))
    

提交回复
热议问题