rggplot2ggfortify

Why is ggfortify failing with this 2 time series plot?


I am having trouble with a single plot of 2 time series using the GGfortify package.

I run into a problem on the last line. Is there a correction that can be made?

library(Ecdat)
inflation <- as.numeric(Mishkin[, 1])

data_ts <- ts(inflation,start=c(1950,2), frequency = 12)

AR_data <- arima(data_ts, order = c(1,0,0))

AR_data_fitted <- data_ts - residuals(AR_data)

combined <- cbind(data_ts,AR_data_fitted)

gg <- autoplot(combined, columns = c(1,2),cmain = "Inflation Data")

Solution

  • Use the following code

    library(ggfortify)
    
    combined <- cbind(data_ts,AR_data_fitted)
    
    colnames(combined) <- c("Original Data", "AR fitted data")
    
    autoplot(combined,main = "Inflation Data",facets = FALSE)
    

    enter image description here

    Update

    autoplot(combined,main = "Inflation Data",facets = FALSE)+
      scale_color_manual(values=c("blue", "black"))
    

    enter image description here