Skip to content

Commit 2a5e494

Browse files
karawoohadley
authored andcommitted
Remove missing data in StatBoxplot (#2629)
Fixes #2615. Closes #2616
1 parent f888dd9 commit 2a5e494

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

R/stat-boxplot.r

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ StatBoxplot <- ggproto("StatBoxplot", Stat,
4646
non_missing_aes = "weight",
4747
setup_data = function(data, params) {
4848
data$x <- data$x %||% 0
49+
data <- remove_missing(
50+
data,
51+
na.rm = FALSE,
52+
vars = "x",
53+
name = "stat_boxplot"
54+
)
4955
data
5056
},
5157

tests/testthat/test-stat-boxplot.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
context("stat_boxplot")
2+
3+
test_that("stat_boxplot drops missing rows with a warning", {
4+
5+
p1 <- ggplot(PlantGrowth, aes(x = group, y = weight)) +
6+
geom_boxplot(position = "dodge") +
7+
scale_x_discrete(limits = c("trt1", "ctrl"))
8+
9+
p2 <- ggplot(PlantGrowth, aes(x = group, y = weight)) +
10+
geom_boxplot(position = "dodge2") +
11+
scale_x_discrete(limits = c("trt1", "ctrl"))
12+
13+
expect_warning(
14+
ggplot_build(p1),
15+
"Removed 10 rows containing missing values \\(stat_boxplot\\)\\."
16+
)
17+
expect_warning(
18+
ggplot_build(p2),
19+
"Removed 10 rows containing missing values \\(stat_boxplot\\)\\."
20+
)
21+
22+
})

0 commit comments

Comments
 (0)