[R] scatterplot of two y's

MacQueen, Don macqueen1 at llnl.gov
Wed Feb 19 20:38:22 CET 2014


The quickest way, using the example data, would be

  matplot( df$x, df[,-1])

Obviously doesn't have the nice ggplot style, but it does do what was
requested. And depending on the context and ultimate goal, may be
sufficient.

Simple improvements are easy:

  matplot( df$x, df[,-1],
     xlab='x', ylab='y1, y2',
     pch=c(1,4) , main='My Data' )

-Don

p.s.
As a personal and editorial aside, I often think that amongst all of the
great extensions to R that have been developed over the years, the basics
get forgotten.

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 2/17/14 2:41 PM, "Ramiro Barrantes" <ramiro at precisionbioassay.com>
wrote:

>Hello,
>
>Sorry if this is repeated somewhere, I imagine it must be a common issue
>but I can't find an answer!
>
>I have a data.frame with two responses, example (response variables to x
>are y1 and y2):
>
>df<-data.frame(x=1:10,y1=1:10,y2=11:20)
>
>I would like to see it on the same plot with different colours.
>
>The only thing I can think of is:
>df2<-rbind(df,df)
>df2[1:10,"y"]<-df$y1
>df2[11:20,"y"]<-df$y2
>df2[1:10,"yType"]<-'y1'
>df2[11:20,"yType"]<-'y2'
>
>ggplot(df2,aes(x=x,y=y,colour=yType))+geom_point(shape=1)
>
>Is there a better way?
>
>Thanks in advance,
>Ramiro
>
>	[[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.




More information about the R-help mailing list