One way to do it is to use bquote
, and wrap any code that requires evaluation in .()
, as suggested by @GGrothendieck here.
legend('topleft', bty='n',
as.expression(bquote(R^2==.(format(summary(fit)$adj.r.squared,
digits=3)))))
See also Uwe's Automation of Mathematical Annotation in Plots R Help Desk.