Convert bar into points in hist() function

hist() will generate a histogram composed of lots of "bars"

How can I replace each bar with one point, so that many points together will look like a continuous curve?

Answers


some dummy data

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))

Or you could simply use density

plot(density(x))


What you want is the density plot for a histogram. Here are two previous answers: The first shows how to overlay the density plot on the histogram. And the second on how to create the density plot along.

Axis-labeling in R histogram and density plots; multiple overlays of density plots

How to Plot Density from Frequency Table


Need Your Help

How to configure spring-boot with swing application

java swing spring-boot

I'd like using spring-boot-starter-data-jpa features to create a non-web aplication.

Is there a Lock implementation that performs deadlock detection?

java multithreading concurrency locking

The Java Docs for Lock contain the following statement in documentation of the Methods lock, lockInterruptibly and tryLock.