我是一名统计学家和R新手,正在使用RStudio学习很多关于这两方面的知识。我导入了一个数据框架,其中包含纵向平衡研究设计中混合效应方差分析的长格式数据。我的数据有以下标题:治疗、主题、日期、年龄和体积。我可以使用以下代码单独按年龄组或仅按治疗组绘制图形:
lineplot.CI(mri$Date,mri$Les.V.PD, mri$Age,main="Mean Lesion Volume by Age Group on PD Sequences",xlab="MRI timepoints (months post treatment)", ylab="Lesion Volume(cm^3)")我想用lineplot.CI绘制,日期在x轴上,4条线:2年治疗,6年治疗,2年对照,6年对照。此代码仅生成按年龄组绘制的线条图:
lineplot.CI(mri$Date,mri$Les.V.PD,mri$Age,subset=mri$Treatment %in% c("MSC","Control"),main="Mean Lesion Volume by Age Group on PD Sequences", xlab="MRI timepoints (months post treatment)", ylab="Lesion Volume(cm^3)")这段代码给出了与上面代码相同的线条图:
lineplot.CI(mri$Date,mri$Les.V.PD,mri$Age,subset= .(mri$Treatment == "MSC" | mri$Treament == "Control"),main="Mean Lesion Volume by Age Group on PD Sequences",xlab="MRI timepoints (months post treatment)", ylab="Lesion Volume(cm^3)")我还尝试了这段代码的各种不同版本:
lineplot.CI(mri$Date,mri$Les.V.PD,mri$Age,subset(mri,Treatment == "MSC"|Treatment =="Control"),main="Mean Lesion Volume by Age Group on PD Sequences",xlab="MRI timepoints (months post treatment)", ylab="Lesion Volume(cm^3)")或
lineplot.CI(mri$Date,mri$Les.V.PD,mri$Age,subset(mri, !(Treatment == "MSC"|Treatment == "Control")),main="Mean Lesion Volume by Age Group on PD Sequences",xlab="MRI timepoints (months post treatment)", ylab="Lesion Volume(cm^3)")并得到以下错误:
Error in subset.default(mri$Treatment == "MSC" | mri$Treament == "Control") : 参数"subset“缺失,没有默认值
Error in match.arg(type) : 'arg' must be NULL or a character vector我知道这个子集包含在lineplot.CI中,但是我见过的所有示例都显示了subset=NULL。我更喜欢继续使用lineplot.CI,因为它会自动插入错误条,而且我对ggplot2也不熟悉。
谢谢
发布于 2014-04-08 00:13:41
您可以使用:
lineplot.CI(xField, yField, group=gField, data=subset(dataSource,
field1=="value1" | field2=="value2"))问题的作者尝试使用带有参数“lineplot.CI”的子集命令。取而代之的是,可以使用带有子集的值的参数"data“。
因此,不是使用
lineplot.CI (...,subset=(数据源,select表达式),...)
我们的想法是使用:
lineplot.CI(...,data=subset(数据源,select表达式),...)
这种另一种方式对我很有效。
发布于 2015-03-19 02:09:32
我也陷入了同样的问题...经过一些研究,我发现lineplot.CI documentation不仅缺少很多有用的信息,而且当它们实际上是外部方法时,它提供了一些函数,就好像它们是它的一部分,这些函数可以是结合和lineplot.CI,以达到特定的结果。子集是R环境的基本函数,因此它不依赖于lineplot.CI。This link提供了有关子集的更多信息,但可以在R包中提供的脱机文档中找到更好/更深入的说明。在R命令行上键入
help(subset)您将看到将其应用于数据帧的有趣方法。
将新创建的子集分配给lineplot.CI的data参数,您将获得所需的结果。例如(基于您的数据):
df <- subset(
mri,
Treatment %in% c("MSC", "Control"),
select = c( Treatment, Subject, Date, Age, Volume )
)
lineplot.CI(
data = df,
x.factor = Date,
response = Les.V.PD,
group = Age,
main="Mean Lesion Volume by Age Group on PD Sequences",
xlab="MRI timepoints (months post treatment)",
ylab="Lesion Volume(cm^3)"
)
https://stackoverflow.com/questions/22918776
复制相似问题