如何使用hist绘制R中的相对频率?

如何使用hist绘制R中的相对频率?

问题描述:

如何使用hist()在R中绘制相对频率?

How do you use hist() to plot relative frequencies in R?

如果执行以下操作,我将得到一个密度图,但是我想要一个相对频率图:

If I do the following, I will get a density plot, but I want a relative frequency plot:

a <- c(0,0,0,1,1,2)
hist(a, freq=FALSE)

我想查看具有以下相对频率的直方图:

I want to see a histogram with the following relative frequencies:

.5表示0到1,

.33表示1到2,

和.166,表示2到3.

and .166 for 2 to 3.

您可以尝试在晶格中使用histogram()函数

you can try using the histogram() function in lattice

a <- c(0,0,0,1,1,2)
library(lattice)
histogram(a)

默认为百分比.