0

I'm posting this because i've been having a little problem with my code. What i want to do is to make a forecast of COVID cases in a province for the next 30 days using the AUTOARIMA script. Everything is ok, but when i plot the forecast model, the date labels appears in increments of 25% (IE: 2020.2, 2020.4, etc), but i want to label that axis with a YMD format. This is my code:

library(readxl)
library(ggplot2)
library(forecast)
data <- read_xlsx("C:/Users/XXXX/Documents/Casos ARIMA Ejemplo.xlsx")
provincia_1 <- ts(data$Provincia_1, frequency = 365, start = c(2020,64))
autoarima_provincia1 <- auto.arima(provincia_1)
forecast_provincia1 <- forecast(autoarima_provincia1, h = 30)
plot(forecast_provincia1, main = "Proyeccion Provincia 1", xlab = "Meses", ylab = "Casos Diarios")

When i plot the forecast, this is what appears (with the problem i've stated before on the dates label)

The database is here:

https://github.com/pgonzalezp/Casos-Covid-provincias

1 Answers1

0

Try to create a data.frame having on one column your predictions and in the other the daily dates. Then plot it.

Introduce your start and ending date as seen below, then at "by" argument, please check documentation from this link: https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/as.Date

df <- data.frame(
  date=seq(as.Date("1999-01-01"), as.Date("2014-01-10"), by="6 mon"),
  pred_val = forecast_provincia1 
)

with(df, plot(date, pred_val ))

I got inspired from here: R X-axis Date Labels using plot()