Skip to content

Commit

Permalink
Merge pull request #1511 from rstudio/nanoplots-constant-zero
Browse files Browse the repository at this point in the history
Handle special nanoplot case where all `y` values are zero
  • Loading branch information
rich-iannone authored Dec 18, 2023
2 parents 418a1d7 + aba583d commit 5db482e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion R/utils_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,16 @@ generate_nanoplot <- function(
y_scale_max <- get_extreme_value(y_vals, stat = "max")
y_scale_min <- get_extreme_value(y_vals, stat = "min")

# Handle cases where collection of `y_vals` is invariant
if (y_scale_min == y_scale_max && is.null(expand_y)) {

if (y_scale_min == 0) {
expand_y_dist <- 5
} else {
expand_y_dist <- (y_scale_min / 10) * 2
}

# Expand the `y` scale, centering around the `y_scale_min` value
expand_y_dist <- (y_scale_min / 10) * 2
expand_y <- c(y_scale_min - expand_y_dist, y_scale_min + expand_y_dist)
}

Expand Down

1 comment on commit 5db482e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.