R has a rich set of options for including this mathematical text on plots. We previously discussed this in a tutorial.
Answers to the exercises are available here.
Load the LakeHuron data set using the
data() function. This data includes the lake’s water depth in feet each year from 1875—1972.
Plot Lake Huron water depth over time. Also use
lm() to run a linear model and plot a best fit line. Also, use
summary() to look at the model fit.
str() on the previous
summary() object to see everything you can extract from the
summary() object. Also, be able to extract the model coefficients specifically.
Add text for a linear model (y[i] = alpha + beta*X[i]) on your plot using the
text() function combined with
Again, add text detailing a linear model, but use the model coefficients in place of alpha and beta in the previous exercise. You will need to use
Add the R^2 symbol to the plot. Use
substitute() to include the model estimated R^2 on the plot.
In bold text, include R’s notation for a p-value, Pr(>|t|), in the title of the plot.
Use the model estimated p-value for the significance of the slope of the line in the title of the plot.
Use demo(plotmath) or ?plotmath to learn more about using mathematical notation in R