[R] Display Equation on plot
Duncan Murdoch
murdoch at stats.uwo.ca
Tue Mar 24 18:11:47 CET 2009
On 3/24/2009 12:50 PM, Douglas M. Hultstrand wrote:
> Hello,
>
> I am using the lm to fit a linear model to data, I was wondering if
> there is a way to display the equation on a plot using the extracted lm
> coefficients? I am using the plot() function to create the plot/.png.
>
> Example:
> lm_mod <- lm(data1~data2)
>
> intercept = 48.54
> slope = 0.4856
>
> I want to display equation on a plot as y=0.4856x+48.54
mtext(bquote( y == .(slope) * x + .(intercept)), side=1, line=4)
will put it in the bottom margin. Use text() with appropriate
coordinates to put it in the plot area instead.
Duncan Murdoch
>
> Any thoughts or suggestions are appreciated.
>
> Thanks,
> Doug
>
More information about the R-help
mailing list