[R] Newbie graphing questions

Francisco J. Bido bido at mac.com
Thu Aug 28 05:18:21 CEST 2003


Thanks Hedderik, Andrew, David and of course, you Mark.  You have all 
been very helpful.  I got good answers two 1. and 2. and arsenal of 
ideas for 3.  Mark's solution for 3. is exactly what I was thinking 
about.  I'm indeed very grateful.

Best,
-Francisco





On Wednesday, August 27, 2003, at 09:36 PM, Marc Schwartz wrote:

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




More information about the R-help mailing list