[R] dotted contour line for negative values? -- filled.contour(.)

Martin Maechler maechler at stat.math.ethz.ch
Tue May 11 10:25:37 CEST 1999


>>>>> "Ross" == Ross Ihaka <ihaka at stat.auckland.ac.nz> writes:

    Ross> On Mon, 10 May 1999, Bill Simpson wrote:

      >> I have a contour plot where the surface can take on positive and
      >> negative values.  I would like to use solid contour lines for
      >> positive values and dotted contour lines for negative values. I
      >> saw a plot like this produced by S-Plus before.  Is there a way
      >> to do this with R? If not, can anyone suggest a way to make
      >> interpretation of the contour plot easier? (Right now, it is not
      >> clear if a set of "tree rings" in a plot indicate the presence of
      >> a peak or a trough)
      >> 
      >> I am thinking that it might be possible by making one plot of the
      >> positive contours with lty="solid", add=TRUE, then superimpose
      >> the negative contours with lty="dotted". The snag is: how to get
      >> only the positive or negative contours?

    Ross> Here is a small example.  The trick is to specify the levels
    Ross> and to use the add= argument.

    Ross> x <- seq(-1, 1, length=21)
    Ross> f <- function(x,y) (x^2 + y^2) / 2 - 0.5
    Ross> z <- outer(x, x, f)
    Ross> contour(z, levels = seq(-0.5, -0.1, by = 0.1), lty = "dotted")
    Ross> contour(z, levels = 0, lty = "dashed", add = TRUE)
    Ross> contour(z, levels = seq(0.1, 1, by = 0.1), add = TRUE)

Not answering the original question,
however
just adding a hint : 
Since R 0.64.x,  there's the very nice useful function

     filled.contour(.)	   {by Ross himself!}
     -----------------

Consider

   x <- seq(-1, 1, length=21)
   z <- outer(x, x, function(x,y) (x^2 + y^2)  - 1)

   filled.contour(z) ## for color output
# or
   filled.contour(z, color.palette = function(n)gray(1:n/n) ## for (gray) output

Also look at the beautiful

    example(filled.contour)

((which needs an

	x11(colortype = "pseudo")

 if you have just 8-bit colors as I do))
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list