Skip to content
Prev 178004 / 398503 Next

converting histogram to barchart

Hi Thomas,

Here's a simple example of adding a KDE line to a plotted histogram:

set.seed(222)
x <- rnorm(100)
hist(x, freq=FALSE)
lines(density(x), lty=2, col=2, lwd=2)

Note the need to set the freq to FALSE -- otherwise hist will
calculate counts within bins rather than probability densities.  Also,
you may need to adjust the ylim and xlim arguments if the densities
from your two samples are dissimilar.

As for converting the histogram to a bar plot -- I think that's an
aberration best left in Excel...

hope it helps,

Kingsford Jones
On Wed, Apr 22, 2009 at 2:56 AM, Thomas Fr?jd <tfrojd at gmail.com> wrote: