R项目:绘制数据框
9059 2011-02-18 2.81
9060 2011-02-21 <NA>
9061 2011-02-22 2.72
9062 2011-02-23 2.75
9063 2011-02-24 2.73
9064 2011-02-25 2.7
9065 2011-02-28 2.73
9066 2011-03-01 2.75
9067 2011-03-02 2.77
9068 2011-03-03 2.79
9069 2011-03-04 2.81
9070 2011-03-07 2.81
9071 2011-03-08 2.83
9072 2011-03-09 2.78
9073 2011-03-10 2.72
9074 2011-03-11 2.76
9075 2011-03-14 2.75
9076 2011-03-15 2.7
上面是名为“mydata”的数据框的片段。第一列的名称为 V1,第二列的名称为 V2。第一列包含使用 as.Date() 函数转换的日期。
我想将其绘制在 xy 网格上,其中 x 轴为第 1 列,y 轴为第 2 列。我已经尝试了几个小时的各种组合但没有成功。
我尝试过
> plot(mydata[,1], mydata[,2])
这会导致 R 控制台挂起,因为它似乎正在渲染一些无意义的内容。
9059 2011-02-18 2.81
9060 2011-02-21 <NA>
9061 2011-02-22 2.72
9062 2011-02-23 2.75
9063 2011-02-24 2.73
9064 2011-02-25 2.7
9065 2011-02-28 2.73
9066 2011-03-01 2.75
9067 2011-03-02 2.77
9068 2011-03-03 2.79
9069 2011-03-04 2.81
9070 2011-03-07 2.81
9071 2011-03-08 2.83
9072 2011-03-09 2.78
9073 2011-03-10 2.72
9074 2011-03-11 2.76
9075 2011-03-14 2.75
9076 2011-03-15 2.7
The above is a snippet of a data frame named 'mydata'. The name of the first column is V1 and the second V2. The first column contains dates which was converted using the as.Date() function.
I want to plot this on a x-y grid with column-1 on the x-axis and column-2 on the y-axis. I've tried various combinations for hours without success.
I tried
> plot(mydata[,1], mydata[,2])
This causes the R console to hang as it appears that it is rendering something nonsensical.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我有用(尽管我不知道它是否会产生所需的输出?
This works for me (although I don't know if it produces the desired output?
我让它工作执行以下操作:
这有效...但是如果我使用 read.csv 加载数据并尝试更改数据对象,那将是一场噩梦。
现在我有另一个问题。该图有效,但 x 轴标签每 10 年以年为单位报告一次。我的数据是自 1976 年以来的利差。我希望 x 轴标签为季度。我尝试了各种方法,包括以下内容,但出现了错误。
这是 str(我的对象) 的输出
I got it to work doing the following:
this worked... but if I load the data using read.csv and try to change the data object it is a nightmare.
Now I have another problem. The plot works but the x-axis label reported in years every 10 years. My data is the interest rate spread going back to 1976. I would like the x-axis label to be quarterly. I tried various things including the following but got errors.
This is the output of str(my object)