【发布时间】:2012-02-20 19:12:36
【问题描述】:
我需要从存储在文本文件中的数据中画线。 到目前为止,我只能在图表上绘制点,我希望将它们作为线(折线图)。
代码如下:
pupil_data <- read.table("C:/a1t_left_test.dat", header=T, sep="\t")
max_y <- max(pupil_data$PupilLeft)
plot(NA,NA,xlim=c(0,length(pupil_data$PupilLeft)), ylim=c(2,max_y));
for (i in 1:(length(pupil_data$PupilLeft) - 1))
{
points(i, y = pupil_data$PupilLeft[i], type = "o", col = "red", cex = 0.5, lwd = 2.0)
}
请帮我改一下这行代码:
points(i, y = pupil_data$PupilLeft[i], type = "o", col = "red")
从数据中画线。
这是文件中的数据:
PupilLeft
3.553479
3.539469
3.527239
3.613131
3.649437
3.632779
3.614373
3.605981
3.595985
3.630766
3.590724
3.626535
3.62386
3.619688
3.595711
3.627841
3.623596
3.650569
3.64876
【问题讨论】:
-
如果要绘制
lines,为什么要使用points函数? -
在
plot()函数中添加type='l'并使用lines()aftwerards。 -
数据:PupilLeft3.553479 3.539469 3.527239 3.613131 3.649437 3.632779 3.614373 3.605981 3.595985 3.630766 3.590724 3.626535 3.62386 3.619688 3.595711 3.627841 3.623596 3.650569 3.64876 跨度>
-
我尝试了这两种解决方案,但是当我使用'lines()'时没有任何结果。 'plot()' fcn 中的 'type='l'' 在之后使用线条时也会发生同样的情况。
-
@user1221812:是你的循环弄乱了你的代码。请参阅我修改后的答案。