Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:lattice.qq如何绘制治疗[x]与对照的多面板图?_R_Lattice_Quantile - Fatal编程技术网

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()

谢谢你的详细解释。考虑到我对数据集所做的其他事情,循环似乎是最简单的解决方案。