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

John Kane jrkrideau at inbox.com
Tue Jul 3 14:59:08 CEST 2012


Your data is effectively unreadable. Please use dput() to supply sample data.

Here is one way to do what you want  for data frames using the ggplot2 package.

library(ggplot2)
mydata  <-  data.frame(x = 1:10, y = rnorm(10), z = c(rep(1,4), rep(2, 6)))
ggplot(mydata, aes(x, y, colour= as.factor( z))) + geom_point()


John Kane
Kingston ON Canada


> -----Original Message-----
> From: kbw1123 at yahoo.com
> Sent: Mon, 2 Jul 2012 13:31:36 -0700 (PDT)
> To: r-help at r-project.org
> Subject: [R] Code scatter plot data from matrix with 3rd column
> 
> 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
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails



More information about the R-help mailing list