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

时间:2018-10-30 17:14:45

标签: r ggplot2 label lattice facet

我正在生成一个简单的xyplot,我想在条件标签strip / facet上包括希腊字符和数学方程式(请参见下面的“ tau”和“ cond”)。

我知道可以在here等晶格和ggplot2中添加数学表达式和特殊字符。我也知道,使用ggplot2,您可以使用facet_grid命令(here)添加图例。

我尚未成功使expression()命令与点阵一起工作或使其以任何其他方式发生。

# 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)]

I want to be able to change "tau", "cond1" and "cond2" into Greek letters

1 个答案:

答案 0 :(得分:1)

代替expression,您可以将Unicode用作“ tau”:

# 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"

enter image description here