I got a lm function from a dataframe with two groups. I am facet_wrapping one of them. IN each facet_wrap plot I would like to show the function of the lm.
I have this one (and it works):
lm_eqn = function(DAT){
  m = lm(Percentage ~ as.numeric(Year), DAT);
  eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(r)^2~"="~r2, 
                   list(a = format(coef(m)[1], digits = 2), 
                        b = format(coef(m)[2], digits = 2), 
                        r2 = format(summary(m)$r.squared, digits = 3)))
  as.character(as.expression(eq));                 
}
eq <- ddply(DAT,.(Class),lm_eqn)
Now i would like to add the p- value inside the lots aswel..so I wat to use this code:
lm_eqn = function(DAT){
  m = lm(Percentage ~ as.numeric(Year), DAT);
  eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(r)^2~"="~r2,","~~italic(r)^2~"="~p,
                   list(a = format(coef(m)[1], digits = 2), 
                        b = format(coef(m)[2], digits = 2), 
                        r2 = format(summary(m)$r.squared, digits = 3,
                        p = format(summary(m)$p.value, digits = 3)))
  as.character(as.expression(eq));                 
}
eq <- ddply(DAT,.(Class),lm_eqn)
But this one gives an error...and I don't understand :/ Is there a way to also add the F value?
Thank you in advance.
