R 如何在lattice条件标签条中插入希腊字母?
我正在制作一个简单的xyplot,我想在条件标签条/面上包括希腊字符和数学方程,见下文(“tau”和“cond”) 我知道可以在lattice和ggplot2中添加数学表达式和特殊字符,例如。我还知道,使用ggplot2,可以使用facet_grid命令()添加图例 我还没有成功地使expression()命令与lattice一起工作,或者以任何其他方式实现它R 如何在lattice条件标签条中插入希腊字母?,r,ggplot2,label,lattice,facet,R,Ggplot2,Label,Lattice,Facet,我正在制作一个简单的xyplot,我想在条件标签条/面上包括希腊字符和数学方程,见下文(“tau”和“cond”) 我知道可以在lattice和ggplot2中添加数学表达式和特殊字符,例如。我还知道,使用ggplot2,可以使用facet_grid命令()添加图例 我还没有成功地使expression()命令与lattice一起工作,或者以任何其他方式实现它 # Load packages require(lattice) require(gridExtra) require(grid) #
# 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)]
#加载包
需要(格子)
需要(额外)
需要(网格)
#生成一些值
x您可以使用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"