Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change text on strips in lattice plots

Tags:

r

lattice

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.

like image 770
joheid Avatar asked Sep 10 '11 17:09

joheid


2 Answers

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))
like image 190
IRTFM Avatar answered Sep 30 '22 07:09

IRTFM


If you make your character vector a factor then you can just change the levels:

> xyplot(a~x | y,data=test)       # your plot
> test$y=as.factor(test$y)        # convert y to factor
> xyplot(a~x | y,data=test)       # should be identical
> levels(test$y)=c("Argh","Boo")  # change the level labels
> xyplot(a~x | y,data=test)       # new panel labels!
like image 23
Spacedman Avatar answered Sep 30 '22 05:09

Spacedman