Skip to content

negative and positive values in diff. colors

5 messages · Rado Bonk, Paul Murrell, Roger Bivand +2 more

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

Thanks in advance,

Rado
#
Hi
Rado Bonk wrote:
Do you mean something like this ... ?

x <- rnorm(50)
y <- rnorm(50)
z <- rnorm(50)
pch <- rep(1, 50)
pch[z < 0] <- 20
cex <- (abs(z)/max(abs(z))) * 4.9 + 0.1
plot(x, y, pch=pch, cex=cex)

Paul
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
[1] 20 20 20 20  1  1 20 20  1 20 20 20 20 20  1 20  1 ...
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

  
    
#
Rado Bonk wrote:
I'm not sure if I understand your question completely, but I guess you
want to vectorize as in:

 x <- 1:10
 y <- 1:10
 res <- -4:5
 plot(x, y, pch = ifelse(res < 0, 20, 1))
points() doesn't know about any arguments called cex.min and cex.max.
If I guess right, you want to extend the above as in:

 plot(x, y, pch = ifelse(res < 0, 20, 1), 
   cex = (4.9 * abs(res) / max(abs(res)) + 0.1))

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
I found that (0.1,0.5) was a bit small for a point-size range so I used 
(0.5,2.5), but otherwise I think this does what you want. 

n <- 20
x <- runif(n)
y <- runif(n)
z <- 2*runif(n)-1

cex.min <- 0.5
cex.max <- 2.5
plot(x,y,pch=ifelse(z>0,1,20),cex=cex.min+((z-min(z))/(max(z)-min(z)))*(cex.max-cex.min))



On
Thu, 7 Nov 2002, Rado Bonk wrote: