Skip to content

Commit 3f3ce99

Browse files
Fix auto[plot/layer] draw key for single-point multiple-forecast ribbons
Resolves #414
1 parent 3d4c848 commit 3f3ce99

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# fabletools (development version)
22

3+
## Bug fixes
4+
5+
* Fixed forecast autoplot() and autolayer() draw key for single-point
6+
multiple-forecast ribbons (#414).
7+
38
# fabletools 0.5.0
49

510
## New features

R/plot.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ build_fbl_layer <- function(object, data = NULL, level = c(80, 95),
316316
if (is.null(data[["fill"]]) && (!is.null(data[["fill_ramp"]]) || !all(is.na(data[["alpha"]])))) {
317317
data$fill = "gray65"
318318
}
319+
if (is.null(data[["colour"]]) && (!is.null(data[["colour_ramp"]]) || !all(is.na(data[["alpha"]])))) {
320+
data$colour = "black"
321+
}
319322
# Apply ramped fill
320323
if (!is.null(data[["fill_ramp"]])) {
321324
if (utils::packageVersion("ggdist") > "3.3.1") {
@@ -326,6 +329,16 @@ build_fbl_layer <- function(object, data = NULL, level = c(80, 95),
326329
}, data$fill, data$fill_ramp)
327330
}
328331
}
332+
# Apply ramped colour
333+
if (!is.null(data[["colour_ramp"]])) {
334+
if (utils::packageVersion("ggdist") > "3.3.1") {
335+
data$colour <- get("ramp_colours", asNamespace("ggdist"), mode = "function")(data$colour, data$colour_ramp)
336+
} else {
337+
data$colour <- mapply(function(color, amount){
338+
(scales::seq_gradient_pal(attr(amount, "from") %||% "white", color))(amount %||% NA)
339+
}, data$colour, data$colour_ramp)
340+
}
341+
}
329342
ggplot2::draw_key_rect(data, params, size)
330343
}
331344

0 commit comments

Comments
 (0)