Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Histogram of two variables in R

I have two variables that I want to compare in a histogram like the one below. For each bin of the histogram the frequency of both variables is shown what makes it easy to compare them.

enter image description here

like image 575
alex Avatar asked Feb 01 '13 02:02

alex


1 Answers

You can use the add parameter to hist (see ?hist, ?plot.histogram):

hist(rnorm(1000, mean=0.2, sd=0.1), col='blue', xlim=c(0, 1))
hist(rnorm(1000, mean=0.8, sd=0.1), col='red', add=T)

enter image description here

To find out about the add parameter I noticed that in ?hist the ... argument says that these are arguments passed to plot.histogram, and add is documented in ?plot.histogram. Alternatively, one of the examples at the bottom of ?hist uses the add parameter.

like image 163
mathematical.coffee Avatar answered Sep 28 '22 00:09

mathematical.coffee