本文介绍了累积直方图与ggplot2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我怎么能得到像这样的累积直方图?/ b> x h h [[counts]] - cumsum(h [[counts]]) plot(h) 与ggplot2? 我也想绘制一个像这样的多边形 p> lines(h [[breaks]],c(0,h [[counts]])) 解决方案使累积直方图使用 geom_histogram(),然后对 y 值使用 cumsum(.. count ..)。可以使用 stat_bin()和 geom =line和 y 值计算为 cumsum(.. count ..)。 ggplot(NULL,aes(x))+ geom_histogram(aes(y = cumsum(.. count ..)))+ stat_bin(aes(y = cumsum(.. count ..) ),geom =line,color =green) How could I get a cumulative histogram like thisx <- runif(100,0,10)h <- hist(x)h[["counts"]] <- cumsum(h[["counts"]])plot(h)with ggplot2?I want also to draw a polygon like thislines(h[["breaks"]],c(0,h[["counts"]])) 解决方案 To make cumulative histogram use geom_histogram() and then use cumsum(..count..) for y values. Cumulative line can be added with stat_bin() and geom="line" and y values calculated as cumsum(..count..).ggplot(NULL,aes(x))+geom_histogram(aes(y=cumsum(..count..)))+ stat_bin(aes(y=cumsum(..count..)),geom="line",color="green") 这篇关于累积直方图与ggplot2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-05 21:42