# [R] Code scatter plot data from matrix with 3rd column

Tue Jul 3 10:36:17 CEST 2012

```Hello,

In order to avoid messing up the data, use dput. See below, in the end.

As for your question, try this:

set.seed(1234)
xyz <- data.frame(x=sample(20, 10), y=sample(20, 10), z=sample(0:1, 10,
TRUE))

# pch=16 --> solid circle; cex=4 --> 4 fold expansion
with(xyz, plot(x, y, col=z+1, pch=16, cex=4)) # color 0 is white

If you have a matrix, not a data.frame, don't use with(),
use xyz[, "x"], etc.

~~~~~~~~~~~~~~~~ The use of dput() ~~~~~~~~~~~~~~~~

dput(xyz)
structure(list(x = c(3L, 12L, 11L, 18L, 14L, 10L, 1L, 4L, 8L,
6L), y = c(14L, 11L, 6L, 16L, 5L, 13L, 17L, 4L, 3L, 12L), z = c(0L,
0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L)), .Names = c("x", "y", "z"
), row.names = c(NA, -10L), class = "data.frame")

Now all anyone has to do is to copy that output, from 'structure' onward
and paste it in an R session. Try it, assign to a variable:
xyz2 <- structure(...etc...)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hope this helps,

Em 02-07-2012 21:31, Kathryn B Walters-Conte escreveu:
> Hello
>
> I am looking for a simple way to plot my data from a matrix (or data frame) using a 3rd column as category to code the data points.
>
> for example:
> xyz
> 543240
> 104230
> 15901
> 203241
> 25781
> 3042340
> 357891
> 405670
> 45780
> 50531
>
> Ideally, I'd like 0 or 1 to correspond to a color but I'd settle for a symbol at this point.  I have tried working with pch but can't get it to work.
>
> Thanks
> Kat
> 	[[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help