hist()
将生成一个由许多“条”组成的直方图
如何用一个点替换每个条,使多个点看起来像一条连续曲线?
一些虚拟数据
x <- rnorm(50)
# create a histogram
.hist <- hist(x)
# look at the structure to see what is created when calling hist
str(.hist)
## List of 7
## $ breaks : num [1:10] -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2
## $ counts : int [1:9] 1 2 5 6 8 10 10 5 3
## $ intensities: num [1:9] 0.04 0.08 0.2 0.24 0.32 0.4 0.4 0.2 0.12
## $ density : num [1:9] 0.04 0.08 0.2 0.24 0.32 0.4 0.4 0.2 0.12
## $ mids : num [1:9] -2.25 -1.75 -1.25 -0.75 -0.25 0.25 0.75 1.25 1.75
## $ xname : chr "x"
## $ equidist : logi TRUE
## - attr(*, "class")= chr "histogram"
# we could plot the mids (midpoints) against the counts
with(.hist, plot(mids, counts))
或者你可以简单地使用density
plot(density(x))