使用聚合数据创建直方图 [英] Creating a histogram using aggregated data
问题描述
令人尴尬的简单问题...
我是R的新手,我似乎无法围绕这个原因。我有一个CSV文件,看起来像这样:
Bin,Number
1363,5
1028 ,4
1303,3
1467,1
1242,3
1415,5
..
。
容器大小为1,范围为1000-1500。我已经读取我的CSV文件,一切似乎都确定,但我只是不能产生一个简单的直方图。我试过简单地使用条形图,但数据不是数字排序,所以不会产生我需要的输出。使用这样的数据,我如何在R?中产生一个直方图?
一旦我有一个简单的直方图,我相信我可以玩因为 hist
函数会执行以下操作:
rep
。然后,您可以在结果向量上使用 hist
。 ,hist(rep(x = Bin,times = Number)))
Embarrassingly simple question...
I'm new to R and I can't seem to wrap my head around this for some reason. I have a CSV file which looks something like this:
Bin,Number
1363,5
1028,4
1303,3
1467,1
1242,3
1415,5
..
.
The bin size is 1, with a range of 1000-1500. I have read my CSV file in, everything seems to be ok there, but I just cannot produce a simple histogram. I have tried simply using a barplot, but the data is not numerically ordered, so will not produce the output I need. Using data such as this, how can I produce a histogram in R?
Once I have a simple histogram, I'm sure I'll be able to play around with it and format it nicely.
Because the hist
function does the counting of items in each bin, you need to 'explode' your 'already counted' data, for example by using rep
. Then you can use hist
on the resulting vector.
with(df, hist(rep(x = Bin, times = Number)))
这篇关于使用聚合数据创建直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!