Reputation: 1
I'm having problems changing the data facet label in the stl plot, I was able to do it whit the classic decomposition but the stl decomposition works different. I'm not English spoken, so, I need to put the label in Spanish but is like imposible, also, I'm not pretty good programming because I don't know how to do it, so, I really need help here. Below it is my code, I was able to change the another facet labels but not the data one (just add the label in the "labels" function it doesn't worked, just allows the "seasonal, trend and random" labels). Also, I need to change the strips position to the top.
d_stl <- stl(ts_prom_mensual, s.window = "periodic", robust = TRUE)
autoplot(d_stl, labels = c("Estacionalidad", "Tendencia", "Aleatoreidad"))+
ggtitle("Descomposición stl de serie temporal de los datos generados por el\n mareografo ubicado en la zona de ______ con regularidad mensual\n durante el periodo coomprendido entre ____ y ________")+
theme_bw()+
theme(title = element_text(family = 'serif', size = 12, face = 'bold', hjust = 0.5, vjust = 0.5),
axis.text = element_text(family = 'serif', size = 10),
axis.title.x = element_text(face = "plain", size = 12),
axis.title.y = element_text(face = "plain", size = 12),
strip.background = element_rect(fill = 'white'),
strip.text = element_text(family = 'serif')
)+
labs(x="Año", y= "Componentes")+
geom_line(colour = "seagreen")
I just need to change the data facet name to "Observaciones" and change the strips position to the top.
Upvotes: 0
Views: 228
Reputation: 124183
You can overwrite the default facet layer used by autoplot.stl
, e.g. use a facet_wrap
with ncol=1
which will automatically put the strip text at the top and for you labels use a custom labeller()
.
Using a minimal reproducible example based on the default example from ?stl
:
library(ggplot2)
library(forecast)
#> Registered S3 method overwritten by 'quantmod':
#> method from
#> as.zoo.data.frame zoo
d_stl <- stl(nottem, s.window = "periodic", robust = TRUE)
autoplot(
d_stl
) +
ggtitle(paste0(
"Descomposición stl de serie temporal de",
" los datos generados por el\n",
" mareografo ubicado en la zona de ______ ",
"con regularidad mensual\n ",
"durante el periodo coomprendido entre ____ y ________"
)) +
theme_bw() +
theme(
title = element_text(
family = "serif", size = 12,
face = "bold", hjust = 0.5, vjust = 0.5
),
axis.text = element_text(family = "serif", size = 10),
axis.title.x = element_text(face = "plain", size = 12),
axis.title.y = element_text(face = "plain", size = 12),
strip.background = element_rect(fill = "white"),
strip.text = element_text(family = "serif")
) +
labs(x = "Año", y = "Componentes") +
geom_line(colour = "seagreen") +
facet_wrap(~parts,
labeller = labeller(
parts = c(
data = "Observaciones",
trend = "Estacionalidad",
seasonal = "Tendencia",
remainder = "Aleatoreidad"
)
),
ncol = 1,
scales = "free_y"
)
Upvotes: 1