[R] scatterplot of two y's

Jim Lemon jim at mail.bitwrit.com.au
Tue Feb 18 03:59:36 CET 2014


> 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
>
Hi Ramiro,
Check out twoord.plot in the plotrix package.

Jim




More information about the R-help mailing list