[R] scatterplot of two y's

arun smartpink111 at yahoo.com
Mon Feb 17 23:52:46 CET 2014


Hi,
Try:
library(reshape2)
 df2New <- melt(df,id.var="x")
 ggplot(df2New,aes(x=x,y=value,colour=variable))+geom_point(shape=1)
A.K.




On Monday, February 17, 2014 5:42 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