How to increase line width for the horizontal blue dashed lines in ACF plot

Hello,

I would like to increase the line width in ACF plot. For example, in this plot:

library(fpp2)
beer2 <- window(ausbeer, start=1992)
ggAcf(beer2,lwd=1.5)

Modify the code to increase not only the line width for the vertical lines, but also for the horizontal blue dashed lines in the plot. Does anyone know how to increase the line width of the dashed blue lines? What should I modify in the code above?

Thank you in advance.

Cheers,

Francesc

ggAcf take an ellipses argument, \dots, meant to pass

Other plotting parameters to affect the plot

I wasn't able to find much in the way of documentation. With some experimentation, though, it's not meant to be very fine grained.

The good news is that ggAcf produces a ggplot object. That is also the disappointing news. I suspect it is possible to edit a ggplot object directly, I haven't attempted it, in favor of the crude overplotting for the blue bands shown below.

library(fpp2)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
#> ── Attaching packages ────────────────────────────────────────────── fpp2 2.4 ──
#> ✓ ggplot2   3.3.3     ✓ fma       2.4  
#> ✓ forecast  8.14      ✓ expsmooth 2.3
#> 
beer2 <- window(ausbeer, start=1992)
ggAcf(beer2, size = 2, color = "orange") + 
  geom_hline(yintercept = 0.24, size = 2, color = "blue", linetype = "3313") +
  geom_hline(yintercept = -0.24, size = 2, color = "blue", linetype = "3313") +
  theme_minimal()

Here is a simple solution by changing the default line widths. You will need to change them back again or all subsequent plots will be affected. The same solution will work if you are using the feasts package instead of the forecast package.

library(fpp2)
#> ── Attaching packages ────────────────────────────────────────────── fpp2 2.4 ──
#> ✓ ggplot2   3.3.3     ✓ fma       2.4  
#> ✓ forecast  8.14      ✓ expsmooth 2.4
#> 
beer2 <- window(ausbeer, start=1992)
update_geom_defaults("line", list(size = 1.5))
update_geom_defaults("hline", list(size = 1.5))
update_geom_defaults("segment", list(size = 1.5))
ggAcf(beer2)

Created on 2021-05-19 by the reprex package (v2.0.0)

2 Likes

Thanks for update_geom_defaults, an invaluable tip.

1 Like

Thank you so much for this tip @robjhyndman!

I need to make sure that I am using the default parameters when I need to create a regular plot. It seems that a value of 0.5 is similar to a regular plot.

Is this code correct to change back to the default value of the parameters to create a regular ACF plot?

library(fpp2)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
#> -- Attaching packages ---------------------------------------------- fpp2 2.4 --
#> v ggplot2   3.3.3     v fma       2.4  
#> v forecast  8.14      v expsmooth 2.3
#> 
beer2 <- window(ausbeer, start=1992)
update_geom_defaults("line", list(size = 1.5))
update_geom_defaults("hline", list(size = 1.5))
update_geom_defaults("segment", list(size = 1.5))
ggAcf(beer2)

update_geom_defaults("line", list(size = 0.5))
update_geom_defaults("hline", list(size = 0.5))
update_geom_defaults("segment", list(size = 0.5))
ggAcf(beer2)

Created on 2021-05-19 by the reprex package (v2.0.0)

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.