N Brouwer
N Brouwer

Reputation: 5078

Plotting numeric frequency data based on midpoints of bins in base R or ggplot

I am replicating simulation results from a published study. The authors present their output in a density plot (below) that is very rectangular. They appear to have created bins and then plotted the midpoint of the bins. Is it possible to easily build this type of plot using base R graphics or ggplot?

enter image description here

Upvotes: 0

Views: 563

Answers (1)

Lucas Fortini
Lucas Fortini

Reputation: 2460

Very simple indeed:

data=rnorm(1000)
hist_info=hist(data, plot=F)
plot(hist_info$mids, hist_info$density, type="l", xlab="X", ylab="density")

enter image description here

Upvotes: 1

Related Questions