Skip to content

Commit

Permalink
Add a legend for add_fan()
Browse files Browse the repository at this point in the history
  • Loading branch information
ThierryO committed Oct 25, 2023
1 parent fee1b1e commit c0bd21d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions R/add_fan.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' Defaults to `"text"`.
#' When no `"text"` variable is specified, the function displays a formatted
#' confidence interval.
#' @param name Optional name of the trace for the legend.
#' @template example_effect_data
#' @template example_effect_plotly
#' @family plotly add-ons
Expand All @@ -30,7 +31,8 @@
add_fan <- function(
p, x = NULL, y = NULL, ..., sd, link = c("identity", "log", "logit"),
max_prob = 0.9, step = 0.05, fillcolor = coarse_unsigned_palette[2],
data = NULL, inherit = TRUE, text = NULL, hoverinfo = "text"
data = NULL, inherit = TRUE, text = NULL, hoverinfo = "text",
name
) {
assert_that(
is.flag(inherit), noNA(inherit), is.string(fillcolor), noNA(fillcolor),
Expand Down Expand Up @@ -68,7 +70,14 @@ add_fan <- function(
)
p <- do.call(add_ribbons, dots)
}
p
if (missing(name)) {
return(p)
}
p |>
add_ribbons(
data = data, x = x, ymin = y, ymax = y, opacity = 1, showlegend = TRUE,
line = list(width = 0), fillcolor = fillcolor, name = name
)
}

coalesce <- function(x, y) {
Expand Down
5 changes: 4 additions & 1 deletion man/add_fan.Rd

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

0 comments on commit c0bd21d

Please sign in to comment.