Timo Schmid
2011-Sep-13 12:30 UTC
[R] Mathematical expressions in the group labels in lattice
Hi, I am working with the lattice package and I want to label to groups in the xyplots with mathematical expressions. I short example for this library(lattice) Case<-factor(rep(1:2,each=300)) xx<-rnorm(600,0,1) yy<-rnorm(600,0,1) xyplot(yy~xx|Case) This results in two scatter plots with label "1" and "2". I would like to substitute this labels by math expression. I used the following code Case<-factor(rep(1:2,each=300)) levels(Case) <- c(expression(R^2),expression(sigma_[i])) xx<-rnorm(600,0,1) yy<-rnorm(600,0,1) xyplot(yy~xx|Case) But the label did not change to mathematical expressions. Any ideas? Thank you very much for your help. [[alternative HTML version deleted]]
David Winsemius
2011-Sep-13 13:30 UTC
[R] Mathematical expressions in the group labels in lattice
On Sep 13, 2011, at 8:30 AM, Timo Schmid wrote:> > Hi, > > I am working with the lattice package and I want to label to groups > in the xyplots with mathematical expressions. > I short example for this > > library(lattice) > > Case<-factor(rep(1:2,each=300)) > xx<-rnorm(600,0,1) > yy<-rnorm(600,0,1) > xyplot(yy~xx|Case) > > This results in two scatter plots with label "1" and "2". I would > like to substitute this labels by math expression. I used the > following code > > Case<-factor(rep(1:2,each=300)) > levels(Case) <- c(expression(R^2),expression(sigma_[i])) > xx<-rnorm(600,0,1) > yy<-rnorm(600,0,1) > xyplot(yy~xx|Case) > > But the label did not change to mathematical expressions. Any ideas?You should be looking at the strip.custom function. It has worked examples.> Thank you very much for your help.-- David Winsemius, MD West Hartford, CT
David Winsemius
2011-Sep-13 13:44 UTC
[R] Mathematical expressions in the group labels in lattice
On Sep 13, 2011, at 9:30 AM, David Winsemius wrote:> > On Sep 13, 2011, at 8:30 AM, Timo Schmid wrote: > >> >> Hi, >> >> I am working with the lattice package and I want to label to groups >> in the xyplots with mathematical expressions. >> I short example for this >> >> library(lattice) >> >> Case<-factor(rep(1:2,each=300)) >> xx<-rnorm(600,0,1) >> yy<-rnorm(600,0,1) >> xyplot(yy~xx|Case) >> >> This results in two scatter plots with label "1" and "2". I would >> like to substitute this labels by math expression. I used the >> following code >> >> Case<-factor(rep(1:2,each=300)) >> levels(Case) <- c(expression(R^2),expression(sigma_[i])) >> xx<-rnorm(600,0,1) >> yy<-rnorm(600,0,1) >> xyplot(yy~xx|Case) >> >> But the label did not change to mathematical expressions. Any ideas? > > You should be looking at the strip.custom function. It has worked > examples.The worked examples only illustrate a few of the arguments. The factor.levels argument is probably what you wanted: xyplot(yy~xx|Case, strip=strip.custom(factor.levels= c( expression(R^2), expression(sigma_[i]) ) )> > >> Thank you very much for your help. > > > -- > David Winsemius, MD > West Hartford, CT > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT