User Tools

Site Tools



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. The 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$pH, xlab = 'pH', main = 'Histogram of pH')

en/customized_functions/hist.dnorm.txt · Last modified: 2018/03/30 23:04 by

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki