Change text on strips in lattice plots

joheid picture joheid · Sep 10, 2011 · Viewed 11.6k times · Source

how do I change the text displayed in the strips of lattice plots? example: suppose I have a data frame test consisting of 3 columns

x
 [1]  1  2  3  4  5  6  7  8  9 10

y
 [1] "A" "A" "A" "A" "A" "B" "B" "B" "B" "B"

a
 [1] -1.9952066 -1.7292978 -0.8789127 -0.1322849 -0.1046782  0.4872866
 [7]  0.5199228  0.5626998  0.6392686  1.6604549

a normal call to a lattice plot

xyplot(a~x | y,data=test)

will give the plot with the Text 'A' and 'B' on the strips

How can I get different texts written on the strips?

An attept with another character vector

z
 [1] "a" "a" "a" "a" "a" "b" "b" "b" "b" "b"

and a call to strip.custom()

xyplot(a~x | y,data=test,strip=strip.custom(var.name=z))

does not give the desired result.

In reality it is an internationalization problem.

Answer

IRTFM picture IRTFM · Sep 10, 2011

I think what you want can be obtained by:

z <-c( "a" , "b" ) # Same number of values as there are panels
xyplot(a~x | y,data=test,strip=strip.custom(factor.levels=z))