This was my initial attempt at creating a title on a graph of the R squared value: x<-rnorm(10) y<-rnorm(10) plot(x,y, main=paste(expression(R^2)," = ",round(summary(lm(y~ x))$r.squared, digits=3), sep="")) I've read various other posts that say expression needs to be taken outside the paste, but I can't seem to get it work as the following fails plot(x,y, main=expression(paste("R^2"," = ",round(summary(lm(y~ x))$r.squared, digits=3), sep=""))) I tried it with title() and didn't get much further either. Hmmm, any ideas what am I missing? Thanks Paul -- View this message in context: http://n4.nabble.com/Paste-expression-in-graph-title-tp1289272p1289272.html Sent from the R help mailing list archive at Nabble.com.
Have a look at the help page for ?plotmath, and try also this: x <- rnorm(10) y <- rnorm(10) R2 <- round(summary(lm(y ~ x))$r.squared, 3) plot(x, y, main = bquote(R^2 == .(R2))) I hope it helps. Best, Dimitris Paul Chatfield wrote:> This was my initial attempt at creating a title on a graph of the R squared > value: > > x<-rnorm(10) > y<-rnorm(10) > plot(x,y, main=paste(expression(R^2)," = ",round(summary(lm(y~ > x))$r.squared, digits=3), sep="")) > > I've read various other posts that say expression needs to be taken outside > the paste, but I can't seem to get it work as the following fails > > plot(x,y, main=expression(paste("R^2"," = ",round(summary(lm(y~ > x))$r.squared, digits=3), sep=""))) > > I tried it with title() and didn't get much further either. > > Hmmm, any ideas what am I missing? > > Thanks > > Paul-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014
Try bquote: set.seed(123) x<-rnorm(10) y<-rnorm(10) R2 <- summary(lm(y ~ x))$r.squared R2round <- round(R2, digits = 3) plot(x, y, main = bquote(R^2 == .(R2round))) On Mon, Jan 25, 2010 at 7:06 AM, Paul Chatfield <p.s.chatfield at reading.ac.uk> wrote:> > This was my initial attempt at creating a title on a graph of the R squared > value: > > x<-rnorm(10) > y<-rnorm(10) > plot(x,y, main=paste(expression(R^2)," = ",round(summary(lm(y~ > x))$r.squared, digits=3), sep="")) > > I've read various other posts that say expression needs to be taken outside > the paste, but I can't seem to get it work as the following fails > > plot(x,y, main=expression(paste("R^2"," = ",round(summary(lm(y~ > x))$r.squared, digits=3), sep=""))) > > I tried it with title() and didn't get much further either. > > Hmmm, any ideas what am I missing? > > Thanks > > Paul > -- > View this message in context: http://n4.nabble.com/Paste-expression-in-graph-title-tp1289272p1289272.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Try this: plot(x, y, main = bquote(R^2 == .(round(summary(lm(y ~ x))$r.squared, 3)))) On Mon, Jan 25, 2010 at 10:06 AM, Paul Chatfield <p.s.chatfield at reading.ac.uk> wrote:> > This was my initial attempt at creating a title on a graph of the R squared > value: > > x<-rnorm(10) > y<-rnorm(10) > plot(x,y, main=paste(expression(R^2)," = ",round(summary(lm(y~ > x))$r.squared, digits=3), sep="")) > > I've read various other posts that say expression needs to be taken outside > the paste, but I can't seem to get it work as the following fails > > plot(x,y, main=expression(paste("R^2"," = ",round(summary(lm(y~ > x))$r.squared, digits=3), sep=""))) > > I tried it with title() and didn't get much further either. > > Hmmm, any ideas what am I missing? > > Thanks > > Paul > -- > View this message in context: http://n4.nabble.com/Paste-expression-in-graph-title-tp1289272p1289272.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O