当比例分开时,将文本添加到格子中的不同面板?
Adding text to different panels in lattice when scales are separate?
我想将文本标签(例如 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))
如果有人对此有任何建议,将不胜感激。
一种方式是grid.text
,用npc
坐标指代想要的位置,其中左下角为(0, 0),右上角为(1, 1) .
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))
我想将文本标签(例如 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))
如果有人对此有任何建议,将不胜感激。
一种方式是grid.text
,用npc
坐标指代想要的位置,其中左下角为(0, 0),右上角为(1, 1) .
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))