Related
I have made a graph that works fine when I run the code without a for loop. When the same graph is a part of a for loop, I get the error message "plot.new has not been called yet" and no graph. How can I run this graph in a for loop?
There are very many questions about this error message. I have read more than 15 of them carefully and tried several things, but with no success.
For example, I looked at the problem described in plot.new has not been called yet. However, I cannot see how my code could close the device when I use a for loop, but not when it is run without the for loop.
The plot consists of one plot.xts() and then several lines().
GRA_events <- c("20080118/20080201", "20080123/20080206", "20080205/20080219", "20080210/20080224", "20080229/20080314", "20080912/20080926", "20081002/20081016", "20081206/20081220", "20081218/20090101", "20090209/20090223")
for (i in 1:length(GRA_events)) {
#i=1
period <- GRA_events[i]
png(paste("GRA_",i,".png", sep=""), width = 1200, height = 600)
windows(width = 16, height = 8)
# plot(0, 0, xlab="", ylab="")
par(mfrow=c(1,1), oma=c(4.5, 1.5, 4, 2.5), mar=c(0.1,4,0.1,0.1), cex=1, las=1)
plot.xts(GRA_mod$Qprecip, on=1,
main =period, ylim=c(0,10),
col = "blue", type="l", lwd=2,
ylab="Precip. & flow [m3/10min]",
yaxis.right = FALSE)
lines(GRA_mod$Qin, on=1, col = "black", type="l", lwd = 2)
addLegend("topright", on=1,
legend.names = c("Flow (obs)", "Precipitation", "Flow (model)"),
lty=c(1, 1, 1), lwd=c(2, 2, 1),
col=c("black", "blue", "red"))
lines(GRA_all_part$Air.temp, on=NA, main =period, ylim=c(-15,25),
col = "red", type="l", lwd=2, ylab="Air temp. [degree C]")
lines(GRA_all_part$zero_line, on=2, col = "grey", lwd=2, lty=2)
lines(GRA_all_part$SnowDepth, on=2, main =period, col = "blue", lwd=2,
ylab="Snow depth")
addLegend("topright", on=2,
legend.names = c("Snow depth", "Air temperature"),
lty=c(1,1), lwd=c(2,2),
col=c("blue","red"))
lines(GRA_all_part$LW_ground, on=NA, main =period, col = "green",
lwd=2, ylim=c(165,400))
lines(GRA_all_part$LW_in, on=3, main =period, col = "black", lwd=2)
addLegend("topright", on=3,
legend.names = c("Longwave in", "Longwave ground"),
lty=c(1,1), lwd=c(1,1),
col=c("black","green"))
lines(GRA_all_part$SW_ground, on=NA, main =period, col = "red", lwd=2,
ylim=c(-2,425))
lines(GRA_all_part$Tot_rad, on=4, main =period, col = "black", lwd=3)
addLegend("topright", on=4,
legend.names = c("Total radiation", "Shortwave ground"),
lty=c(1,1), lwd=c(3,1),
col=c("black","red"))
title(main = "Available data", outer=TRUE)
dev.copy(which = 2)
dev.list()
dev.off()
}
When I skip the first (for (i in 1:length(GRA_events)) {) and the last row (}) in the code and instead start at i=1, the graph is nicely plotted both on screen and on a .png-file, see figure below. When I use the for loop, I get the error message.
Finally, some data to reproduce the error (much shorter, but it gives the same problem):
GRA_mod <- structure(c(0.05856, -0.07752, 0.099, -0.16374, 0.26532, -0.22224,
-0.05352, -0.06132, 0.18216, 0.01536, -0.00222, 0.07116, -0.00996,
-0.04068, 0.14706, 0.00318, -0.04626, -0.0105, -0.09654, 0.00762,
0.1026, 0.01314, -0.08766, 0.03522, -0.03792, -0.00972, -0.00174,
-0.0354, 0.07428, -0.1035, -0.00468, 0.05442, 0.01062, 0.06954,
-0.04374, -0.02568, -0.0435, -0.02772, 0.05766, 0.03222, -0.02136,
-0.04164, 0.10182, -0.01296, 0.0675, 0.021, 0.08514, 0.02994,
-0.02862, 0.03162, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), class = c("xts",
"zoo"), .indexCLASS = c("POSIXct", "POSIXt"), .indexTZ = "GMT", tclass = c("POSIXct",
"POSIXt"), tzone = "GMT", index = structure(c(1202169600, 1202170200,
1202170800, 1202171400, 1202172000, 1202172600, 1202173200, 1202173800,
1202174400, 1202175000, 1202175600, 1202176200, 1202176800, 1202177400,
1202178000, 1202178600, 1202179200, 1202179800, 1202180400, 1202181000,
1202181600, 1202182200, 1202182800, 1202183400, 1202184000, 1202184600,
1202185200, 1202185800, 1202186400, 1202187000, 1202187600, 1202188200,
1202188800, 1202189400, 1202190000, 1202190600, 1202191200, 1202191800,
1202192400, 1202193000, 1202193600, 1202194200, 1202194800, 1202195400,
1202196000, 1202196600, 1202197200, 1202197800, 1202198400, 1202199000
), tzone = "GMT", tclass = c("POSIXct", "POSIXt")), .Dim = c(50L,
2L), .Dimnames = list(NULL, c("Qin", "Qprecip")))
GRA_all_part <- structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, -0.12,
-0.12, -0.12, -0.12, -0.12, -0.12, -0.07, -0.07, -0.07, -0.07,
-0.07, -0.07, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, -0.08, -0.08,
-0.08, -0.08, -0.08, -0.08, -0.22, -0.22, -0.22, -0.22, -0.22,
-0.22, -0.18, -0.18, -0.18, -0.18, -0.18, -0.18, -0.2, -0.2,
-0.2, -0.2, -0.2, -0.2, -0.25, -0.25, 298.07, 298.07, 298.07,
298.07, 298.07, 298.07, 299.35, 299.35, 299.35, 299.35, 299.35,
299.35, 299.98, 299.98, 299.98, 299.98, 299.98, 299.98, 300.38,
300.38, 300.38, 300.38, 300.38, 300.38, 300.98, 300.98, 300.98,
300.98, 300.98, 300.98, 302.35, 302.35, 302.35, 302.35, 302.35,
302.35, 302.07, 302.07, 302.07, 302.07, 302.07, 302.07, 297.35,
297.35, 297.35, 297.35, 297.35, 297.35, 297.93, 297.93, 278.25,
278.25, 278.25, 278.25, 278.25, 278.25, 283.78, 283.78, 283.78,
283.78, 283.78, 283.78, 286.83, 286.83, 286.83, 286.83, 286.83,
286.83, 286.68, 286.68, 286.68, 286.68, 286.68, 286.68, 287.82,
287.82, 287.82, 287.82, 287.82, 287.82, 289.92, 289.92, 289.92,
289.92, 289.92, 289.92, 286.13, 286.13, 286.13, 286.13, 286.13,
286.13, 259.12, 259.12, 259.12, 259.12, 259.12, 259.12, 271.43,
271.43, -0.98, -0.98, -0.98, -0.98, -0.98, -0.98, -0.83, -0.83,
-0.83, -0.83, -0.83, -0.83, -0.67, -0.67, -0.67, -0.67, -0.67,
-0.67, -0.97, -0.97, -0.97, -0.97, -0.97, -0.97, -0.77, -0.77,
-0.77, -0.77, -0.77, -0.77, -0.85, -0.85, -0.85, -0.85, -0.85,
-0.85, -0.97, -0.97, -0.97, -0.97, -0.97, -0.97, -1, -1, -1,
-1, -1, -1, -0.97, -0.97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2.865, -2.73,
-2.704, -2.703, -2.67, -2.487, -2.447, -2.443, -2.303, -2.406,
-2.507, -2.506, -2.499, -2.475, -2.459, -2.383, -2.372, -2.425,
-2.512, -2.566, -2.457, -2.41, -2.413, -2.393, -2.393, -2.377,
-2.383, -2.366, -2.316, -2.3, -2.175, -2.022, -1.99, -1.914,
-1.898, -1.87, -1.845, -1.812, -1.841, -1.93, -1.998, -1.995,
-2.083, -2.253, -2.463, -2.633, -2.647, -2.446, -2.376, -2.596,
0.874, 0.874, 0.874, 0.873, 0.873, 0.873, 0.872, 0.873, 0.873,
0.872, 0.871, 0.871, 0.871, 0.871, 0.87, 0.87, 0.87, 0.87, 0.871,
0.87, 0.869, 0.87, 0.869, 0.869, 0.869, 0.868, 0.868, 0.868,
0.869, 0.868, 0.868, 0.868, 0.868, 0.868, 0.869, 0.869, 0.868,
0.868, 0.867, 0.869, 0.869, 0.868, 0.867, 0.866, 0.865, 0.864,
0.864, 0.865, 0.865, 0.866, -2.567, -2.48, -2.47, -2.474, -2.373,
-2.207, -2.245, -2.133, -2.059, -2.3, -2.35, -2.335, -2.313,
-2.308, -2.245, -2.165, -2.16, -2.255, -2.336, -2.334, -2.183,
-2.197, -2.149, -2.171, -2.135, -2.143, -2.114, -2.064, -1.999,
-1.955, -1.768, -1.659, -1.657, -1.625, -1.633, -1.597, -1.543,
-1.508, -1.531, -1.595, -1.532, -1.524, -1.67, -1.799, -1.9,
-2.025, -2.051, -2.01, -1.998, -2.136, 0.976, -1.292, 1.65, -2.729,
4.422, -3.704, -0.892, -1.022, 3.036, 0.256, -0.037, 1.186, -0.166,
-0.678, 2.451, 0.053, -0.771, -0.175, -1.609, 0.127, 1.71, 0.219,
-1.461, 0.587, -0.632, -0.162, -0.029, -0.59, 1.238, -1.725,
-0.078, 0.907, 0.177, 1.159, -0.729, -0.428, -0.725, -0.462,
0.961, 0.537, -0.356, -0.694, 1.697, -0.216, 1.125, 0.35, 1.419,
0.499, -0.477, 0.527, 0.195, 0.27, 0.199, 0.247, 0.237, 0.203,
0.224, 0.187, 0.191, 0.256, 0.242, 0.256, 0.242, 0.271, 0.22,
0.276, 0.215, 0.233, 0.251, 0.22, 0.26, 0.237, 0.232, 0.233,
0.224, 0.228, 0.233, 0.228, 0.215, 0.228, 0.237, 0.238, 0.216,
0.191, 0.22, 0.187, 0.203, 0.207, 0.199, 0.203, 0.22, 0.216,
0.229, 0.211, 0.216, 0.22, 0.229, 0.22, 0.211, 0.211, 1873, 1872,
1873, 1871, 1874, 1871, 1871, 1870, 1872, 1872, 1872, 1872, 1872,
1871, 1873, 1873, 1872, 1872, 1871, 1871, 1871, 1871, 1870, 1871,
1870, 1870, 1870, 1869, 1870, 1869, 1868, 1869, 1869, 1869, 1869,
1868, 1868, 1867, 1868, 1868, 1868, 1867, 1868, 1868, 1868, 1869,
1869, 1869, 1869, 1869, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), class = c("xts",
"zoo"), .indexCLASS = c("POSIXct", "POSIXt"), .indexTZ = "GMT", tclass = c("POSIXct",
"POSIXt"), tzone = "GMT", index = structure(c(1202169600, 1202170200,
1202170800, 1202171400, 1202172000, 1202172600, 1202173200, 1202173800,
1202174400, 1202175000, 1202175600, 1202176200, 1202176800, 1202177400,
1202178000, 1202178600, 1202179200, 1202179800, 1202180400, 1202181000,
1202181600, 1202182200, 1202182800, 1202183400, 1202184000, 1202184600,
1202185200, 1202185800, 1202186400, 1202187000, 1202187600, 1202188200,
1202188800, 1202189400, 1202190000, 1202190600, 1202191200, 1202191800,
1202192400, 1202193000, 1202193600, 1202194200, 1202194800, 1202195400,
1202196000, 1202196600, 1202197200, 1202197800, 1202198400, 1202199000
), tzone = "GMT", tclass = c("POSIXct", "POSIXt")), .Dim = c(50L,
15L), .Dimnames = list(NULL, c("SnowDepth", "SnowCover", "SnowCoverMountains",
"SW_ground", "LW_ground", "LW_in", "Tot_rad", "Precip", "Sun.temp",
"Soil.temp", "Air.temp", "Qin", "Qout", "V_med", "zero_line")))
When running the code below I get the following error:
Error in plot.new() : figure margins too large
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
The code I run is the following:
library(vars)
library(forecast)
datSel <- structure(list(oenb_dependent = c(1.0227039, -5.0683144, 0.6657713,
3.3161374, -2.1586704, -0.7833623, -0.2203209, 2.416144, -1.7625406,
-0.1565037, -7.9803936, 9.4594715, -4.8104584, 8.4827107, -6.1895262,
1.4288595, 1.4896459, -0.4198522, -5.1583964, 5.2502294, 1.0567102,
-1.0923342, -1.5852298, 0.6061936, -0.3752335, 2.5008664, -1.3999729,
2.2802166, -2.1468756, -1.4890328, -0.79254376, 3.21804705, -0.94407886,
-0.27802316, -0.20753079, -1.12610048, 2.0883735, -0.7424854,
0.44203729, -1.48905938, 1.39644424, -3.8917377, 11.25665848,
-9.22884035, 3.26856762, -0.00179541, -2.39664325, 4.00455574,
-5.60891295, 4.6556348, -4.40536951, 6.64234497, -7.34787319,
7.56303006, -8.23083674, 4.43247855, 1.31090412), carReg = c(0.73435946,
0.24001161, 16.90532537, -14.60281976, 6.47603166, -8.35815849,
3.55576685, 7.10705794, -4.6955223, 10.9623709, 5.5801857, -6.4499936,
-9.46196502, 9.36289122, -8.52630424, 5.45070994, -4.5346405,
-2.26716538, 2.56870398, 0.013737, 5.7750101, -27.1060826, 1.08977179,
4.94934712, 17.55391859, -13.91160577, 10.38981128, -11.81349246,
-0.0831467, 2.79748237, 1.84865463, -1.98736934, -6.24191695,
13.33602659, -3.86527871, 0.78720993, 4.73360651, -4.1674034,
9.37426802, -5.90660464, -0.4915792, -5.84811629, 9.67648643,
-6.96872719, -7.6535767, 0.24847595, 0.18685263, -2.28766949,
1.1544631, -3.87636933, -2.4731545, 4.33876671, 1.08836339, 5.64525271,
1.90743854, -3.94709355, -0.84611324), cpi = c(1.16, -3.26, 0.22,
-3.51, 0.84, -2.81, -0.34, -4.57, -0.12, -3.95, -1.37, -2.73,
0.35, -5.38, -4.43, -3.08, 0.74, -3.03, -1.09, -2, 0.35, -1.52,
1.28, 0.2, -0.25, -4.55, -2.49, -4.24, -0.31, -2.96, -2.24, -0.46,
-0.06, -2.67, -1.27, -1.4, -0.7, -0.96, -2.18, -2.53, -0.52,
-1.74, -2.18, -1.4, -0.34, -0.09, -1.65, -1.15, -0.17, -2.01,
-1.38, -1.24, 0.09, -2.44, -1.92, -2.61, -0.34), primConstTot = c(-0.33334,
-0.93333, -0.16667, -0.33333, -0.16667, -0.86666, -0.3, -0.4,
-0.26667, -1.56667, -0.73333, 0.1, -0.23333, -0.26667, -1.5774,
-0.19284, 0.38568, -2.42423, -0.93663, 0.08265, -0.63361, 0.0551,
-0.49587, 2.39668, -1.70798, -3.36085, -2.56196, 0.16529, 0,
-1.84572, -1.3774, -0.49586, -1.70798, -1.90081, -0.55096, -0.77134,
-0.16529, -0.30303, -0.17066, -0.23853, -0.64401, -1.52657, -1.57426,
-0.28623, -0.54861, -1.07336, -0.71558, 0.02385, -0.38164, -1.09721,
0, 0.14311, -0.38164, -1.02566, -0.42934, -0.35779, -0.4532),
resProp.Dwell = c(0.8, -4, -3.2, 2.7, -1.6, -1, -2.4, -0.4,
-0.8, 1, -12.1, 0.2, -5.2, 3.7, -2.7, -1.7, 1.5, 0.7, -7.9,
0.3, 0.3, 1.4, -3.3, -1, -1.6, 1.5, 0.5, 1.5, -1, -2.2, -3.5,
0.5, 0.5, -0.9, -0.4, -3.4, 0.9, 0.1, -0.2, -2.8, -0.8, -6.2,
11.3, -4.6, 1, 1.1, -1.7, 4.1, -5, 2.3, -2.3, 4.6, -6.3,
6.3, -6.9, 0, 2.4), cbre.office.primeYield = c(0, 0, 0.15,
0.15, 0.2, 0.2, 0.2, 0.25, 0.25, 0.25, 0.25, 0.2, 0.15, 0.1,
0.05, 0.15, 0.3, 0.35, 0.4, 0.3, 0.2, 0, -0.15, -0.85, -1,
-0.85, -0.75, -0.1, 0, 0, 0, 0.05, 0.05, 0.05, 0.05, 0, 0,
0, 0.2, 0.2, 0.2, 0.2, 0, 0, 0, 0, 0.25, 0.25, 0.25, 0.25,
0, 0, 0, 0, 0, 0, 0), cbre.retail.capitalValue = c(-1882.35294,
230.76923, -230.76923, -226.41509, -670.78117, -436.13707,
-222.22223, 0, -205.91233, -202.16847, 0, -393.5065, -403.91909,
-186.30647, -539.81107, -748.11463, -764.70588, -311.47541,
-301.42782, -627.09677, -480, 720, 782.6087, 645.96273, 251.42857,
1386.66667, -533.33334, -533.33333, -533.33333, 0, 0, -1024.56141,
-192.10526, 0, -730, 0, 0, 0, 0, 0, -834.28571, 0, -1450.93168,
0, 0, 0, -700.78261, 0, 0, 0, 0, 0, 0, 0, -1452, 0, 0)), .Names = c("oenb_dependent",
"carReg", "cpi", "primConstTot", "resProp.Dwell", "cbre.office.primeYield",
"cbre.retail.capitalValue"), row.names = c(NA, -57L), class = "data.frame")
#estimate lags
VARselect(datSel$oenb_dependent, lag.max=8, type="const")$selection
var <- VAR(datSel, p=6, type="const")
serial.test(var, lags.pt=10, type="PT.asymptotic")
summary(var)
par(mar=c(1,1,1,1))
fcst <- predict(var, n.ahead = 24) # this function works
plot(fcst$oenb_dependent, xlab="Year")
I do not have NAs in my fcst object.
Any suggestions, why R does not allow me to plot?
I have created a var autoregressive model:
> library(vars)
> dput(datSel)
structure(list(oenb_dependent = c(1.0227039, -5.0683144, 0.6657713,
3.3161374, -2.1586704, -0.7833623, -0.2203209, 2.416144, -1.7625406,
-0.1565037, -7.9803936, 9.4594715, -4.8104584, 8.4827107, -6.1895262,
1.4288595, 1.4896459, -0.4198522, -5.1583964, 5.2502294, 1.0567102,
-1.0923342, -1.5852298, 0.6061936, -0.3752335, 2.5008664, -1.3999729,
2.2802166, -2.1468756, -1.4890328, -0.79254376, 3.21804705, -0.94407886,
-0.27802316, -0.20753079, -1.12610048, 2.0883735, -0.7424854,
0.44203729, -1.48905938, 1.39644424, -3.8917377, 11.25665848,
-9.22884035, 3.26856762, -0.00179541, -2.39664325, 4.00455574,
-5.60891295, 4.6556348, -4.40536951, 6.64234497, -7.34787319,
7.56303006, -8.23083674, 4.43247855, 1.31090412), carReg = c(0.73435946,
0.24001161, 16.90532537, -14.60281976, 6.47603166, -8.35815849,
3.55576685, 7.10705794, -4.6955223, 10.9623709, 5.5801857, -6.4499936,
-9.46196502, 9.36289122, -8.52630424, 5.45070994, -4.5346405,
-2.26716538, 2.56870398, 0.013737, 5.7750101, -27.1060826, 1.08977179,
4.94934712, 17.55391859, -13.91160577, 10.38981128, -11.81349246,
-0.0831467, 2.79748237, 1.84865463, -1.98736934, -6.24191695,
13.33602659, -3.86527871, 0.78720993, 4.73360651, -4.1674034,
9.37426802, -5.90660464, -0.4915792, -5.84811629, 9.67648643,
-6.96872719, -7.6535767, 0.24847595, 0.18685263, -2.28766949,
1.1544631, -3.87636933, -2.4731545, 4.33876671, 1.08836339, 5.64525271,
1.90743854, -3.94709355, -0.84611324), cpi = c(1.16, -3.26, 0.22,
-3.51, 0.84, -2.81, -0.34, -4.57, -0.12, -3.95, -1.37, -2.73,
0.35, -5.38, -4.43, -3.08, 0.74, -3.03, -1.09, -2, 0.35, -1.52,
1.28, 0.2, -0.25, -4.55, -2.49, -4.24, -0.31, -2.96, -2.24, -0.46,
-0.06, -2.67, -1.27, -1.4, -0.7, -0.96, -2.18, -2.53, -0.52,
-1.74, -2.18, -1.4, -0.34, -0.09, -1.65, -1.15, -0.17, -2.01,
-1.38, -1.24, 0.09, -2.44, -1.92, -2.61, -0.34), primConstTot = c(-0.33334,
-0.93333, -0.16667, -0.33333, -0.16667, -0.86666, -0.3, -0.4,
-0.26667, -1.56667, -0.73333, 0.1, -0.23333, -0.26667, -1.5774,
-0.19284, 0.38568, -2.42423, -0.93663, 0.08265, -0.63361, 0.0551,
-0.49587, 2.39668, -1.70798, -3.36085, -2.56196, 0.16529, 0,
-1.84572, -1.3774, -0.49586, -1.70798, -1.90081, -0.55096, -0.77134,
-0.16529, -0.30303, -0.17066, -0.23853, -0.64401, -1.52657, -1.57426,
-0.28623, -0.54861, -1.07336, -0.71558, 0.02385, -0.38164, -1.09721,
0, 0.14311, -0.38164, -1.02566, -0.42934, -0.35779, -0.4532),
resProp.Dwell = c(0.8, -4, -3.2, 2.7, -1.6, -1, -2.4, -0.4,
-0.8, 1, -12.1, 0.2, -5.2, 3.7, -2.7, -1.7, 1.5, 0.7, -7.9,
0.3, 0.3, 1.4, -3.3, -1, -1.6, 1.5, 0.5, 1.5, -1, -2.2, -3.5,
0.5, 0.5, -0.9, -0.4, -3.4, 0.9, 0.1, -0.2, -2.8, -0.8, -6.2,
11.3, -4.6, 1, 1.1, -1.7, 4.1, -5, 2.3, -2.3, 4.6, -6.3,
6.3, -6.9, 0, 2.4), cbre.office.primeYield = c(0, 0, 0.15,
0.15, 0.2, 0.2, 0.2, 0.25, 0.25, 0.25, 0.25, 0.2, 0.15, 0.1,
0.05, 0.15, 0.3, 0.35, 0.4, 0.3, 0.2, 0, -0.15, -0.85, -1,
-0.85, -0.75, -0.1, 0, 0, 0, 0.05, 0.05, 0.05, 0.05, 0, 0,
0, 0.2, 0.2, 0.2, 0.2, 0, 0, 0, 0, 0.25, 0.25, 0.25, 0.25,
0, 0, 0, 0, 0, 0, 0), cbre.retail.capitalValue = c(-1882.35294,
230.76923, -230.76923, -226.41509, -670.78117, -436.13707,
-222.22223, 0, -205.91233, -202.16847, 0, -393.5065, -403.91909,
-186.30647, -539.81107, -748.11463, -764.70588, -311.47541,
-301.42782, -627.09677, -480, 720, 782.6087, 645.96273, 251.42857,
1386.66667, -533.33334, -533.33333, -533.33333, 0, 0, -1024.56141,
-192.10526, 0, -730, 0, 0, 0, 0, 0, -834.28571, 0, -1450.93168,
0, 0, 0, -700.78261, 0, 0, 0, 0, 0, 0, 0, -1452, 0, 0)), .Names = c("oenb_dependent",
"carReg", "cpi", "primConstTot", "resProp.Dwell", "cbre.office.primeYield",
"cbre.retail.capitalValue"), row.names = c(NA, -57L), class = "data.frame")
> #estimate lags
> VARselect(datSel, lag.max=7, type="const")$selection
AIC(n) HQ(n) SC(n) FPE(n)
7 7 7 6
> var <- VAR(datSel, p=5, type="const")
> serial.test(var, lags.pt=10, type="PT.asymptotic")
Portmanteau Test (asymptotic)
data: Residuals of VAR object var
Chi-squared = 401.1802, df = 245, p-value = 1.15e-09
> fcst <- predict(var, n.ahead = 24) # this function works
> plot(fcst, xlab="Year")
> forecast(var, 24)
Error in round(frequency) : non-numeric argument to mathematical function
However, I would like to use the forecast function instead of the predict function, because my current plots are all using the forecast function.
The error I get is:
Error in round(frequency) : non-numeric argument to mathematical function
Any suggestions how to use the forecast function correctly?
I appreciate your replies!
I am using the leaps package to generate the following plots:
> library(leaps)
>
>
> dput(datSel)
structure(list(oenb_dependent = c(1.0227039, -5.0683144, 0.6657713,
3.3161374, -2.1586704, -0.7833623, -0.2203209, 2.416144, -1.7625406,
-0.1565037, -7.9803936, 9.4594715, -4.8104584, 8.4827107, -6.1895262,
1.4288595, 1.4896459, -0.4198522, -5.1583964, 5.2502294, 1.0567102,
-1.0923342, -1.5852298, 0.6061936, -0.3752335, 2.5008664, -1.3999729,
2.2802166, -2.1468756, -1.4890328, -0.79254376, 3.21804705, -0.94407886,
-0.27802316, -0.20753079, -1.12610048, 2.0883735, -0.7424854,
0.44203729, -1.48905938, 1.39644424, -3.8917377, 11.25665848,
-9.22884035, 3.26856762, -0.00179541, -2.39664325, 4.00455574,
-5.60891295, 4.6556348, -4.40536951, 6.64234497, -7.34787319,
7.56303006, -8.23083674, 4.43247855, 1.31090412), gdp = c(-271.6,
-284.2, 34.3, -206, -253.1, -116.8, -169.9, -63.6, -174.2, -138.2,
-171.2, -198.2, -126.2, -222.5, -8.2, -172.5, -169.1, -207.5,
-114.6, -182.4, -43.7, 43.5, 166, 293.1, -30, -144.6, 16.9, -115.6,
-147.4, -189.1, -166.8, -157.9, -108.7, -150.9, -267.3, -176.2,
-231.3, -160.4, -251.5, -194.5, -186.3, -193, -171.6, -191.7,
-254.4, -140.6, -126.3, -66.7, -102.3, -100.4, -133.1, -61.8,
-1.1, -130.3, -35.8, -114.9, -79.1), employ = c(0.2237, -0.024,
0.0906, 0.2809, 0.0555, -0.2404, 0.1717, -0.1225, 0.0538, -0.1211,
-0.2819, 0.2998, -0.2625, -0.0808, 0.2338, -0.3807, -0.2774,
-0.0124, -0.2158, -0.1496, 0.0765, 0.2548, 0.2935, -0.129, 0.3021,
-0.2781, -0.4863, -0.0464, -0.5377, -0.0671, -0.5776, -0.1231,
-0.4383, -0.4593, -0.3337, -0.0388, -0.4048, -0.0609, -0.4173,
-0.1218, -0.1554, -0.1477, 2.4688, 0.1383, 0.1927, -0.1106, -0.1791,
-0.154, 0.1666, -0.0767, -0.3145, -0.1784, 0.2428, -0.0614, 0.0611,
-0.0804, 0.1366), atx = c(296.910157, 22.96997, 22.719932, -18.090049,
-304.469971, 128.03003, 49.19999, -311.47001, -114.390014, 183.710083,
-267.380059, 56.169976, 818.880004, 115.449952, 65.060068, -405.610117,
-262.829834, 355.199951, -138.44, 141.720029, -538.630127, -402.029907,
54.210005, 1016.93001, 1175.389892, -177.23999, 747.070088, 14.319805,
341.959961, -223.759766, -182.03, -595.19998, -122.550049, 394.110107,
-472.800078, -209.580049, -407.540039, -417.01001, -201.519902,
-388.510005, -53.469971, -122.640014, -321.61001, -193.259985,
-46.180054, -142.599976, -13.059985, -79.840039, 172.859985,
46.090054, -148.8, -56.290054, 122.75, -20.279907, -113.240039,
87.860034, -31.580078), un.employ = c(-0.0946, 0.0285, -0.1297,
-0.0563, -0.2938, 0.2474, -0.386, 0.1812, -0.2538, -0.4493, 0.4135,
-0.7771, 0.4232, 0.2375, -0.2525, 0.3409, 0.1633, -0.0739, 0.4948,
0.3698, -0.4075, -0.7342, -0.2505, -0.3096, -0.3006, 0.3804,
0.3246, 0.4871, 0.1521, -0.3552, 0.22, 0.0585, 0.2905, 0.1454,
0.2726, 0.0472, -0.0215, -0.6432, 0.4422, 0.0229, -0.0864, -0.35,
-0.7569, -0.2062, 0.0867, -0.1833, -0.2003, -0.0546, -0.1151,
0.3641, -0.3421, -0.1825, -0.023, -0.2115, -0.0344, 0.0293, -0.0332
), carReg = c(0.73435946, 0.24001161, 16.90532537, -14.60281976,
6.47603166, -8.35815849, 3.55576685, 7.10705794, -4.6955223,
10.9623709, 5.5801857, -6.4499936, -9.46196502, 9.36289122, -8.52630424,
5.45070994, -4.5346405, -2.26716538, 2.56870398, 0.013737, 5.7750101,
-27.1060826, 1.08977179, 4.94934712, 17.55391859, -13.91160577,
10.38981128, -11.81349246, -0.0831467, 2.79748237, 1.84865463,
-1.98736934, -6.24191695, 13.33602659, -3.86527871, 0.78720993,
4.73360651, -4.1674034, 9.37426802, -5.90660464, -0.4915792,
-5.84811629, 9.67648643, -6.96872719, -7.6535767, 0.24847595,
0.18685263, -2.28766949, 1.1544631, -3.87636933, -2.4731545,
4.33876671, 1.08836339, 5.64525271, 1.90743854, -3.94709355,
-0.84611324), cpi = c(1.16, -3.26, 0.22, -3.51, 0.84, -2.81,
-0.34, -4.57, -0.12, -3.95, -1.37, -2.73, 0.35, -5.38, -4.43,
-3.08, 0.74, -3.03, -1.09, -2, 0.35, -1.52, 1.28, 0.2, -0.25,
-4.55, -2.49, -4.24, -0.31, -2.96, -2.24, -0.46, -0.06, -2.67,
-1.27, -1.4, -0.7, -0.96, -2.18, -2.53, -0.52, -1.74, -2.18,
-1.4, -0.34, -0.09, -1.65, -1.15, -0.17, -2.01, -1.38, -1.24,
0.09, -2.44, -1.92, -2.61, -0.34), prodPrice = c(0.3, 0.8, 1.4,
0.5, 0, 2.3, 1, -0.1, 0.1, -0.4, -1.1, -0.4, -0.1, -3.9, -4.5,
-1.74, -3.48, -5.84, -1.92, 0.19, -1.1, 3.56, 3.57, 2.28, -4.11,
-3.01, -3.67, -1.74, -1.63, -2.02, -2.74, -0.73, -1.74, -3.19,
-1.56, -0.64, 1.36, 0.55, -5.38, -2.11, -3.37, -2.02, -1.74,
-0.01, 1.02, 1.73, -1.82, 0.36, 0.18, -0.64, 1.29, 2.1, 0.82,
-0.09, 1.83, -1.83, -2.83), productionConstr = c(0.7000584, 3.900325,
0.4000333, 1.0000834, -4.6003834, -6.50054172, 7.00058342, 3.2002667,
-4.6003834, 1.1000917, 1.3001083, -5.5004584, 2.3001917, -2.2001833,
-3.60030006, 2.70022502, 3.20026664, -2.0001666, 2.340195, 0.8700725,
0.8700725, 0.2900242, -1.740145, 0.6800566, -1.4501208, 9.8508209,
-6.5705476, -1.2501041, 2.8002333, 1.2501042, -1.3501125, -1.0600884,
-4.9304108, -3.28027339, 4.15034589, -4.34036172, 0.87007251,
-9.85082091, 3.81031753, 2.70022502, -3.96033003, -3.86032169,
2.12017668, -1.93016085, -0.3900325, 3.58029836, -12.66105509,
2.03016918, -0.3900325, -2.22018502, -0.0900075, 0.87007251,
-0.78006501, -0.67005584, 7.44062006, -6.48054005, -1.25010417
), constrPriceIndex = c(-0.3, -0.3, -1.42e-14, 0.2, 0.5, -0.7,
0.3, -0.1, 0.3, -0.9, -0.1, 0.8, -0.2, -0.2, -0.3, 0.2, -0.1,
-0.1, -0.16686, 0.41673, -0.08334, 0.16669, 0.25004, -0.33339,
-0.41673, -0.50009, 0.25004, 0.83348, -0.08335, -0.08334, -0.3334,
0.33339, 1e-05, 0.08334, -0.08335, 0.41674, 0.16669, -0.16669,
-0.13514, 0.15617, 1e-05, -0.46855, 0.15619, 0.54662, 0, -0.23426,
0.07808, 0.07809, 0.15618, -0.31236, 0.0781, 0.31235, -0.15618,
-0.23427, 0.07809, 1e-05, -0.0781), constrCostTotal = c(-0.5,
-0.7, -0.1, -0.06667, -0.16667, -0.6, -0.83333, -0.2, -0.33333,
-1, -1.06667, 0.16667, -0.36667, -0.23333, -1.18893, -0.30742,
-0.05589, -1.92836, -1.0061, -0.25153, -0.67073, -0.02795, 0.0559,
1.62094, -1.62094, -2.51526, -2.06809, 0.02795, -0.16769, -1.45325,
-1.14584, -0.41921, -1.64889, -1.87246, -1.03405, -0.67073, 0.11179,
-0.13974, -0.36695, -0.61157, -0.51373, -1.73687, -1.49225, -0.44033,
-0.48926, -0.88067, -0.6605, -0.04893, -0.12231, -0.83175, -0.34248,
0.1957, -0.12231, -0.78282, -0.29355, -0.44034, -0.39141), primConstTot = c(-0.33334,
-0.93333, -0.16667, -0.33333, -0.16667, -0.86666, -0.3, -0.4,
-0.26667, -1.56667, -0.73333, 0.1, -0.23333, -0.26667, -1.5774,
-0.19284, 0.38568, -2.42423, -0.93663, 0.08265, -0.63361, 0.0551,
-0.49587, 2.39668, -1.70798, -3.36085, -2.56196, 0.16529, 0,
-1.84572, -1.3774, -0.49586, -1.70798, -1.90081, -0.55096, -0.77134,
-0.16529, -0.30303, -0.17066, -0.23853, -0.64401, -1.52657, -1.57426,
-0.28623, -0.54861, -1.07336, -0.71558, 0.02385, -0.38164, -1.09721,
0, 0.14311, -0.38164, -1.02566, -0.42934, -0.35779, -0.4532),
baumeisterarbeit = c(-177L, -499L, -88L, -176L, -91L, -460L,
-160L, -213L, -142L, -835L, -391L, 54L, -125L, -143L, -831L,
-102L, 205L, -1291L, -501L, 45L, -338L, 30L, -264L, 1278L,
-911L, -1791L, -1365L, 87L, -9L, -974L, -734L, -264L, -910L,
-1013L, -317L, -382L, -102L, -165L, -89L, -127L, -344L, -812L,
-840L, -151L, -293L, -572L, -381L, 12L, -203L, -584L, -1L,
77L, -204L, -546L, -207L, -205L, -248L), gesamtbaukost = c(-274L,
-384L, -55L, -38L, -90L, -329L, -457L, -110L, -183L, -547L,
-586L, 92L, -202L, -127L, -676L, -168L, -30L, -1057L, -552L,
-138L, -368L, -15L, 32L, 887L, -888L, -1379L, -1134L, 16L,
-92L, -800L, -625L, -261L, -949L, -950L, -559L, -348L, 54L,
-93L, -214L, -336L, -282L, -953L, -816L, -242L, -268L, -483L,
-362L, -27L, -66L, -456L, -189L, 108L, -68L, -429L, -156L,
-235L, -225L), lohn = c(66831L, 66966L, 68594L, 69408L, 69408L,
69408L, 70858L, 71583L, 71583L, 71583L, 73167L, 73959L, 73959L,
73959L, 74575L, 74883L, 74883L, 74883L, 75983L, 76533L, 76533L,
76749L, 78321L, 79107L, 79107L, 79107L, 80423L, 81081L, 81081L,
81081L, 83007L, 83970L, 83970L, 83970L, 85794L, 86706L, 86706L,
86706L, 87566L, 87996L, 87996L, 87978L, 88270L, 88416L, 88416L,
88503L, 90779L, 91917L, 91917L, 91917L, 93727L, 94632L, 94632L,
94632L, 96090L, 96819L, 96819L), resProp.Dwell = c(0.8, -4,
-3.2, 2.7, -1.6, -1, -2.4, -0.4, -0.8, 1, -12.1, 0.2, -5.2,
3.7, -2.7, -1.7, 1.5, 0.7, -7.9, 0.3, 0.3, 1.4, -3.3, -1,
-1.6, 1.5, 0.5, 1.5, -1, -2.2, -3.5, 0.5, 0.5, -0.9, -0.4,
-3.4, 0.9, 0.1, -0.2, -2.8, -0.8, -6.2, 11.3, -4.6, 1, 1.1,
-1.7, 4.1, -5, 2.3, -2.3, 4.6, -6.3, 6.3, -6.9, 0, 2.4),
resProp.Dwell.1 = c(-0.4, -7.5, -1, -2.4, 0, 1.2, 0.7, -4.3,
0, 3.3, -18.3, 11.2, -4.9, 4.9, -0.3, -1.8, 2.7, 0.9, -10.8,
-2.6, 6.1, -0.1, -6.3, 1.2, 0.8, 4.1, -3.5, 4.6, -0.2, -2.7,
-15, 8, -0.1, -0.1, 0.4, -4.9, 0.5, 2.7, -2.5, 1.9, -4.6,
-1, 8.1, -4.5, 0.3, 0.7, 2.2, -0.5, -3.8, 1.8, -4.7, 5.9,
-2, 2.3, -0.4, -1.4, 2.3), resProp.Dwell.2 = c(1.3, -2.5,
-4.2, 5, -2.3, -1.9, -3.7, 1.2, -1.2, 0.1, -9.6, -4.4, -5.4,
3.2, -3.8, -1.5, 0.9, 0.7, -6.7, 1.5, -2.2, 2, -2, -1.8,
-2.7, 0.3, 2.3, 0.1, -1.2, -2.1, 1.5, -2.7, 0.7, -1.3, -0.7,
-2.7, 1, -1, 0.9, -4.9, 0.9, -8.5, 12.7, -4.7, 1.4, 1.2,
-3.4, 6.1, -5.4, 2.4, -1.2, 4, -8.1, 7.9, -9.6, 0.6, 2.4),
resProp.Dwell.3 = c(1.4, -2.5, -5.1, 3.6, -3, -3, -2.6, 1.5,
-1.3, -0.3, -9.2, -6, -6.6, 3, -4.4, -1.2, 1.1, 0.5, -7.1,
1.3, -1.3, 1.7, -1.6, -2.8, -3.5, 0.8, 2.9, 0, -0.3, -2.7,
2.3, -3.3, 1.8, -2, 0.4, -3.8, 1.1, -1.5, 1.3, -5.6, 2.2,
-9.7, 14.3, -5.7, 1.4, 1, -3.6, 7.3, -6.5, 3.1, -2.4, 4.2,
-7.9, 8.3, -10.2, 0.2, 3.6), resProp.Dwell.4 = c(0.9, -2.9,
2.7, 13.7, 3, 5.6, -12, -0.5, -0.2, 2.5, -12, 6.7, 3.1, 4.7,
0.2, -3.6, -0.6, 1.8, -3.6, 2.6, -8.2, 3.8, -4.5, 4.7, 3.4,
-3.4, -1.6, 1.1, -8.5, 2.4, -3.8, 1.4, -7.1, 3.4, -7.5, 4.3,
0.3, 1.9, -1.8, 0.7, -8.5, -0.7, 2.5, 2, 1.4, 2.7, -2.2,
-2, 1.7, -2.2, 6.9, 2.7, -8.8, 4.4, -5.4, 3.8, -5.7), cbre.indu.primeRent = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.05, 0.05, 0, 0.1, 0, 0.1,
0, 0.1, 0.05, 0, 0.05, 0.1, 0.1, 0, -0.25, -0.25, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.09, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0), cbre.office.Capital.Value....m.. = c(-64.516129,
-133.83665, -67.861143, -128.947368, -64.43299, -63.11803,
-122.44898, -178.217822, -57.076296, -114.220445, -169.716206,
-52.197802, -57.142858, 0, -114.285714, -257.142857, -189.189189,
-42.953668, -42.193426, -41.453191, 11.441648, 232.919255,
198.701298, 687.160263, -3.906674, -126.31579, -126.315789,
-126.31579, -126.315789, -126.31579, -126.315789, -52.631579,
0, 0, 0, 0, 0, 0, -200, 0, 0, 0, 0, 0, 0, 0, -160, 0, 93.714286,
0, 0, 0, 0, 0, 0, 0, 0), cbre.office.PrimeRent = c(-0.25,
-0.25, 0, -0.25, 0, 0, -0.25, -0.25, 0, -0.25, -0.5, 0, -0.25,
0, -0.5, -0.5, -0.25, 0, 0, 0, 0.25, 0.5, 0.5, 0, -0.5, -0.5,
-0.5, -0.5, -0.5, -0.5, -0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0.3, 0, 0.41, 0, 0, 0, 0, 0, 0, 0, 0),
cbre.office.primeYield = c(0, 0, 0.15, 0.15, 0.2, 0.2, 0.2,
0.25, 0.25, 0.25, 0.25, 0.2, 0.15, 0.1, 0.05, 0.15, 0.3,
0.35, 0.4, 0.3, 0.2, 0, -0.15, -0.85, -1, -0.85, -0.75, -0.1,
0, 0, 0, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0.2, 0.2, 0.2,
0.2, 0, 0, 0, 0, 0.25, 0.25, 0.25, 0.25, 0, 0, 0, 0, 0, 0,
0), cbre.retail.primeRent = c(0, 0, -5, -5, -2, -3, -4, -4,
-2, -1, 0, 0, -1, -1, -1, -3, -5, -5, -5, -5.5, -5, -5, -5,
-7.5, -8, -11, -13, -10, -9, -6, -4, -2, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, -0.33, -0.33, -0.33, -0.33, 0, 0,
0, 0, -7.26, -7.26, -7.26), cbre.retail.primeYield = c(5.25,
5.2, 5.25, 5.3, 5.35, 5.4, 5.4, 5.4, 5.45, 5.5, 5.5, 5.6,
5.65, 5.7, 5.85, 5.95, 6, 6.1, 6.2, 6.25, 6.25, 6, 5.75,
5.25, 5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.75, 4.8, 4.8, 5,
5, 5, 5, 5, 5, 5.25, 5.25, 5.75, 5.75, 5.75, 5.75, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6), cbre.retail.capitalValue = c(-1882.35294,
230.76923, -230.76923, -226.41509, -670.78117, -436.13707,
-222.22223, 0, -205.91233, -202.16847, 0, -393.5065, -403.91909,
-186.30647, -539.81107, -748.11463, -764.70588, -311.47541,
-301.42782, -627.09677, -480, 720, 782.6087, 645.96273, 251.42857,
1386.66667, -533.33334, -533.33333, -533.33333, 0, 0, -1024.56141,
-192.10526, 0, -730, 0, 0, 0, 0, 0, -834.28571, 0, -1450.93168,
0, 0, 0, -700.78261, 0, 0, 0, 0, 0, 0, 0, -1452, 0, 0)), .Names = c("oenb_dependent",
"gdp", "employ", "atx", "un.employ", "carReg", "cpi", "prodPrice",
"productionConstr", "constrPriceIndex", "constrCostTotal", "primConstTot",
"baumeisterarbeit", "gesamtbaukost", "lohn", "resProp.Dwell",
"resProp.Dwell.1", "resProp.Dwell.2", "resProp.Dwell.3", "resProp.Dwell.4",
"cbre.indu.primeRent", "cbre.office.Capital.Value....m..", "cbre.office.PrimeRent",
"cbre.office.primeYield", "cbre.retail.primeRent", "cbre.retail.primeYield",
"cbre.retail.capitalValue"), row.names = c(NA, -57L), class = "data.frame")
> leaps=regsubsets(datSel$oenb_dependent~.,
+ data=datSel, nbest=10)
> plot(leaps, scale="adjr2")
As you can see the text on the y-axis cannot be read. Any suggestions, how to change my plot that the numbers can be read?
I appreciate your replies!
The problem is in the leaps:::plot.regsubsets function that gets called when you plot the regsubsets object.
Line 30 is:
axis(2, at = 1:nmodels, labels = signif(yscale[index], 2))
Aside from modifying the source of the package there is not much to do.
A quick way is to use
fixInNamespace(plot.regsubsets, ns = "leaps")
And edit the function, for instance changing the line above to:
num.labs <- 10
at <- seq(1, nmodels, length.out = num.labs)
lab <- signif(yscale[index], 2)
lab <- lab[seq(1, length(lab), length.out = num.labs)]
axis(2, at = at, labels = lab)
I have the following data:
> dput(data)
structure(list(Date_Quandl = c("31.12.2000", "31.03.2001", "30.06.2001",
"30.09.2001", "31.12.2001", "31.03.2002", "30.06.2002", "30.09.2002",
"31.12.2002", "31.03.2003", "30.06.2003", "30.09.2003", "31.12.2003",
"31.03.2004", "30.06.2004", "30.09.2004", "31.12.2004", "31.03.2005",
"30.06.2005", "30.09.2005", "31.12.2005", "31.03.2006", "30.06.2006",
"30.09.2006", "31.12.2006", "31.03.2007", "30.06.2007", "30.09.2007",
"31.12.2007", "31.03.2008", "30.06.2008", "30.09.2008", "31.12.2008",
"31.03.2009", "30.06.2009", "30.09.2009", "31.12.2009", "31.03.2010",
"30.06.2010", "30.09.2010", "31.12.2010", "31.03.2011", "30.06.2011",
"30.09.2011", "31.12.2011", "31.03.2012", "30.06.2012", "30.09.2012",
"31.12.2012", "31.03.2013", "30.06.2013", "30.09.2013", "31.12.2013",
"31.03.2014", "30.06.2014", "30.09.2014", "31.12.2014"), Date_Quartal = c("Q4-2000",
"Q1-2001", "Q2-2001", "Q3-2001", "Q4-2001", "Q1-2002", "Q2-2002",
"Q3-2002", "Q4-2002", "Q1-2003", "Q2-2003", "Q3-2003", "Q4-2003",
"Q1-2004", "Q2-2004", "Q3-2004", "Q4-2004", "Q1-2005", "Q2-2005",
"Q3-2005", "Q4-2005", "Q1-2006", "Q2-2006", "Q3-2006", "Q4-2006",
"Q1-2007", "Q2-2007", "Q3-2007", "Q4-2007", "Q1-2008", "Q2-2008",
"Q3-2008", "Q4-2008", "Q1-2009", "Q2-2009", "Q3-2009", "Q4-2009",
"Q1-2010", "Q2-2010", "Q3-2010", "Q4-2010", "Q1-2011", "Q2-2011",
"Q3-2011", "Q4-2011", "Q1-2012", "Q2-2012", "Q3-2012", "Q4-2012",
"Q1-2013", "Q2-2013", "Q3-2013", "Q4-2013", "Q1-2014", "Q2-2014",
"Q3-2014", "Q4-2014"), oenb_dependent = c(1.0227039, -5.0683144,
0.6657713, 3.3161374, -2.1586704, -0.7833623, -0.2203209, 2.416144,
-1.7625406, -0.1565037, -7.9803936, 9.4594715, -4.8104584, 8.4827107,
-6.1895262, 1.4288595, 1.4896459, -0.4198522, -5.1583964, 5.2502294,
1.0567102, -1.0923342, -1.5852298, 0.6061936, -0.3752335, 2.5008664,
-1.3999729, 2.2802166, -2.1468756, -1.4890328, -0.79254376, 3.21804705,
-0.94407886, -0.27802316, -0.20753079, -1.12610048, 2.0883735,
-0.7424854, 0.44203729, -1.48905938, 1.39644424, -3.8917377,
11.25665848, -9.22884035, 3.26856762, -0.00179541, -2.39664325,
4.00455574, -5.60891295, 4.6556348, -4.40536951, 6.64234497,
-7.34787319, 7.56303006, -8.23083674, 4.43247855, 1.31090412),
carReg = c(0.73435946, 0.24001161, 16.90532537, -14.60281976,
6.47603166, -8.35815849, 3.55576685, 7.10705794, -4.6955223,
10.9623709, 5.5801857, -6.4499936, -9.46196502, 9.36289122,
-8.52630424, 5.45070994, -4.5346405, -2.26716538, 2.56870398,
0.013737, 5.7750101, -27.1060826, 1.08977179, 4.94934712,
17.55391859, -13.91160577, 10.38981128, -11.81349246, -0.0831467,
2.79748237, 1.84865463, -1.98736934, -6.24191695, 13.33602659,
-3.86527871, 0.78720993, 4.73360651, -4.1674034, 9.37426802,
-5.90660464, -0.4915792, -5.84811629, 9.67648643, -6.96872719,
-7.6535767, 0.24847595, 0.18685263, -2.28766949, 1.1544631,
-3.87636933, -2.4731545, 4.33876671, 1.08836339, 5.64525271,
1.90743854, -3.94709355, -0.84611324), cpi = c(1.16, -3.26,
0.22, -3.51, 0.84, -2.81, -0.34, -4.57, -0.12, -3.95, -1.37,
-2.73, 0.35, -5.38, -4.43, -3.08, 0.74, -3.03, -1.09, -2,
0.35, -1.52, 1.28, 0.2, -0.25, -4.55, -2.49, -4.24, -0.31,
-2.96, -2.24, -0.46, -0.06, -2.67, -1.27, -1.4, -0.7, -0.96,
-2.18, -2.53, -0.52, -1.74, -2.18, -1.4, -0.34, -0.09, -1.65,
-1.15, -0.17, -2.01, -1.38, -1.24, 0.09, -2.44, -1.92, -2.61,
-0.34), primConstTot = c(-0.33334, -0.93333, -0.16667, -0.33333,
-0.16667, -0.86666, -0.3, -0.4, -0.26667, -1.56667, -0.73333,
0.1, -0.23333, -0.26667, -1.5774, -0.19284, 0.38568, -2.42423,
-0.93663, 0.08265, -0.63361, 0.0551, -0.49587, 2.39668, -1.70798,
-3.36085, -2.56196, 0.16529, 0, -1.84572, -1.3774, -0.49586,
-1.70798, -1.90081, -0.55096, -0.77134, -0.16529, -0.30303,
-0.17066, -0.23853, -0.64401, -1.52657, -1.57426, -0.28623,
-0.54861, -1.07336, -0.71558, 0.02385, -0.38164, -1.09721,
0, 0.14311, -0.38164, -1.02566, -0.42934, -0.35779, -0.4532
), resProp.Dwell = c(0.8, -4, -3.2, 2.7, -1.6, -1, -2.4,
-0.4, -0.8, 1, -12.1, 0.2, -5.2, 3.7, -2.7, -1.7, 1.5, 0.7,
-7.9, 0.3, 0.3, 1.4, -3.3, -1, -1.6, 1.5, 0.5, 1.5, -1, -2.2,
-3.5, 0.5, 0.5, -0.9, -0.4, -3.4, 0.9, 0.1, -0.2, -2.8, -0.8,
-6.2, 11.3, -4.6, 1, 1.1, -1.7, 4.1, -5, 2.3, -2.3, 4.6,
-6.3, 6.3, -6.9, 0, 2.4), cbre.office.primeYield = c(0, 0,
0.15, 0.15, 0.2, 0.2, 0.2, 0.25, 0.25, 0.25, 0.25, 0.2, 0.15,
0.1, 0.05, 0.15, 0.3, 0.35, 0.4, 0.3, 0.2, 0, -0.15, -0.85,
-1, -0.85, -0.75, -0.1, 0, 0, 0, 0.05, 0.05, 0.05, 0.05,
0, 0, 0, 0.2, 0.2, 0.2, 0.2, 0, 0, 0, 0, 0.25, 0.25, 0.25,
0.25, 0, 0, 0, 0, 0, 0, 0), cbre.retail.capitalValue = c(-1882.35294,
230.76923, -230.76923, -226.41509, -670.78117, -436.13707,
-222.22223, 0, -205.91233, -202.16847, 0, -393.5065, -403.91909,
-186.30647, -539.81107, -748.11463, -764.70588, -311.47541,
-301.42782, -627.09677, -480, 720, 782.6087, 645.96273, 251.42857,
1386.66667, -533.33334, -533.33333, -533.33333, 0, 0, -1024.56141,
-192.10526, 0, -730, 0, 0, 0, 0, 0, -834.28571, 0, -1450.93168,
0, 0, 0, -700.78261, 0, 0, 0, 0, 0, 0, 0, -1452, 0, 0)), .Names = c("Date_Quandl",
"Date_Quartal", "oenb_dependent", "carReg", "cpi", "primConstTot",
"resProp.Dwell", "cbre.office.primeYield", "cbre.retail.capitalValue"
), row.names = c(NA, -57L), class = c("data.table", "data.frame"
), .internal.selfref = <pointer: 0x0000000000200788>)
> plot(data$oenb_dependent, type="l" )
I want to plot my time so that I also get on the x-axis the responsible date of the data point from column data$Date_Quandl.
Any suggestions how to get this?
I appreciate your replies!
One option would be to convert to an xts object and then plot
library(xts)
xt1 <- xts(data$oenb_dependent, order.by= as.Date(data$Date_Quandl, '%d.%m.%Y'))
plot(xt1, main='Plot of oenb_dependent')
We could also change the 'Date' format in the x-axis using major.format
plot(xt1, main='Plot of oenb_dependent', major.format='%b-%d-%Y')