1 year ago
#370939
shineoballo
Why am I getting an error message when trying to plot an xts object in R?
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))
r
xts
zoo
0 Answers
Your Answer