R 更改晶格打印中条带上的文本
如何更改晶格图条带中显示的文本? 例子: 假设我有一个由3列组成的数据帧测试R 更改晶格打印中条带上的文本,r,lattice,R,Lattice,如何更改晶格图条带中显示的文本? 例子: 假设我有一个由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 对格
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) # 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!
我认为你想要的东西可以通过以下方式获得:
z <-c( "a" , "b" ) # Same number of values as there are panels
xyplot(a~x | y,data=test,strip=strip.custom(factor.levels=z))
z您不需要'z'变量:factor.levels=c(“a”,“b”)就可以了。我只是想强调,它需要与面板具有相同的级别数量,而不是数据点的数量
z <-c( "a" , "b" ) # Same number of values as there are panels
xyplot(a~x | y,data=test,strip=strip.custom(factor.levels=z))