[R] Newbie graphing questions

Hedderik van Rijn hvr at van-rijn.org
Thu Aug 28 03:54:37 CEST 2003


> 1.  How do I create a new plot without erasing the prior one i.e.,  
> have a new window pop up with the new graph? I'm on MacOSX using the  
> Carbon port.

I don't know about the Carbon version, but ?Devices should give you a  
list of "Devices" you can use to output graphs to. (Using the fink  
version on OS X, X11() would do what you describe.)

> 2.  How do I pause between plot renderings i.e., in such a way that it  
> will draw the subsequent graph after pressing the space bar (or any  
> other key).

par(ask=T)

See ?par for more useful plotting options.

> 3.  Illustrating critical regions.  Say I wanted to illustrate the  
> critical region of a standard normal.  I would need to draw a vertical  
> line from the critical point to the curve and then shade the critical  
> region.  How do I do this in R?

Based on some code found on the R mailing list some time ago, I was  
able to come up with the following: (it shades an area of a lognormal  
density plot after a certain deadline)

deadline <- 800
mthres <- 6.5
sthres <- 0.15

ymax <- 0.005
xmax <- 1200

plot(0,0,xlim=c(0,xmax),ylim=c(0,ymax),type="n")

thres.xvals <- dlnorm(1:xmax,meanlog=mthres,sdlog=sthres)
lines(thres.xvals,col="blue")

abline(v=deadline,col="darkgrey")
polygon(c((deadline+1):xmax,rev((deadline+1):xmax)),c(rep(0,(xmax- 
deadline)),rev(thres.xvals[(deadline+1):xmax])),density=20,col="blue")

  - Hedderik.




More information about the R-help mailing list