Coercing csv dataset to tssible for time series regression analysis not supported by autoplot

Dear community members,

I want to conduct analysis on time series dataset in csv. The data covers South Korea's GDP and vehicle kilometers traveled (VKT) from 1993 through 2017. I'm also referring to 'Forecasting: Principles and Practice' book by Professor Rob J Hyndman.

Whenever i try to explore my time series dataset with a slew of variables, and choose auto plot, i get this error:

Error: Objects of type tbl_df/tbl/data.frame not supported by autoplot.

The structure of my data set is as follows:

Year       Passenger VKT      GDP per capita     TotalVKT       PVKTpct       TVKTpct 
1993         2507              8740              225867          -3            1  
1994         2893              10204             251671          16           11
.............................................................................................. ................................................
2017          6542            29744              474674           -2          -1

My code is also structured as follows:

Should i declare both key and index? But still it seems i can't identify my key if any.

library(fpp2)
library(tidyverse)
library(GGally)
library(tsibble)
library(dplyr)

#Attaching the dataset 

koreatreg <- read_csv("timeseriesregression.csv")

#deletion of missing values

newkoreatreg <- na.omit(koreatreg)

#coerce a data frame to tssible by declaring the index 

transkorreg <- as_tibble(newkoreatreg, index = Year)

#explore time series dataset 

autoplot(transkorreg[,c('Passenger VKT','GDP per capita')]) +
  ylab("% change") + xlab("Year")

I would greatly appreciate any timely reply!

1 Like
  • Your data do not appear to have any keys.
  • To use autoplot() with tsibbles, load the feasts package.
  • You don't need fpp2 here and it will cause clashes with some functions.

Something like the following should work

library(tidyverse)
library(tsibble)
library(feasts)

koreatreg <- read_csv("timeseriesregression.csv") %>%
  as_tsibble(index = Year)

koreatreg %>%
  autoplot(`Passenger VKT`) + 
  ylab("% change") + xlab("Year")

If you want to plot both series on the same plot, then you can't use autoplot.

1 Like

I'm so lucky!

Thank you very much esteemed Professor Rob J Hyndman!
In case i face hurdles along the way, i earnestly hope, you'll give me timely reply.

You are receiving this error because you have converted your series to a tibble using as_tibble() and not a tsibble (or time series) using as_tsibble().

The error suggests that you have a tibble (and not a tsibble) because:

Error: Objects of type tbl_df/tbl/data.frame not supported by autoplot.

A tbl_df object is a tibble.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.