Change text on strips in lattice plots
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
开发者_Python百科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.
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))
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!
This is an old question, but I recently was struggling with this for shingles and factors. Here is an example for both cases using the quakes dataset.
library(lattice)
data(quakes)
As shingles, use strip = strip.custom(strip.names=FALSE, strip.levels=TRUE)
to just show the bins. Use as.table = TRUE
to sort the panels progressively. Using shingles retains the color bar in the strip.
depth1 <- equal.count(quakes$depth, number = 8, overlap = 0)
xyplot(lat ~ long | depth1,
data = quakes,
xlab = "Longtitude",
ylab = "Latitude",
aspect = 1,
pch = 1,
as.table = TRUE,
strip = strip.custom(strip.names=FALSE, strip.levels=TRUE),
)
As a factor, the strip name automatic.
depth2 <- cut(quakes$depth, breaks=8)
xyplot(lat ~ long | depth2,
data = quakes,
xlab = "Longtitude",
ylab = "Latitude",
aspect = 1,
pch = 1,
as.table = TRUE,
)
精彩评论