[R] Side by side scatter plots with specified regression lines

William Revelle lists at revelle.net
Mon Jun 13 04:53:06 CEST 2011


Dear Sigrid,

At 12:46 PM -0700 6/12/11, Sigrid wrote:
>I am new and self taught in R, so please bear with me.
>
>I want to create two scatter plots side by side. The data set includes
>measurements from two different countries with 7 treatments over a timeline
>(x-axis).
>
>Problem 1
>I want to have each plot to include the data from one of the countries with
>7 regression lines of the treatments, but I do no know how to divide the
>data between them. This is how I created one plot with all the data.
>
>> 
>>plot(YEAR,YIELD,col="red",xlab="Year",ylab="Yield",xlim=c(1,4),ylim=c(1,150))
>
>Problem 2
>The models I've found to describe the regression lines of the treatments
>seems to be different than the default ablines that R creates. I have the
>values of the exact values of intercepts and slopes, but does not know how
>to add them to the graph. This is what I got so far.
>
>>  abline(lm(YIELD[TREATMENT=="A"]~YEAR[TREATMENT=="A"]),lty=2,col="1")
>
>I hope this is enough to give me some pointers, otherwise I will try to
>elaborate.
>
>Thank you for your help.


Here is an example that might help:
library(psych)  #in order to get the sat.act data set
  my.data <- sat.act
  with(my.data,plot(SATV~SATQ,   col=c("blue","red")[gender]))
  by(my.data,my.data$education,   function(x) abline   (lm(SATV~SATQ,data=x),
     lty=c("solid", "dashed", "dotted",  "dotdash", "longdash", 
"twodash")[(x$education+1)]))

#to make two scatter plots side by side, use
op <- par(mfrow=c(1,2))


I hope this helps.

Bill




>
>--
>View this message in context: 
>http://r.789695.n4.nabble.com/Side-by-side-scatter-plots-with-specified-regression-lines-tp3592473p3592473.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>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