2

我正在尝试使用下表构建一些格子箱图

Table = structure(list(T1 = c(0.291087321369092, 0.273666903677489, 0.28310355958841, 
0.284740195855848, 0.295147975635073, 0.311420595965798, 0.291715874011621, 
0.283184027096442, 0.293903569836777, 0.287475601654195, 0.285616753677472, 
0.311174820952075, 0.287718140987709, 0.284171440123499, 0.306648997486453, 
0.296666677175582, 0.267712673230721, 0.268172747179194, 0.282515694671931, 
0.275166455045057, 0.290677888190142, 0.28925362685232, 0.308675947395171, 
0.280783034596667, 0.293825918534905, 0.321187687739256, 0.316655886927714, 
0.306212759138124, 0.298058984840916, 0.288205090461148, 0.31125783131106, 
0.281113913883764), T2 = c(0.254641064713426, 0.280025002552195, 
0.265431676967411, 0.260018566448208, 0.241113868252169, 0.224969659994714, 
0.256666545183005, 0.26899868567758, 0.254889821628355, 0.256369320142347, 
0.265651766783899, 0.223656902559304, 0.259521892511503, 0.257931132867981, 
0.215928878425669, 0.242755942003399, 0.315657914021147, 0.307310393081742,
0.275207754304725, 0.296106839381649, 0.255484283039166, 0.253043444440123, 
0.221582655924359, 0.264993533576062, 0.237539473920042, 0.173638172129653, 
0.207913054356728, 0.208239244766248, 0.231349331756598, 0.236781399925237, 
0.227976661572611, 0.256537362632766)), .Names = c("T1", "T2"
), class = "data.frame", row.names = c(NA, -32L))

我可以为其中一列创建箱线图

Var1<-structure(as.integer(c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2)), .Label= c("no","yes"), class="factor")
Var2<-structure(as.integer(c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,1,1,1,1,2,2,2,2)), .Label=c("no","yes"),class="factor")
Var3<-structure(as.integer(c(1,1,1,1,2,2,2,2,1,1,1,1,2,2,2,2,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2)), .Label=c("normal","low"),class="factor")

T1<-Table[,c("T1")]
T2<-Table[,c("T2")]

library(lattice)
library(latticeExtra)
library(gridExtra)

table.df<-cbind(Var1,Var2,Var3,Table)

trellis<-useOuterStrips(bwplot(T1~Var1|Var2+Var3,groups=Var1,data=table.df,main="title",ylab=NULL)) 

但是我无法用两列创建图表。像这张图片(从http://www.statmethods.net/下载):

在此处输入图像描述

有什么建议吗?

4

2 回答 2

1

像这样(注意没有表示T2):

bwplot(T1 ~ Var1 | Var2 + Var3, data=tab, main='title', ylab=NULL)

在此处输入图像描述

或者可能是这样的:

tab <- reshape(table.df, direction='long', varying=c('T1','T2'), sep='')
bwplot(T ~ factor(paste0('T', time)) | Var2 + Var3, data=tab, groups=Var1, main='title', ylab=NULL)

在此处输入图像描述

于 2013-01-29T04:13:19.703 回答
1

您是否想将数据框中的两个数字列(T1 和 T2)相互绘制 - 这就是您想要的吗?

useOuterStrips(xyplot(T1 ~ T2 | Var2 + Var3, groups=Var1, data=table.df, 
               auto.key=T))

在此处输入图像描述

于 2013-01-28T18:55:22.533 回答