Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address warnings when shading zero area #529

Merged
merged 8 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

* The aliases `p_value()` and `conf_int()`, first deprecated 6 years ago, now
return an error (#530).

* Addresses ggplot2 warnings when shading p-values for test statistics
that are outside of the range of the generated distribution (#528).

# infer v1.0.6

Expand Down
8 changes: 8 additions & 0 deletions R/shade_p_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ shade_p_value_term <- function(plot, obs_stat, direction,
segment_args <- c_dedupl(
# Not overwritable arguments
list(
# Address length-1 aesthetics warning by providing geom-specific data (#528)
data = data.frame(obs_stat = obs_stat),
# Here `aes()` is needed to force {ggplot2} to include segment in the plot
mapping = aes(x = obs_stat, xend = obs_stat, y = 0, yend = Inf),
color = color,
Expand Down Expand Up @@ -346,6 +348,12 @@ hist_area <- function(data, obs_stat, direction, yval) {
right = c(obs_stat, x_extra[x_extra > obs_stat])
)

# if area will have area 0, return 0-length tibble to trigger
# `ggplot:::empty()` edge case (#528)
if (length(x_grid) == 1) {
return(tibble::tibble(x = numeric(0), y = numeric(0), dir = character(0)))
}

tibble::tibble(x = x_grid, y = curve_fun(x_grid), dir = direction)
}

Expand Down
99 changes: 0 additions & 99 deletions tests/testthat/_snaps/shade_p_value/pval-both-both.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading