[R] R: plotting values on graphics

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Oct 6 15:34:41 CEST 2000


> "joseph d. hughes" wrote:
> 
> Everyone,
> 
> I have an array of integer values which are located on a uniform 2-D
> grid.  I want to plot the integer values at the node locations. The
> closest I have come is with the following code:
> 
> for (i in 1:ny) {
>   for (j in 1:nx) {
>   ncell <- nx*(i - 1) + j
>   ch <- as.character(ncount[ncell])
>   tx <- j*dx - dx/2
>   ty <- ny*dy - (i-1)*dy - dy/2
>   points(tx, ty, pch = ch, col = "red", bg = "yellow", cex = 3)
>   }
> }

Try 
  text(tx, ty, label = ch, col = "red", bg = "yellow", cex = 3)
instead of points(...).
If you specify pch, only the first character is taken as the symbol for
your point.

Remark: It should be possible to vectorize your code. That will make it
much faster.

> The problem with the code above is I only get a one character symbol
> at each node (e.g. n=123 gives me 1 on the screen).  Is there
> something wrong with my as.character or points function calls?  Is
> there a better way to do this?

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



More information about the R-help mailing list