Here are the codes:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Random numbers | |
h2<-rnorm(1000,4) | |
h1<-rnorm(1000,6) | |
# Histogram Grey Color | |
hist(h1, col=rgb(0.1,0.1,0.1,0.5),xlim=c(0,10), ylim=c(0,200), main="Overlapping Histogram") | |
hist(h2, col=rgb(0.8,0.8,0.8,0.5), add=T) | |
box() | |
# Histogram Colored (blue and red) | |
hist(h1, col=rgb(1,0,0,0.5),xlim=c(0,10), ylim=c(0,200), main="Overlapping Histogram", xlab="Variable") | |
hist(h2, col=rgb(0,0,1,0.5), add=T) | |
box() |
Of course, for the transparency to have any effect, you would have to use an image file format that actually supports it, e.g. PNG or PDF. In R, you can do this easily using the png() or pdf() functions.
ReplyDeleteNice post! Love this, a very useful tool to have.
ReplyDeleteThanks!
Thanks Doug! I am happy that others like my post and found it useful.
DeleteHow about that we don't know the ylim for the two distributions? If they are different (the first one is less than the second)? Can we look the maximum ylim beforehand. Thanks.
ReplyDeleteRecently I've started working with R and I was looking for this.
ReplyDeleteThanks mate!
Titanium Hair dye - The Home of TITONIC-ART®
ReplyDeleteA unique blend of titanium and titanium nail silicon has the everquest titanium finest texture titanium for sale and micro touch trimmer the lowest heat on the tin! grade 23 titanium