如何更改格子图条中显示的文本?例如:假设我有一个由3列组成的数据框测试
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
Run Code Online (Sandbox Code Playgroud)
正常调用格子图
xyplot(a~x | y,data=test)
Run Code Online (Sandbox Code Playgroud)
将在条带上给出带有文本"A"和"B"的图
如何在条带上写下不同的文字?
与另一个角色向量一起考虑
z
[1] "a" "a" "a" "a" "a" "b" "b" "b" "b" "b"
Run Code Online (Sandbox Code Playgroud)
和一个电话 strip.custom()
xyplot(a~x | y,data=test,strip=strip.custom(var.name=z))
Run Code Online (Sandbox Code Playgroud)
没有给出理想的结果.
实际上,这是一个国际化问题.
42-*_*42- 14
我想你想要的是:
z <-c( "a" , "b" ) # Same number of values as there are panels
xyplot(a~x | y,data=test,strip=strip.custom(factor.levels=z))
Run Code Online (Sandbox Code Playgroud)
如果你将角色向量作为一个因素,那么你可以只改变等级:
> 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!
Run Code Online (Sandbox Code Playgroud)