[R] using "substitute" inside a legend
Uwe Ligges
ligges at statistik.tu-dortmund.de
Fri Apr 3 16:26:04 CEST 2009
Mathew Fox wrote:
> Hello list,
>
> I have a linear regression:
>
> mylm = lm(y~x-1)
>
> I've been reading old mail postings as well as the plotmath demo and I came
> up with a way to print an equation resulting from a linear regression:
>
> model = substitute(list("y"==slope%*%"x", R^2==rsq),
> list(slope=round(mylm$coefficients[[1]],2),rsq=round(summary(mylm)$adj.r.squared,
> 2)))
>
> I have four models and I need to list each equation in a legend. I'm using:
>
> legend(20, 120, title = "fitted models", c(model1, model2, model3, model4),
> lty=1, col=c("blue", "red", "black", "green"))
legend(20, 120, title = "fitted models",
do.call("expression", list(model1, model2, model3, model4)),
lty=1, col=c("blue", "red", "black", "green"))
Uwe Ligges
> But this only works when I have up to two models. With four models the
> formatting is lost. I suspect the concatenation converts the objects into
> List and this destroys the formatting.
>
> Does anybody have any suggestions? The main difficulty I have is
> substituting R squared / slope values from a linear model into a
> mathematical expression.
>
> Thanks,
>
> M.
>
> [[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