Full labels in trellis plot in R
I'm having some trouble getting labels on a trellis plot in R. This is an example below
x <- c(1,2,3)
y <- c(2,4,6)
z <- c(0.1,0.5,2)
combo <- expand.grid(x,y,z)
combo <- data.frame(combo)
names(combo) <- c("x","y","z")
outcome <- function(l){
(l[1]*l[2]) / l[3]
}
resp <- apply(combo, 1, outcome)
levelplot(resp ~ x * y | z, data = combo, pretty = TRUE, region = TRUE,开发者_StackOverflow社区
contour = FALSE)
I ideally want each one to be labeled "z=0.1" "z=0.5" and "z=2". I can get it to say z ( as it does currently), and get it to say the value without z, but I really want both. Can anyone help?
Thanks.
P.S (apologies for spacing on the code, formatting seems to have messed it up a bit!)
Make z
a factor with the text you want as the labels. Here I make a new variable zF
as a factor of z
to leave the original z
unchanged. I also rewrote your data generation commands in a way I prefer; perhaps you will find that useful too.
zz <- c(0.1, 0.5, 2)
combo <- expand.grid( x = c(1, 2, 3),
y = c(2, 4, 6),
z = zz )
combo$resp <- with(combo, x*y/z)
combo$zF <- with(combo, factor(z, levels=zz, labels=paste("z =", zz)))
levelplot(resp ~ x * y | zF, data = combo, pretty = TRUE, region = TRUE,
contour = FALSE)
精彩评论