[R] negative and positive values in diff. colors

Roger Bivand Roger.Bivand at nhh.no
Thu Nov 7 21:29:47 CET 2002


> Hi R-users,
>
> I have a set of elevation residuals as geodata points. I would like to
> display them in the following way:
> -negative values using pch=20 (filled circle)
> -positive values using pch=1  (empty circle)
>
> while using the cex.max=5, cex.min=0.1 for points() to represent the
> residuals value. Basically I would like to distinguish neagtive and
> positive values at my map. How to do this.

> x <- rnorm(25)
> y <- rnorm(25)
> z <- rnorm(25)
> pchs <- c(1, 20)
> pchs[(z < 0)+1]
 [1] 20 20 20 20  1  1 20 20  1 20 20 20 20 20  1 20  1 ...
> plot(x, y, pch=pchs[(z < 0)+1])
> text(x, y, labels=round(z, 2), pos=1, offset=0.5)

This "cuts" the z vector at zero, using the convenient slight-of-hand that
TRUE and FALSE map to integers 1 and 0, and thus gives the pch argument in
plot() or points() a vector of values of indices of the pchs vector. More
generally, use cut() to break a numeric vector into class intervals
(possibly within ordered()).

Roger

>
> Thanks in advance,
>
> Rado
>
> --
> Radoslav Bonk M.S.
> Dept. of Physical Geography and Geoecology
> Faculty of Sciences, Comenius University
> Mlynska Dolina 842 15, Bratislava, SLOVAKIA
> tel: +421 2 602 96 250 e-mail: rbonk at host.sk
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


-- 
Roger Bivand
NHH, Breiviksveien 40, N-5045 Bergen, Norway
(travelling but still accessible)


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