本文介绍了如何在R中绘制一个预先生成的直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于较大的数据集,我有一个预先装入的频率表。也就是说,单个列的向量向量和与这些仓相关联的单个列的向量向量。我想让R通过进一步分类和总结现有的计数来绘制这些数据的直方图。例如,如果在预先装入的数据中,我有类似[(0.01,5000),(0.02,231),(0.03,948)]的东西,其中第一个数字是bin,第二个是count,而I选择0.04作为新的仓宽度,我希望得到[(0.04,6179)]。在R中这是最快和最简单的方法?解决方案
看起来ggplot2有答案。
库(ggplot2)
qplot(bin,data = cbind(bin, =计数,geom =直方图)
I have a pre-binned frequency table for a rather large dataset. That is, a single column vector of bins and a single column vector of counts associated with those bins. I'd like R to plot a histogram of this data by doing further binning and summing the existing counts. For example, if in the pre-binned data I have something like [(0.01, 5000), (0.02, 231), (0.03, 948)], where the first number is the bin and the second is the count, and I choose 0.04 as the new bin width, I'd expect to get [(0.04, 6179)]. What's the fastest and or easiest way to do this in R?
解决方案
Looks like ggplot2 has the answer.
library(ggplot2)
qplot(bin, data=cbind(bins,counts), weight=counts, geom="histogram")
这篇关于如何在R中绘制一个预先生成的直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!