I am using the forecast package and I tried to make a decomposition plot. Below you can see the code.
library(forecast)
librarary(ggplot2)
stl(AirPassengers,s.window="periodic",robust=TRUE)%>%autoplot()
These lines of code produce a plot with four charts below you can see the plot
Now I want to have this plot but without the first chart (data). So can anybody help me how to solve this problem and make a plot only with three charts (trend, seasonal, and remainder )?
>Solution :
One option would be to manually manipulate the ggplot2 object returned by autoplot, e.g. to get rid of the data panel you could remove the data values from the plot data and the layer data.
As the categories for the facets are stored in a column called parts we have to filter the data to get rid of the parts category "data":
library(forecast)
library(ggplot2)
p <- stl(AirPassengers,s.window="periodic",robust=TRUE) |> autoplot()
# Remove "data" from layer data
p$layers <- lapply(p$layers, function(x) { x$data <- subset(x$data, parts != "data"); x })
# Remove "data" from plot data
p$data <- subset(p$data, parts != "data")
p

