Hello, I want to have a title that will look something like: "Results for \theta=2.1", given that I have a variable theta=2.1, and \theta should show on the screen like the greek letter. I've tried a lot of things: theta <- 2.1 plot(1:10, main=expression(paste("Results for", theta, "=", eval(theta)))) or using bquote plot(1:10, main=paste("Results for ", bquote(theta == .(theta)))) or using substitute, etc. I could not make it work. This should be easy. I would appreciate your help. Thanks, Adrian
This'll work. theta <- 2.1 plot(NA, xlim=c(0,1), ylim=c(0,1), xlab=bquote(theta == .(theta)), ylab=bquote(theta == .(theta)), main=bquote(paste("Results for ",theta =.(theta)))) Charles Annis, P.E. Charles.Annis at StatisticalEngineering.com phone: 561-352-9699 eFax: 614-455-3265 http://www.StatisticalEngineering.com -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Adrian Dragulescu Sent: Tuesday, July 25, 2006 4:12 PM To: r-help at stat.math.ethz.ch Subject: [R] greek letters, text, and values in labels Hello, I want to have a title that will look something like: "Results for \theta=2.1", given that I have a variable theta=2.1, and \theta should show on the screen like the greek letter. I've tried a lot of things: theta <- 2.1 plot(1:10, main=expression(paste("Results for", theta, "=", eval(theta)))) or using bquote plot(1:10, main=paste("Results for ", bquote(theta == .(theta)))) or using substitute, etc. I could not make it work. This should be easy. I would appreciate your help. Thanks, Adrian ______________________________________________ R-help at stat.math.ethz.ch 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.
Marc Schwartz (via MN)
2006-Jul-25 20:37 UTC
[R] greek letters, text, and values in labels
On Tue, 2006-07-25 at 13:12 -0700, Adrian Dragulescu wrote:> Hello, > > I want to have a title that will look something like: > "Results for \theta=2.1", given that I have a variable theta=2.1, and > \theta should show on the screen like the greek letter. > > I've tried a lot of things: > theta <- 2.1 > plot(1:10, main=expression(paste("Results for", theta, "=", eval(theta)))) > > or using bquote > plot(1:10, main=paste("Results for ", bquote(theta == .(theta)))) > > or using substitute, etc. I could not make it work. This should be easy. > > I would appreciate your help. > > Thanks, > AdrianAdrian, Try this: theta <- 2.1 plot(1:10, main = bquote(paste("Results For: ", theta == .(theta)))) You need to surround the full expression with bquote() so that the paste()d text is within it. bquote() then returns an expression that is passed to plotmath. HTH, Marc Schwartz
Try: plot(1:10, main = bquote("Results for" ~ theta == .(theta))) On 7/25/06, Adrian Dragulescu <adrian_d at eskimo.com> wrote:> > Hello, > > I want to have a title that will look something like: > "Results for \theta=2.1", given that I have a variable theta=2.1, and > \theta should show on the screen like the greek letter. > > I've tried a lot of things: > theta <- 2.1 > plot(1:10, main=expression(paste("Results for", theta, "=", eval(theta)))) > > or using bquote > plot(1:10, main=paste("Results for ", bquote(theta == .(theta)))) > > or using substitute, etc. I could not make it work. This should be easy. > > I would appreciate your help. > > Thanks, > Adrian > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Unfortunately this does not work for lattice graphics. In such case I do something like the following, but I still do not know how to plot Greek letters in the panel titles: theta <- 2.1 gr <- as.factor(c(1,2)) levels(gr)[1]<-"Group 1" levels(gr)[2]<-"Group 2" library(lattice) print(xyplot(1~1|gr, xlab=eval(substitute(expression(paste(theta, " = ", tval)), list(tval=theta))), ylab=eval(substitute(expression(paste(theta, " = ", tval)), list(tval=theta))), main=eval(substitute(expression(paste("Results for ",theta, " = ", tval)), list(tval=theta))), sub=eval(substitute(expression(paste(theta, " = ", tval)), list(tval=theta))) )) best, valentin
Try this where gr and theta are as in your post: xyplot(1~1|gr, main = as.expression(bquote(theta == .(theta))), strip = strip.custom(factor.levels = expression(theta, beta)) ) On 7/27/06, Valentin Todorov <valentin.to at gmail.com> wrote:> Unfortunately this does not work for lattice graphics. In such case I > do something like the following, but I still do not know how to plot > Greek letters in the panel titles: > > theta <- 2.1 > gr <- as.factor(c(1,2)) > levels(gr)[1]<-"Group 1" > levels(gr)[2]<-"Group 2" > library(lattice) > print(xyplot(1~1|gr, > xlab=eval(substitute(expression(paste(theta, " = ", tval)), > list(tval=theta))), > ylab=eval(substitute(expression(paste(theta, " = ", tval)), > list(tval=theta))), > main=eval(substitute(expression(paste("Results for ",theta, " = ", > tval)), list(tval=theta))), > sub=eval(substitute(expression(paste(theta, " = ", tval)), > list(tval=theta))) > )) > > > best, > valentin > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >