我想在格子多面板图中将文本标签(例如a,b,c,d)添加到不同的面板。我希望文本出现在每个图中的同一点(即左上角),但是当比例不恒定时,我似乎无法做到这一点。
library(lattice)
X <- rnorm(100)
Y <- rnorm(100)
n <- c(rep("control", 5), rep("low", 5), rep("medium", 5),
rep("high", 5), rep("v.high", 5))
Z <- c(rep("a", 25), rep("b", 25), rep("c", 25), rep("d", 25))
df1 <- data.frame(X, Y, n, Z)
MyText <- c("(c)", "(d)", "(a)", "(b)")
xyplot(X ~ Y|Z, data=df1,
groups=n,
panel=function(x, y,...){
panel.xyplot(x, y,...)
panel.text(-1, 1.5, labels=MyText[panel.number()])
},
ylab = expression(paste(delta, ""^"15", "N")),
xlab = expression(paste(delta, ""^"13", "C")),
scales=list(relation="free"),
strip = F,
auto.key=list(columns= 5, title="Treatments", cex.title=1))
如果有人对此有任何建议,我们将不胜感激。
答案 0 :(得分:5)
一种方法是grid.text
,指的是npc
坐标所需的位置,左下角是(0,0),右上角是(1,1)。 / p>
library(grid)
xyplot(X~Y|Z, data=df1,
groups=n,
panel=function(x, y,...) {
panel.xyplot(x,y,...)
grid.text(MyText[panel.number()], unit(0.05, 'npc'), unit(0.95, 'npc'))
},
ylab = expression(paste(delta, ""^"15","N")),
xlab = expression(paste(delta, ""^"13","C")),
scales=list(relation="free"),
strip = F,
auto.key=list(columns= 5, title="Treatments", cex.title=1))