2012-12-08 137 views
1

我有一个文件中的数据,它们看起来是这样的:如何绘制R中的折线图?

frame_delay 
0.000030 
0.000028 
0.000028 
0.000028 
0.000028 
0.000028 
0.000027 
0.000027 
0.000027 
0.000027 
0.000028 
0.000027 
.... 

我写这个剧本R

delays <- read.table("../../data/frame_delay.dat", header=T) 
plot(delays) 

,并得到如下图。

enter image description here

我不知道如何调整我的代码以获得更多的东西可读这样的(忘了线),其中y轴表示上述数值和X轴从1到任何数字的任何序列。

enter image description here

感谢您的答复!

回答

2

尝试这样的:

delays <- read.table("../../data/frame_delay.dat", header=T) 
plot(row(delays), delays[, 1], type="l") 

enter image description here

+0

好的!这听起来比我的好。现在如何将圆圈更改为直线?我要求不关心的线路是虚线的 –

+1

@FopaLéonConstantin'type =“l”'。仔细看看'plot'。 – joran

+0

@Fopa我编辑了答案来显示行。 –

0

给它一个人工的X轴,像这样的(命名您的数据帧x):

plot(cbind(1:length(x[[1]]), x), xlab='Index') 

这做同样的事情,也许是多一点效率:

plot(1:length(x[[1]]),x[[1]], xlab='Index') 
+0

不知道我明白。给出他的示例数据,两种表达式看起来似乎都打印了正确的图表(但带有点而不是线条)。 –

+0

当然他可能想'type =“l”'但是没有横坐标变量是他真正的问题。 –

+0

你说得对,对不起,我对传递一个向量与一个数据帧或矩阵感到困惑。但我绝对认为他们想要'type =“l”'。我现在要删除其中的一些评论... – joran