如何在格子条件标签条中插入希腊字母?

How to insert Greek letters in lattice conditional labels strips?

我正在制作一个简单的 xyplot,我想在条件标签 strip/facet 上包含希腊字符和数学方程式,见下文("tau" 和 "cond")。

我知道在lattice和ggplot2中可以添加数学表达式和特殊字符比如here. I also know that with ggplot2 you can add a legend with facet_grid command (here)。

我还没有成功地使 expression() 命令与 lattice 一起工作或以任何其他方式实现它。

# Load packages
require(lattice)
require(gridExtra)
require(grid)

# Generate some values
x<-rnorm(100,10,4)
y<-rnorm(100,10,1)
cond1<-rbinom(100,1,0.5)
cond2<-rbinom(100,1,0.5)

groups<-sample(c(0:10),100,replace=TRUE)
dataa<-data.frame(y,x1,cond1,cond2,groups)
cond1<-factor(cond1,labels = c(expression(tau),"cond1"))
cond2<-factor(cond2,labels = c(expression(tau),"cond2"))
# ploting function
  xyplot(y~x|cond1*cond2,groups=groups,
         col = gray(seq(0.01,0.7,length=length(levels(as.factor(groups))))),
         pch = 1:length(levels(as.factor(groups))),
         key = NULL)]

而不是 expression,您可以只使用 "tau" 的 unicode:

# Generate some values
x<-rnorm(100,10,4)
y<-rnorm(100,10,1)
cond1<-rbinom(100,1,0.5)
cond2<-rbinom(100,1,0.5)

groups<-sample(c(0:10),100,replace=TRUE)
dataa<-data.frame(y,x,cond1,cond2,groups)
cond1<-factor(cond1,labels = c("\u03C4","cond1"))
cond2<-factor(cond2,labels = c("\u03C4","cond2"))

# ploting function
xyplot(y~x|cond1*cond2,groups=groups,
       col = gray(seq(0.01,0.7,length=length(levels(as.factor(groups))))),
       pch = 1:length(levels(as.factor(groups))),
       key = NULL)

输出:

> levels(cond1)
[1] "τ"     "cond1"