R格子箱线图网格

R lattice boxplot grids

我的数据类似于下面的形式。我想从中创建一个 4x4 的箱线图网格。但是,下面的代码只生成一个箱线图。当我做 xyplot 时,它绘制得很好。我是 R 的新手,所以我确定这是一个愚蠢的错误,但任何人都可以 help/answer 为什么 xyplot 和 bwplot 有不同的行为以及我如何获得 4x4 的箱线图?

library(lattice)
require(lattice)
t1 <- c(LETTERS[1:17])
m1 <- matrix( rnorm(12*16,mean=0,sd=1), 12, 16)
fac <- rep(1:4,3)
    m1 <- cbind(m1,fac)
    m1 <- data.frame(m1)
    colnames(m1) <- t1
    m1$Q <- as.factor(m1$Q)

xyplot(A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P ~ Q,
        data=m1,
        groups=A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P,
        scales=list(relation="free"),
        col="blue",
        layout=(c(4,4))
        )
bwplot(A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P ~ Q,
        data=m1,
        groups=A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P,
        col="blue",   
        coef=4, do.out = FALSE,
        layout=(c(4,4))
        )

首先尝试重新格式化数据:

library(reshape)
m1d<-melt(m1,id=17)

bwplot(value ~ Q | variable, data=m1d)

outer=TRUE 添加到 bwplot(...) 似乎可以解决问题:

bwplot(A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P ~ Q,
        data=m1,
        groups=A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P,
        col="blue",   
        coef=4, 
        do.out = FALSE,
        outer = TRUE,
        layout=(c(4,4))
        )

来自帮助文件:

A variation on this feature is when the ‘outer’ argument is set to ‘TRUE’. In that case, the plots are not superposed in each panel, but instead separated into different panels (as if a new conditioning variable had been added).