r - Superscript a legend in plot() and add the adjusted R2 from lm() -
how can superscript 2 in "adjusted r2 = " , import value summary()?
as example:
#multiple linear regression model nitrate<-sswells[,6] predictors<-sswells[,9:31] linear<-lm(nitrate~.,data=predictors) summary(linear) #obs vs. predicted obs <-nitrate pred <-linear$fitted.values obs.pred <- lm(obs~pred) plot(obs~pred, main="observed vs. predicted \nmultiple linear regression", xlim=c(0,14), ylim=c(0,14), ylab="predicted nitrate [mg l-1 no3-n]", xlab="observed nitrate [mg l-1 no3-n]") abline(obs.pred)
through searching, found that:
lgd <- bquote(r^2 == .(round(summary(obs.pred)$r.squared,3))) legend("bottomright", legend=lgd)
gives me legend 2 in r2 superscripted, when modify to:
lgd <- bquote("adjusted" r^2 == .(round(summary(obs.pred)$adj.r.squared,3))) legend("bottomright", legend=lgd)
so can adjusted r2 new value error
error: unexpected symbol in "lgd <- bquote("adjusted" r"
i've tried taking quotes out around adjusted, doesn't work. i've tried putting single quote in front of it, doesn't work. i've read file , examples , can't figure out.
so tried:
text(2,12,expression(paste("adjusted ", r^2, " =", sep = "")))
this works, except can't figure out how import adjusted r2 summary(obs.pred)$adj.r.squared go on =, if do:
text(2,12,expression(paste("adjusted ", r^2, " =", round(summary(actpred)$r.squared,3), sep = "")))
it prints text instead of actual value.
is there simple way to i'm missing?
i agree @jruf003,
lgd <- bquote(adjusted~r^2 == .(round(summary(obs.pred)$r.squared,3)))
note : don't quote "adjusted" in
bquote(...)
expression
then, can add in main title of plot plot(1:10, main=lgd)
Comments
Post a Comment