我的问题是用格子框架剥离我的面板。
testData<-data.frame(star=rnorm(1200),frame=factor(rep(1:12,each=100))
,n=factor(rep(rep(c(4,10,50),each=100),4))
,var=factor(rep(c("h","i","h","i"),each=300))
,stat=factor(rep(c("c","r"),each=600))
)
levels(testData$frame)<-c(1,7,4,10,2,8,5,11,3,9,6,12)# order of my frames
histogram(~star|factor(frame), data=testData
,as.table=T
,layout=c(4,3),type="density",breaks=20
,panel=function(x,params,...){
panel.grid()
panel.histogram(x,...,col=1)
panel.curve(dnorm(x,0,1), type="l",col=2)
}
)
我在寻找的是:
答案 0 :(得分:0)
当它们已经是因素时,您不需要在公式的条件部分中的项目周围添加因子调用。如果您想在两个因素之间进行交叉,interaction
函数是最佳方法。它甚至有一个'sep'参数,它接受一个新的行字符。这是我能做的最接近的:
h<-histogram(~star|interaction(stat, var, sep="\n") + n, data=testData ,
as.table=T ,layout=c(4,3), type="density", breaks=20 ,
panel=function(x,params,...){ panel.grid()
panel.histogram(x,...,col=1)
panel.curve(dnorm(x,0,1), type="l",col=2) } )
plot(h)
useOuterStrips(h,strip.left = strip.custom(horizontal = FALSE),
strip.lines=2, strip.left.lines=1)
当我尝试单独输入三个因素然后尝试使用useOuterStrips
时出现错误。它不会接受三个独立的条件因素。我在Rhelp搜索了帖子,但唯一完美的问题点得到了一个未经检验的建议,当我尝试它时,它失败了。