[R] Combining two histograms

michael watson (IAH-C) michael.watson at bbsrc.ac.uk
Wed Feb 2 15:38:21 CET 2005


Something a bit more sohpisticated than this:
 

a <- rnorm(20000)
b <- rnorm(20000, mean=1.5)
ah <- hist(a,breaks= seq(-5,6,by=0.2),plot=FALSE)
bh <- hist(b,breaks= seq(-5,6,by=0.2),plot=FALSE)
data <- t(cbind(ah$counts,bh$counts))
barplot(data,beside=TRUE, space=rep(0,2*ncol(data)))
 

	-----Original Message----- 
	From: r-help-bounces at stat.math.ethz.ch on behalf of Sean Davis 
	Sent: Wed 2/2/2005 1:42 PM 
	To: r-help 
	Cc: 
	Subject: [R] Combining two histograms
	
	

	I have data like:
	
	a <- rnorm(20000)
	b <- rep(FALSE,20000)
	b[sample(1:20000,15000)] <- TRUE
	
	Using Lattice graphics, I can produce two side-by-side histograms quite
	easily by:
	
	histogram(a | b)
	
	However, I would like to produce a "single" histogram with two bars
	within each bin, one for each group, as the groups are in reality very
	slightly different from each other.  The difference isn't evident
	unless one "overlays" the two histograms in some manner.
	
	Thanks,
	Sean
	
	______________________________________________
	R-help at stat.math.ethz.ch mailing list
	https://stat.ethz.ch/mailman/listinfo/r-help
	PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list