调整面板之间的线宽

时间:2013-11-02 15:53:19

标签: r lattice

考虑以下格子示例:

library(lattice)
x <- c(1:10, 1:10)
y <- c(10:1, 10:1)
z <- c(1:10, seq(1,20, by=2))
a = c(rep("one",10),rep("two",10))

DF <- data.frame(x, y, z, a)

xyplot(y ~ x | a, groups = z < 5, data = DF, col = c("black", "red"),
 pch=20, cex=0.3)

我的问题是:如何增加垂直线的刻度 分隔面板?

1 个答案:

答案 0 :(得分:2)

你可以玩这样的事情。我自定义面板功能,根据条件变量在左侧或右侧为每个面板添加一个段。

xyplot(y ~ x | a, groups = z < 5, data = DF, col = c("black", "red"),
       pch=20, cex=0.3,
       panel = function(...,subscripts){
         limits <- current.panel.limits()
         xx <- limits$xlim
         yy <- limits$ylim
         if(unique(print(DF[subscripts,'a']))=="two"){
           lsegments(xx[1], yy[1], xx[1], yy[2],lwd=20)
         }else{
           lsegments(xx[2], yy[1], xx[2], yy[2],lwd=20)
         }

         panel.xyplot(...,subscripts=subscripts)
       })

enter image description here