R:lattice.qq如何绘制治疗[x]与对照的多面板图?
我有一个如下所示的数据帧:R:lattice.qq如何绘制治疗[x]与对照的多面板图?,r,lattice,quantile,R,Lattice,Quantile,我有一个如下所示的数据帧: str(Data) 'data.frame': 11520 obs. of 29 variables: $ groupname : Factor w/ 8 levels "Control","Treatment1",..: 1 1 1 1 1 1 1 1 1 1 ... $ fCycle : Factor w/ 2 levels "Dark","Light": 2 2 2 2 2 2 2 2 2 2 ... $ totdist : num
str(Data)
'data.frame': 11520 obs. of 29 variables:
$ groupname : Factor w/ 8 levels "Control","Treatment1",..: 1 1 1 1 1 1 1 1 1 1 ...
$ fCycle : Factor w/ 2 levels "Dark","Light": 2 2 2 2 2 2 2 2 2 2 ...
$ totdist : num 0 67.5 89.8 109.1 58.3 ...
#etc.
qq(groupname~totdist|fCycle, data=Data,
subset=(groupname=='Control'|groupname=='Treatment1'))
我可以做一个单一的治疗1与对照的对比图,如下所示:
str(Data)
'data.frame': 11520 obs. of 29 variables:
$ groupname : Factor w/ 8 levels "Control","Treatment1",..: 1 1 1 1 1 1 1 1 1 1 ...
$ fCycle : Factor w/ 2 levels "Dark","Light": 2 2 2 2 2 2 2 2 2 2 ...
$ totdist : num 0 67.5 89.8 109.1 58.3 ...
#etc.
qq(groupname~totdist|fCycle, data=Data,
subset=(groupname=='Control'|groupname=='Treatment1'))
看起来是这样的:
str(Data)
'data.frame': 11520 obs. of 29 variables:
$ groupname : Factor w/ 8 levels "Control","Treatment1",..: 1 1 1 1 1 1 1 1 1 1 ...
$ fCycle : Factor w/ 2 levels "Dark","Light": 2 2 2 2 2 2 2 2 2 2 ...
$ totdist : num 0 67.5 89.8 109.1 58.3 ...
#etc.
qq(groupname~totdist|fCycle, data=Data,
subset=(groupname=='Control'|groupname=='Treatment1'))
我想自动绘制类似的图,处理2与控制…处理X与控制。这是循环的地方还是lattice有更好的方法?在单个面板上执行此操作需要一些重新安排。首先,我将生成一个与您的结构相同的示例数据集
library(lattice)
Data <- data.frame(groupname = factor(rep(c('Control',paste('Treatment',1:7,sep='')),each = 100)),
fCycle = factor(rep(rep(c('Dark','Light'),each = 50),8)),
totdist = sample(unlist(iris),800,replace = TRUE))
然后重新排列数据集,以便给每个治疗组一份对照数据的副本
Data2 <- NULL
for(treat in paste('Treatment',1:7,sep='')){
Data2 <- rbind(Data2,
cbind(rbind(Data[Data$groupname == treat,],Data[Data$groupname == 'Control',]),
treat))
}
如果您希望每个处理都有单独的绘图,那么循环会更好
pdf('treatVsContQq.pdf')
for(treat in paste('Treatment',1:7,sep='')){
print(qq(groupname~totdist|fCycle, data=Data,
subset=(groupname=='Control'|groupname==treat)))
}
dev.off()
谢谢你的详细解释。考虑到我对数据集所做的其他事情,循环似乎是最简单的解决方案。