Skip to content
Prev 298997 / 398506 Next

Code scatter plot data from matrix with 3rd column

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,

Rui Barradas

Em 02-07-2012 21:31, Kathryn B Walters-Conte escreveu: