Skip to content

Commit

Permalink
Added gg_irf
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Sep 16, 2024
1 parent 14fd4bd commit e742098
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Imports:
slider,
utils,
lifecycle,
gtable
gtable,
tidyselect
Suggests:
tsibbledata,
pillar (>= 1.0.1),
Expand All @@ -49,7 +50,7 @@ License: GPL-3
URL: http://feasts.tidyverts.org/, https://github.com/tidyverts/feasts/
BugReports: https://github.com/tidyverts/feasts/issues
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE, roclets=c('rd', 'collate', 'namespace'))
Language: en-GB
RdMacros: lifecycle
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export(feat_pacf)
export(feat_spectral)
export(feat_stl)
export(gg_arma)
export(gg_irf)
export(gg_lag)
export(gg_season)
export(gg_subseries)
Expand Down Expand Up @@ -137,6 +138,7 @@ importFrom(stats,ts)
importFrom(stats,var)
importFrom(tibble,tibble)
importFrom(tidyr,gather)
importFrom(tsibble,as_tsibble)
importFrom(utils,tail)
importFrom(vctrs,vec_cast)
importFrom(vctrs,vec_ptype2)
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# feasts (development version)

## New features

* Added `gg_irf()` for plotting impulse responses (typically obtained from using
`IRF()` with fable models).

## Bug fixes

* Fixed `gg_season()` not wrapping across `facet_period` argument correctly.

# feasts 0.3.2
Expand Down
26 changes: 26 additions & 0 deletions R/graphics.R
Original file line number Diff line number Diff line change
Expand Up @@ -805,3 +805,29 @@ gg_arma <- function(data){
ggplot2::coord_fixed(ratio = 1) +
facet_grid(vars(!!!fcts), vars(!!sym("type")))
}



#' Plot impulse response functions
#'
#' Produces a plot of impulse responses from an impulse response function.
#'
#' @param data A tsibble with impulse responses
#' @param y The impulse response variables to plot (defaults to all measured variables).
#'
#' @return A ggplot object of the impulse responses.
#'
#' @export
gg_irf <- function(data, y = all_of(measured_vars(data))){
kv <- key_vars(data)
if(is_empty(kv)) kv <- NULL
data <- tidyr::pivot_longer(
data, {{y}},
names_to = ".variable", values_to = ".response"
)
ggplot(data) +
geom_line(ggplot2::aes_string(x = index_var(data), y = ".response")) +
ggplot2::geom_hline(yintercept = 0, linetype = "dashed") +
facet_grid(vars(!!!syms(kv)), vars(!!sym(".variable"))) +
ggplot2::labs(y = "Impulse response", x = NULL)
}
17 changes: 17 additions & 0 deletions man/gg_irf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e742098

Please sign in to comment.