为什么我在尝试在 R 中绘制 xts 对象时收到错误消息?
我正在尝试在R中绘制XTS对象。以下是我正在运行的代码,它为我提供了错误消息。
outcomes_xts <- xts(true_outcomes, as.yearqtr(end_dates))
plot(as.zoo("outcomes_xts"),
col = "purple",
lwd = 4,
ylab = "Quarterly Change in per-capita GDP (£)",
main = paste0("ADL(1,1): Pseudo-Out-Of-Sample Forecasts of Differenced",
" per-capita GDP, United Kingdom"),
ylim = -200:200)
但是,此代码给了我以下错误消息:
Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In xy.coords(x, y) : NAs introduced by coercion
从我收集的内容中,这可能是由XTS对象中的数据作为字符字符串而不是数字引起的,但是此数据并非如此。它也不是由XTS对象中的N/A引起的 - 我尝试在XTS对象上使用Na.omit(),但我仍然遇到相同的错误。感谢您,谢谢。
这是我运行dput(utemes_xts [1:30])
时的结果
structure(c(62, 48, 24, 30, 4, 12, 31, 58, 54, 70, 28, 13, 3,
33, 46, 20, 37, 15, 31, -52, -131, -169, -149, -37, -10, 8, 37,
69, 37, -6), class = c("xts", "zoo"), index = structure(c(1057017600,
1064966400, 1072915200, 1080777600, 1088640000, 1096588800, 1104537600,
1112313600, 1120176000, 1128124800, 1136073600, 1143849600, 1151712000,
1159660800, 1167609600, 1175385600, 1183248000, 1191196800, 1199145600,
1207008000, 1214870400, 1222819200, 1230768000, 1238544000, 1246406400,
1254355200, 1262304000, 1270080000, 1277942400, 1285891200), tzone = "UTC", tclass = "yearqtr"), .Dim = c(30L,
1L))
I am trying to plot an xts object in R. Below is the code I am running that gives me the error message.
outcomes_xts <- xts(true_outcomes, as.yearqtr(end_dates))
plot(as.zoo("outcomes_xts"),
col = "purple",
lwd = 4,
ylab = "Quarterly Change in per-capita GDP (£)",
main = paste0("ADL(1,1): Pseudo-Out-Of-Sample Forecasts of Differenced",
" per-capita GDP, United Kingdom"),
ylim = -200:200)
However this code gives me the following error message:
Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In xy.coords(x, y) : NAs introduced by coercion
From what I gather, this can be caused by the data in the xts object being stored as character strings rather than numeric, but this isn't the case with this data. Neither is it caused by n/a's in the xts object - I have tried using na.omit() on the xts object but I still get the same error. Help would be appreciated, thank you.
Here is my result when I run dput(outcomes_xts[1:30])
structure(c(62, 48, 24, 30, 4, 12, 31, 58, 54, 70, 28, 13, 3,
33, 46, 20, 37, 15, 31, -52, -131, -169, -149, -37, -10, 8, 37,
69, 37, -6), class = c("xts", "zoo"), index = structure(c(1057017600,
1064966400, 1072915200, 1080777600, 1088640000, 1096588800, 1104537600,
1112313600, 1120176000, 1128124800, 1136073600, 1143849600, 1151712000,
1159660800, 1167609600, 1175385600, 1183248000, 1191196800, 1199145600,
1207008000, 1214870400, 1222819200, 1230768000, 1238544000, 1246406400,
1254355200, 1262304000, 1270080000, 1277942400, 1285891200), tzone = "UTC", tclass = "yearqtr"), .Dim = c(30L,
1L))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论