首页 文章

在格子图中更改条带上的文本

提问于
浏览
13

如何更改格子图条中显示的文本?例如:假设我有一个由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

正常调用格子图

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

将在条带上给出带有文本“A”和“B”的图

如何在条带上写下不同的文字?

与另一个角色向量一起考虑

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

并致电 strip.custom()

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

没有给出理想的结果 .

实际上,这是一个国际化问题 .

2 回答

  • 14

    如果你将角色向量作为一个因素,那么你可以只改变等级:

    > 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!
    
  • 8

    我想你想要的东西可以通过以下方式获得:

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

相关问题