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) } } 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? Thanks in advance, Joseph Hughes jdhughes99 at mindspring.com -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20001006/daeadf08/attachment.html
>>>>> On Fri, 6 Oct 2000 08:51:47 -0400, >>>>> joseph d hughes (jdh) wrote:jdh> Everyone, jdh> 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: jdh> for (i in 1:ny) { jdh> for (j in 1:nx) { jdh> ncell <- nx*(i - 1) + j jdh> ch <- as.character(ncount[ncell]) jdh> tx <- j*dx - dx/2 jdh> ty <- ny*dy - (i-1)*dy - dy/2 jdh> points(tx, ty, pch = ch, col = "red", bg = "yellow", cex = 3) jdh> } jdh> } jdh> 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? The function text() allows plotting arbitrary strings at a give (x,y)-position (with control over font, alignment, ...). Hope this helps, Fritz -- ------------------------------------------------------------------- Friedrich Leisch Institut f?r Statistik Tel: (+43 1) 58801 10715 Technische Universit?t Wien Fax: (+43 1) 58801 10798 Wiedner Hauptstra?e 8-10/1071 Friedrich.Leisch at ci.tuwien.ac.at A-1040 Wien, Austria http://www.ci.tuwien.ac.at/~leisch PGP public key http://www.ci.tuwien.ac.at/~leisch/pgp.key ------------------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 6.10.2000 14:51 Uhr, joseph d. hughes wrote: ...> points(tx, ty, pch = ch, col = "red", bg = "yellow", cex = 3) > } > } > > 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?Yes, "points" is the wrong function to use for this, since the "pch" option uses only one character. You should use "text" instead. For usage see "help(text)".> Is there a better way to do this?You might also want to look at the "symbols" function available in the current R versions. It allows you to, e.g., draw circles of a size corresponding to your count values. I've found this quite an intuitive way of visualizing such data. Cheers Kaspar Pflugshaupt -- Kaspar Pflugshaupt Geobotanisches Institut Zuerichbergstr. 38 CH-8044 Zuerich Tel. ++41 1 632 43 19 Fax ++41 1 632 12 15 mailto:pflugshaupt at geobot.umnw.ethz.ch privat:pflugshaupt at mails.ch http://www.geobot.umnw.ethz.ch -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> "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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Use text(). On Fri, 6 Oct 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) > } > } > > 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? > > Thanks in advance, > > Joseph Hughes > jdhughes99 at mindspring.com > > >-- 318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._