I am creating a ts object and then I am trying to run it through autoplot. Execution gives me an error:
autoplot(pts, facets = TRUE) Error: Objects of type mts/ts/matrix not supported by autoplot.
I have already checked the type of the object , and it is ts and autoplot is supposed to make a plot out of the ts object. I also tried to run other built in ts object (USAccDeaths) , but it gives me same error
library(ggplot2)
pts <- ts(data = Popcopys[,-1], start = c(2006,1),frequency = 1 )
autoplot(pts) autoplot(USAccDeaths)
A plot of TS is expected , but what I get is this error:
autoplot(pts) Error: Objects of type mts/ts/matrix not supported by autoplot. autoplot(USAccDeaths) Error: Objects of type ts not supported by autoplot.
The single function in the ggfortify package, which is of interest to us is the autoplot() function, which is helpful to plot time series objects (i.e a ts object) the ggplot way.
To add an arbitrary title and/or subtitle to a plot, use either function ggtitle() or function labs() from package 'ggplot2'. For example "title:objt" , the default for "title" , adds a title with the name of the object being plotted.
This works:
library(ggplot2)
library(ggfortify)
autoplot(USAccDeaths)
Following https://cran.r-project.org/web/packages/ggfortify/vignettes/plot_ts.html :
"{ggfortify} lets {ggplot2} know how to interpret ts objects"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With