【发布时间】:2014-05-20 01:42:45
【问题描述】:
我是一名统计学家,也是一名 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") :
参数“子集”丢失,没有默认值
Error in match.arg(type) : 'arg' must be NULL or a character vector
我知道子集包含在 lineplot.CI 中的 sciplot 包文档,但我看到的所有示例都显示子集=NULL。我宁愿继续使用 lineplot.CI,因为会自动插入误差线,而且我不熟悉 ggplot2。
谢谢
【问题讨论】: