Dear list, My problem is to change the strip text of lattice panels when using two factors. I have a data frame with two factors: df <- expand.grid( "fact1"=c("y","b","r"), "fact2"=c("far","por","lis","set"), "year"=1991:2000, "value"= NA) df[,"value"] <- sample(1:50, 120, replace=TRUE) I can make simple xyplot and change the text of the factor levels with strip.custom: require("lattice") xyplot( value ~ year | fact1, data=df, type="b", subset= fact2=="far", strip = strip.custom(bg=gray.colors(1,0.95), factor.levels=c("yellow", "black", "red")), layout=c(1,3) ) But how can I change the text of the factor levels when using both factors as in this plot: xyplot( value ~ year | fact1*fact2, data=df, type="b") (fact2 levels text should change to: c("faro","porto","lisbon","setubal")) I read the help for strip.default and the emails archive, tried with "which.given" but could not find out how to accomplish this. Many thanks, Rafael Duarte -- Rafael Duarte Marine Resources Department - DRM IPIMAR - National Research Institute for Agriculture and Fisheries Av. Bras?lia, 1449-006 Lisbon - Portugal Tel:+351 21 302 7000 Fax:+351 21 301 5948 e-mail: rduarte at ipimar.pt
Try this: levels(df$fact2) <- c("faro","porto","lisbon","setubal") xyplot( value ~ year | fact1*fact2, data=df, type="b") On 9/22/06, Rafael Duarte <rduarte at ipimar.pt> wrote:> Dear list, > My problem is to change the strip text of lattice panels when using two > factors. > I have a data frame with two factors: > > df <- expand.grid( "fact1"=c("y","b","r"), > "fact2"=c("far","por","lis","set"), "year"=1991:2000, "value"= NA) > df[,"value"] <- sample(1:50, 120, replace=TRUE) > > I can make simple xyplot and change the text of the factor levels with > strip.custom: > > require("lattice") > xyplot( value ~ year | fact1, data=df, type="b", subset= fact2=="far", > strip = strip.custom(bg=gray.colors(1,0.95), factor.levels=c("yellow", > "black", "red")), > layout=c(1,3) > ) > > But how can I change the text of the factor levels when using both > factors as in this plot: > xyplot( value ~ year | fact1*fact2, data=df, type="b") > > (fact2 levels text should change to: c("faro","porto","lisbon","setubal")) > > I read the help for strip.default and the emails archive, tried with > "which.given" but could not find out how to accomplish this. > > Many thanks, > Rafael Duarte > > -- > Rafael Duarte > Marine Resources Department - DRM > IPIMAR - National Research Institute for Agriculture and Fisheries > Av. Bras?lia, 1449-006 Lisbon - Portugal > Tel:+351 21 302 7000 Fax:+351 21 301 5948 > e-mail: rduarte at ipimar.pt > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
On 9/26/06, Joe Moore <emgt_r at hotmail.com> wrote:> Dear All: > > In the following code which I modified from previous question,Perhaps you should also have checked if it runs after the modification.> in addition > to show the fact1 level names (y, b, r) in strips, I also want to have a > color bar to indicate the state of every panel (in this example, y > correspods to 1, and b, r correspond to 0). Does anyone have a quick > solution?No, but this might give you a hint (you need to write a suitable panel function): xyplot(value ~ year | fact1:factor(state), data=df, type="b", subset= fact2=="far", layout=c(1,3)) Deepayan> > Thanks > > > > > > df <- expand.grid("fact1"=c("y","b","r"), > "fact2"=c"far","por","lis","set"), "year"=1991:2000, "value"= NA) > df[,"value"] <- sample(1:50, 120, replace=TRUE) > df$state <- 0 > df$state[df$fact1=="y"] <- 1 > > require("lattice") > xyplot( value ~ year | fact1, data=df, type="b", subset= fact2=="far", > strip = strip.custom(bg=gray.colors(1,0.95), > factor.levels=c("yellow", "black", "red")), layout=c(1,3)) >