Skip to content

Commit 2c5e800

Browse files
authored
merge pr #529: address warnings when shading zero area
2 parents e6212f3 + 18fdf9e commit 2c5e800

32 files changed

+203
-3567
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
* The aliases `p_value()` and `conf_int()`, first deprecated 6 years ago, now
44
return an error (#530).
5+
6+
* Addresses ggplot2 warnings when shading p-values for test statistics
7+
that are outside of the range of the generated distribution (#528).
58

69
# infer v1.0.6
710

R/shade_p_value.R

+8
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ shade_p_value_term <- function(plot, obs_stat, direction,
180180
segment_args <- c_dedupl(
181181
# Not overwritable arguments
182182
list(
183+
# Address length-1 aesthetics warning by providing geom-specific data (#528)
184+
data = data.frame(obs_stat = obs_stat),
183185
# Here `aes()` is needed to force {ggplot2} to include segment in the plot
184186
mapping = aes(x = obs_stat, xend = obs_stat, y = 0, yend = Inf),
185187
color = color,
@@ -346,6 +348,12 @@ hist_area <- function(data, obs_stat, direction, yval) {
346348
right = c(obs_stat, x_extra[x_extra > obs_stat])
347349
)
348350

351+
# if area will have area 0, return 0-length tibble to trigger
352+
# `ggplot:::empty()` edge case (#528)
353+
if (length(x_grid) == 1) {
354+
return(tibble::tibble(x = numeric(0), y = numeric(0), dir = character(0)))
355+
}
356+
349357
tibble::tibble(x = x_grid, y = curve_fun(x_grid), dir = direction)
350358
}
351359

tests/testthat/_snaps/shade_p_value/pval-both-both.svg

-99
Loading

0 commit comments

Comments
 (0)