Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
To add simple text to a plot, simply add an annotation. In this
example, we’ll create a linear model and use the predictvals()
function defined in Adding Fitted Lines from an Existing Model to
create a prediction line from the model. Then we’ll add an
annotation:
library(gcookbook)# For the data setmodel<-lm(heightIn ~ ageYear,heightweight)summary(model)Call: lm(formula=heightIn ~ ageYear,data=heightweight)Residuals: Min1Q Median3Q Max-8.3517-1.90060.13781.90718.3371Coefficients: Estimate Std. Error t value Pr(>|t|)(Intercept)37.43561.828120.48<2e-16***ageYear1.74830.132913.15<2e-16***---Signif. codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘ ’1Residual standard error:2.989on234degrees of freedom Multiple R-squared:0.4249,Adjusted R-squared:0.4225F-statistic:172.9on1and234DF,p-value:<2.2e-16