[R] multiple graphs

Greg Snow Greg.Snow at intermountainmail.org
Thu Jul 26 18:30:17 CEST 2007

One of the nice things about the R Graph Gallery is that if you click on
the R logo underneath the graph (may need to scroll down a bit) it will
show you the code used to create that particular graph.

You may also want to look at the subplot function in the TeachingDemos
package for another way to add histograms to a plot:

Here is one possible example of this:

x <- rep(1:10, each=25)
y <- rexp(250, 1/x)


tmp1 <- hist(y, plot=FALSE)
r <- range(tmp1$breaks)
w <- diff(tmp1$breaks)
plot(x,y, type='n', xlim=c(0.5,10.5), ylim=r)
for(i in 1:10){
	tmp2 <- hist( y[x==i], breaks=tmp1$breaks, plot=FALSE )
	subplot( barplot(tmp2$counts, ylim=r, width=w,
                       horiz=TRUE, space=0, xaxt='n', yaxs='i'),
               c(i-0.45, i+.45), r

points(x,y) # just to compare

Hope this helps,

Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Daniele Amberti
> Sent: Thursday, July 26, 2007 1:26 AM
> To: r-help
> Subject: [R] multiple graphs
> Does anyone have a simple explanation and example on how to 
> add histograms or barcharts to an other graph like in the 
> example at the R-graph gallery:
> http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=109
> looking at the code I'not undertand very well how to add 
> graphs in arbitrary/clever position with an adequate scale.
> If somebody have a simplier example with explanations it will 
> be highly appreciate.
> Best
> Daniele
> ------------------------------------------------------
> Scegli infostrada: ADSL gratis per tutta l'estate e telefoni 
> senza canone Telecom
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list