[R] Backgrounds in Multiple Plots made with "fig"

Paul Murrell p.murrell at auckland.ac.nz
Mon Jul 7 05:18:38 CEST 2008


Hi


Tom La Bone wrote:
> The following code was adapted from an example Vincent Zoonekynd gave on his
> web site http://zoonek2.free.fr/UNIX/48_R/03.html:
> 
> n <- 1000
> x <- rnorm(n)
> qqnorm(x)
> qqline(x, col="red")
> op <- par(fig=c(.02,.5,.5,.98), new=TRUE)
> hist(x, probability=T,
>      col="light blue", xlab="", ylab="", main="", axes=F)
> lines(density(x), col="red", lwd=2)
> box()
> par(op)
> 
> How can I make the background in the small box in the upper left-hand corner
> be a different color than the background in the main plot and erase any of
> the main plot that happens to be behind the box?


Here's one way ...

n <- 1000
x <- rnorm(n)
qqnorm(x)
qqline(x, col="red")
op <- par(fig=c(.02,.5,.5,.98), new=TRUE)
plot.new()
usr <- par("usr")
rect(usr[1], usr[3], usr[2], usr[4], col="wheat")
par(new=TRUE)
hist(x, probability=T,
     col="light blue", xlab="", ylab="", main="", axes=F)
lines(density(x), col="red", lwd=2)
box()
par(op)


Paul


> Tom
>  
> 
> 
> 

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



More information about the R-help mailing list