change colour of confidence intervals in ggplot

Would anyone know how to change the colour of the confidence interval bands to black in this ggplot (using the ggPacf function)? Code below and output attached

figs1 <- ggPacf(ardl_62_acf) +
  theme_classic() + 
  labs(y = "Partial Autocorrelation Function", title = " ") + 
  scale_y_continuous(breaks = seq(-0.80, 0.80,0.1))

Hey there,

from which package is this function exactly? It is not in ggplot2 as far as I know.

That function is from the forecast package.

Thanks @EconProf

I don't know how to change it in the function, but you can just calculate the confidence interval by yourself and plot it over the ggPacf() call:

library('ggplot2')
library('forecast')
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo

# calculate the confidence interval by hand
# two-sided, alpha = 5%
ci_upper <- qnorm((1 + 0.95)/2)/sqrt(length(wineind))
ci_lower <- -ci_upper

ggPacf(wineind) +
  geom_hline(aes(yintercept = ci_upper), col = 'black', linetype = 'dashed') +
  geom_hline(aes(yintercept = ci_lower), col = 'black', linetype = 'dashed')

Created on 2022-11-12 with reprex v2.0.2

Kind regards

1 Like

A few tweaks:

library('ggplot2')
library('forecast')
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo

ci <- qnorm((1 + 0.95)/2)/sqrt(length(wineind))

ggPacf(wineind) +
  geom_hline(yintercept = c(-ci, ci), col = 'black', linetype = 'dashed')

Created on 2022-11-12 with reprex v2.0.2

2 Likes

Thank you very much for your replies and sorry for not being specific about the package related to the function. This has worked, and makes sense. I thought there might be an argument I am missing in ggplot but it is better to manually compute ci.

I now wonder what inference I can draw about pacf values for an ardl model - especially if out of bounds @EconProf @FactOREO ?

This topic was automatically closed 21 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.