儿童在不同年龄开始的改善线图

时间:2015-09-08 07:19:02

标签: linechart

我正在尝试创建一个重叠的折线图,显示儿童随着时间的推移而改善但有些孩子从6岁开始,其他8,9等等。这是我使用的代码,但它产生了奇怪的结果。我不知道我是否需要更好地构建我的数据文件或者:

我的数据的第一行如下所示:

Name    Participant Age Correct
Becky   1           9   22
Becky   2           12  28
Byron   3           8   25
Byron   4           13  21

dat = read.table("Data03_IMPROVE1.txt", T)
head(dat)
attach(dat)

为方便起见,将因子转换为数字

dat$Participant <- as.numeric(dat$Participant) 
ntrees <- max(dat$Participant)

获取x轴和y轴的范围

xrange <- range(Age) 
yrange <- range(Correct) 

设置图

plot(xrange, yrange, type="n", xlab="Age",
     ylab="Correct" ) 
colors <- rainbow(ntrees) 
linetype <- c(1:ntrees) 
plotchar <- seq(18,18+ntrees,1)

添加行

for (i in 1:ntrees) { 
  tree <- subset(dat, Participant==i) 
  lines(dat$Age, dat$Correct, type="b", lwd=1.5,
        lty=linetype[i], col=colors[i], pch=plotchar[i]) 
}

0 个答案:

没有答案
相关问题