Reputation: 3152
I have a lattice graph with two conditions: one condition (x1) has 4 levels and one has 2 levels (x2). The graph has a stripes for each variable x1 and x2:
df <- data.frame(y = runif(100,0,10)
, x1 = rep(c("A","B","C","D"),25)
, x2 = as.numeric(c(runif(100)<0.5))
)
histogram( ~y | x1 + as.factor(x2), data=df)
I would like to change the levels of x1.
I tried with:
histogram( ~y | x1 + as.factor(x2)
, data=df
, strip = strip.custom(
, factor.levels = c("no","yes"))
)
)
but I don't konw how to assign the levels condition x2. I appreciate any hint.
Upvotes: 2
Views: 993
Reputation: 98449
Searching the web found solution defining own strip function.
my.strip <- function(which.given, ..., factor.levels) {
levs <- if (which.given == 2) c("no","yes") #levels for your second factor (x2)
else c("AAA", "BBB", "CCC", "DDD") #levels for your first factor (x1)
strip.default(which.given, ..., factor.levels = levs)
}
histogram( ~y | x1 + as.factor(x2) , data=df, strip = my.strip)
library(latticeExtra)
useOuterStrips(histogram( ~y | x1 + as.factor(x2) , data=df),
strip =strip.custom(factor.levels = c("AAA","BBB","CCC","DDD")),
strip.left=strip.custom(factor.levels = c("no","yes")))
Upvotes: 4