在R中使用hist()函数获取百分比,而不是原始频率 [英] Use hist() function in R to get percentages as opposed to raw frequencies
本文介绍了在R中使用hist()函数获取百分比,而不是原始频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用R中的hist()函数绘制相对于原始频率的百分比?
How can one plot the percentages as opposed to raw frequencies using the hist() function in R?
推荐答案
仅使用freq=FALSE
参数不能给出带有百分比的直方图,它可以对直方图进行归一化,因此总面积等于1.
要获取某些数据集的百分比直方图,例如x,请执行以下操作:
Simply using the freq=FALSE
argument does not give a histogram with percentages, it normalizes the histogram so the total area equals 1.
To get a histogram of percentages of some data set, say x, do:
h = hist(x) # or hist(x,plot=FALSE) to avoid the plot of the histogram
h$density = h$counts/sum(h$counts)*100
plot(h,freq=FALSE)
基本上,您正在做的是创建一个直方图对象,将density属性更改为百分比,然后重新绘图.
Basically what you are doing is creating a histogram object, changing the density property to be percentages, and then re-plotting.
这篇关于在R中使用hist()函数获取百分比,而不是原始频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文