changing background color in xyplot()

前端 未结 1 515
离开以前
离开以前 2020-12-21 02:29

I\'m trying to get the background colors of the strips to change (it is a 6 by 6 matrix and i have 6 strip colors stocked in a vector named cola). I\'ve tried to combine thi

1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-21 03:11

    This code (quickly adapted from my answer to this SO question) gets you part of the way to a solution. (I'd be interested to learn whether/how it can be adapted to also print text in the each of the strips).

    One thing to note is that the customized strip function need to be passed directly to useOuterStrips(), rather than to the nested call to bwplot().

    # Create a function to be passes to "strip=" argument of xyplot
    myStripStyle <- function(which.panel, factor.levels, ...) {
        panel.rect(0, 0, 1, 1,
                   col = bgColors[which.panel],
                   border = 1)
        ## This call to panel.text() commented out because it does not
        ## work as I would have expected/hoped it to
        # panel.text(x = 0.5, y = 0.5,
        #            font=2,
        #            lab = factor.levels[which.panel],
        #            col = "black")
    }
    
    mycola <- rainbow(6)
    bgColors <- mycola
    
    useOuterStrips(bwplot(~B$ylab|B$g1*B$g2,ylab="",xlab="",as.table=TRUE,
                          panel=function(...,bg){
                              panel.fill(col=mycol[panel.number()])
                          },
                          scale=list(draw=FALSE)),
                   strip = myStripStyle,
                   strip.left = myStripStyle)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题