Change text on strips in lattice plots

一世执手 提交于 2019-12-10 01:06:43

问题


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.


回答1:


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))



回答2:


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!


来源:https://stackoverflow.com/questions/7373487/change-text-on-strips-in-lattice-plots

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!