将bar转换为hist()函数中的点

Loo*_*ast 1 r histogram

hist() 将生成由许多"条形"组成的直方图

如何用一个点替换每个条形图,以便将多个点组合在一起看起来像一个连续的曲线?

mne*_*nel 5

一些虚拟数据

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))
Run Code Online (Sandbox Code Playgroud)

或者你可以简单地使用 density

plot(density(x))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述