Hi everyone. R is new to me and I'm very impressed with its capabilities but still cannot figure out how to do some basic things. There seems to be no lack of documentation but finding what I need has proven difficult. Perhaps you can help. Here's what I'm after: 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. 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). 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? Thanks! -Francisco
Dear Francisco, 1. Have a look at ?Devices which (under Windows at least) lists a range of devices you can open before and between plots. 2. Use par(ask=TRUE) before you start your plots 3. Christophe Declercq provided an excellent example on this mailing list, under the topic "curves with shaded areas". Search for that in the archives. Regards, Andrew C. Ward CAPE Centre Department of Chemical Engineering The University of Queensland Brisbane Qld 4072 Australia andreww at cheque.uq.edu.au Quoting "Francisco J. Bido" <bido at mac.com>:> Hi everyone. R is new to me and I'm very impressed with > its > capabilities but still cannot figure out how to do some > basic things. > There seems to be no lack of documentation but finding > what I need has > proven difficult. Perhaps you can help. > > Here's what I'm after: > > 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. > > 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). > > 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? > > Thanks! > -Francisco > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
> 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.
On Wed, 2003-08-27 at 17:28, Francisco J. Bido wrote:> Hi everyone. R is new to me and I'm very impressed with its > capabilities but still cannot figure out how to do some basic things. > There seems to be no lack of documentation but finding what I need has > proven difficult. Perhaps you can help. > > Here's what I'm after: > > 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.In general, if you want to leave the existing device open and have a new device open for a new plot, you simply call the device name that you want to open (ie. under Linux you would use X11() ) to open a new plotting device on the display. See ?Devices for more details.> 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).Set 'par(ask = TRUE)' before plotting. See ?par> 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?# Generate a sequence of x values x <- seq(-3, 3, by = 0.001) # Plot normal curve over x plot(x, dnorm(x), type = "l") # Define left side boundary using min(x) # and CritVal using alpha = 0.05 alpha <- 0.05 CritVal <- qnorm(alpha / 2) x.l <- seq(min(x), CritVal, length = 100) y.l <- c(dnorm(x.l), 0, 0) # add CritVal, min(x) to complete polygon x.l <- c(x.l, CritVal, min(x)) # draw and fill left region polygon(x.l, y.l, density = 50) # Do the same for right side boundary using max(x) # and Crit Val CritVal <- qnorm(1 - (alpha / 2)) x.r <- seq(CritVal, max(x), length = 100) y.r <- c(dnorm(x.r), 0, 0) # add max(x) and CritVal to complete polygon x.r <- c(x.r, max(x) , CritVal) # draw and fill left region polygon(x.r, y.r, density = 50) HTH, Marc Schwartz
Marc Schwartz wrote:> In general, if you want to leave the existing device open and have a new > device open for a new plot, you simply call the device name that you > want to open (ie. under Linux you would use X11() ) to open a new > plotting device on the display. See ?Devices for more details.X11() works on Windows too. Thomas