User Tools

Site Tools


This is an old revision of the document!


Author: Tim from CrossValidated, with modification from D. Zeleny

Quick and dirty function which draws histogram overlaid with normal distribution curve.

hist.dnorm <- function (x, lines.col = 'red', lines.lwd = 2, ...)
  hist (x, freq = FALSE, ...)
  lines (seq (min (x), max (x), length = 100), dnorm (seq (min (x), max (x), length = 100), mean = mean (x), sd = sd (x)), col = lines.col, lwd = lines.lwd)  

To modify color and thickness of the normal distribution curve, use arguments lines.col and lines.lwd. Function accepts most other arguments for hist, with some limitations.

Example of use (using environmental data from the dataset Vegetation of Carpathian wetlands):

source ('') # reads the function definition from above
chem <- read.delim ('', row.names = 1) # reads the ''chem'' dataset
hist.dnorm (chem[,-15], cex.labels = 1)

Note that the package car contains the function scatterplotMatrix, which is doing something similar (and perhaps could be also further customized).

en/customized_functions/hist.dnorm.1488766227.txt.gz · Last modified: 2017/10/11 20:36 (external edit)