Skip to content

Commit

Permalink
Fix auto[plot/layer] draw key for single-point multiple-forecast ribbons
Browse files Browse the repository at this point in the history
Resolves #414
  • Loading branch information
mitchelloharawild committed Feb 4, 2025
1 parent 3d4c848 commit 3f3ce99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# fabletools (development version)

## Bug fixes

* Fixed forecast autoplot() and autolayer() draw key for single-point
multiple-forecast ribbons (#414).

# fabletools 0.5.0

## New features
Expand Down
13 changes: 13 additions & 0 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ build_fbl_layer <- function(object, data = NULL, level = c(80, 95),
if (is.null(data[["fill"]]) && (!is.null(data[["fill_ramp"]]) || !all(is.na(data[["alpha"]])))) {
data$fill = "gray65"
}
if (is.null(data[["colour"]]) && (!is.null(data[["colour_ramp"]]) || !all(is.na(data[["alpha"]])))) {
data$colour = "black"
}
# Apply ramped fill
if (!is.null(data[["fill_ramp"]])) {
if (utils::packageVersion("ggdist") > "3.3.1") {
Expand All @@ -326,6 +329,16 @@ build_fbl_layer <- function(object, data = NULL, level = c(80, 95),
}, data$fill, data$fill_ramp)
}
}
# Apply ramped colour
if (!is.null(data[["colour_ramp"]])) {
if (utils::packageVersion("ggdist") > "3.3.1") {
data$colour <- get("ramp_colours", asNamespace("ggdist"), mode = "function")(data$colour, data$colour_ramp)
} else {
data$colour <- mapply(function(color, amount){
(scales::seq_gradient_pal(attr(amount, "from") %||% "white", color))(amount %||% NA)
}, data$colour, data$colour_ramp)
}
}
ggplot2::draw_key_rect(data, params, size)
}

Expand Down

0 comments on commit 3f3ce99

Please sign in to comment.