[R] Scatter plots, linear regression in ggplot2

ashz ashz at walla.co.il
Wed Aug 24 13:46:54 CEST 2011


Hi,

Based on some modification that I did to the R Cookbook Graphs Scatterplots
code, link:http://wiki.stdout.org/rcookbook/Graphs/Scatterplots%20(ggplot2)
 
I have some questions and I will appreciate a help:
-	How do I change the legend title?
-	How can I change the for each linear regression its color and linetype?
-	How can I add for both the linear regression lines their equations and
Rseq inside or below the plot?

Code:  
set.seed(955)
df <- data.frame(cond = rep(c('A', 'B'), each=10),
                 xvar = 1:20 + rnorm(20,sd=3),
                 yvar = 1:20 + rnorm(20,sd=3))
 
ggplot(df, aes(x=xvar, y=yvar, shape=cond)) +
scale_shape_manual(values=c(1,2))  +
    geom_smooth(method = "lm", se=FALSE) +    
         theme_bw()+
         geom_point(size = 5)+
         opts(title = "Xvar vs. Yvar",
          plot.title = theme_text(face="bold", size=16), 
          axis.text.x  = theme_text(angle=90),
          axis.title.x = theme_text(face="bold", size=12),
          axis.title.y = theme_text(face="bold", size=12, angle=90),
          panel.grid.major = theme_blank(), # switch off major gridlines
          panel.grid.minor = theme_blank()           
  ) 

Thanks a lot in advance


--
View this message in context: http://r.789695.n4.nabble.com/Scatter-plots-linear-regression-in-ggplot2-tp3765080p3765080.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list