Skip to content

Commit 882584f

Browse files
authored
geom_text() drops rows with angle = NA (#5162)
* Declare `angle` as non-missing * Add NEWS bullet * Add test * Bump cache-version in R CMD check
1 parent 15cb2fb commit 882584f

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959

6060
- uses: r-lib/actions/setup-r-dependencies@v2
6161
with:
62-
cache-version: 2
62+
cache-version: 3
6363
extra-packages: >
6464
any::rcmdcheck,
6565
Hmisc=?ignore-before-r=3.6.0,

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* `geom_text()` drops observations where `angle = NA` instead of throwing an
4+
error (@teunbrand, #2757).
35
* Using two ordered factors as facetting variables in
46
`facet_grid(..., as.table = FALSE)` now throws a warning instead of an
57
error (@teunbrand, #5109).

R/geom-text.r

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ geom_text <- function(mapping = NULL, data = NULL,
198198
GeomText <- ggproto("GeomText", Geom,
199199
required_aes = c("x", "y", "label"),
200200

201+
non_missing_aes = "angle",
202+
201203
default_aes = aes(
202204
colour = "black", size = 3.88, angle = 0, hjust = 0.5,
203205
vjust = 0.5, alpha = NA, family = "", fontface = 1, lineheight = 1.2

tests/testthat/test-geom-text.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ test_that("geom_text() checks input", {
22
expect_snapshot_error(geom_text(position = "jitter", nudge_x = 0.5))
33
})
44

5+
test_that("geom_text() drops missing angles", {
6+
7+
df <- data_frame0(x = 1, y = 1, label = "A", angle = 0)
8+
geom <- geom_text()
9+
10+
expect_silent(
11+
geom$geom$handle_na(df, geom$geom_params)
12+
)
13+
14+
df$angle <- NA
15+
expect_warning(
16+
geom$geom$handle_na(df, geom$geom_params),
17+
"Removed 1 row"
18+
)
19+
})
20+
521
# compute_just ------------------------------------------------------------
622

723
test_that("vertical and horizontal positions are equivalent", {

0 commit comments

Comments
 (0)