Skip to content

multiple graphs

3 messages · Daniele Amberti, PIKAL Petr, Greg Snow

#
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
#
Hi

this particular graph is a combination of several approaches
see

layout # how to split plot window (or ?split)
par(new=TRUE) # how to plot several times to the same window without 
erasing previous plot

and of course sophisticated use of all other stuff which is available in 
R.

See also

par(fig=...)

plot(1:10)
par(fig=c(0.1,.5,0.1,.5), new=T)
boxplot(rnorm(10))

Petr

r-help-bounces at stat.math.ethz.ch napsal dne 26.07.2007 09:26:16:
histograms or
appreciate.
canone Telecom
http://www.R-project.org/posting-guide.html
#
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)

library(TeachingDemos)

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,