Skip to content

Commit 93d5395

Browse files
committed
remove nudge specific stuff from geom_text()/geom_label()
1 parent c44ad91 commit 93d5395

File tree

10 files changed

+14
-88
lines changed

10 files changed

+14
-88
lines changed

R/geom-label.R

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,16 @@
44
#' @param label.r Radius of rounded corners. Defaults to 0.15 lines.
55
#' @param label.size Size of label border, in mm.
66
geom_label <- function(mapping = NULL, data = NULL,
7-
stat = "identity", position = "identity",
7+
stat = "identity", position = "nudge",
88
...,
99
parse = FALSE,
10-
nudge_x = 0,
11-
nudge_y = 0,
1210
label.padding = unit(0.25, "lines"),
1311
label.r = unit(0.15, "lines"),
1412
label.size = 0.25,
1513
size.unit = "mm",
1614
na.rm = FALSE,
1715
show.legend = NA,
1816
inherit.aes = TRUE) {
19-
if (!missing(nudge_x) || !missing(nudge_y)) {
20-
if (!missing(position)) {
21-
cli::cli_abort(c(
22-
"Both {.arg position} and {.arg nudge_x}/{.arg nudge_y} are supplied.",
23-
"i" = "Choose one approach to alter the position."
24-
))
25-
}
26-
27-
position <- position_nudge(nudge_x, nudge_y)
28-
}
2917

3018
layer(
3119
data = data,

R/geom-sf.R

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,9 @@ geom_sf <- function(mapping = aes(), data = NULL, stat = "sf",
313313
#' @inheritParams geom_label
314314
#' @inheritParams stat_sf_coordinates
315315
geom_sf_label <- function(mapping = aes(), data = NULL,
316-
stat = "sf_coordinates", position = "identity",
316+
stat = "sf_coordinates", position = "nudge",
317317
...,
318318
parse = FALSE,
319-
nudge_x = 0,
320-
nudge_y = 0,
321319
label.padding = unit(0.25, "lines"),
322320
label.r = unit(0.15, "lines"),
323321
label.size = 0.25,
@@ -326,17 +324,6 @@ geom_sf_label <- function(mapping = aes(), data = NULL,
326324
inherit.aes = TRUE,
327325
fun.geometry = NULL) {
328326

329-
if (!missing(nudge_x) || !missing(nudge_y)) {
330-
if (!missing(position)) {
331-
cli::cli_abort(c(
332-
"Both {.arg position} and {.arg nudge_x}/{.arg nudge_y} are supplied.",
333-
"i" = "Only use one approach to alter the position."
334-
))
335-
}
336-
337-
position <- position_nudge(nudge_x, nudge_y)
338-
}
339-
340327
layer_sf(
341328
data = data,
342329
mapping = mapping,
@@ -362,28 +349,15 @@ geom_sf_label <- function(mapping = aes(), data = NULL,
362349
#' @inheritParams geom_text
363350
#' @inheritParams stat_sf_coordinates
364351
geom_sf_text <- function(mapping = aes(), data = NULL,
365-
stat = "sf_coordinates", position = "identity",
352+
stat = "sf_coordinates", position = "nudge",
366353
...,
367354
parse = FALSE,
368-
nudge_x = 0,
369-
nudge_y = 0,
370355
check_overlap = FALSE,
371356
na.rm = FALSE,
372357
show.legend = NA,
373358
inherit.aes = TRUE,
374359
fun.geometry = NULL) {
375360

376-
if (!missing(nudge_x) || !missing(nudge_y)) {
377-
if (!missing(position)) {
378-
cli::cli_abort(c(
379-
"Both {.arg position} and {.arg nudge_x}/{.arg nudge_y} are supplied.",
380-
"i" = "Only use one approach to alter the position."
381-
))
382-
}
383-
384-
position <- position_nudge(nudge_x, nudge_y)
385-
}
386-
387361
layer_sf(
388362
data = data,
389363
mapping = mapping,

R/geom-text.R

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@
4141
#' @inheritParams geom_point
4242
#' @param parse If `TRUE`, the labels will be parsed into expressions and
4343
#' displayed as described in `?plotmath`.
44-
#' @param nudge_x,nudge_y Horizontal and vertical adjustment to nudge labels by.
45-
#' Useful for offsetting text from points, particularly on discrete scales.
46-
#' Cannot be jointly specified with `position`.
47-
#' @param position A position adjustment to use on the data for this layer.
48-
#' Cannot be jointy specified with `nudge_x` or `nudge_y`. This
49-
#' can be used in various ways, including to prevent overplotting and
50-
#' improving the display. The `position` argument accepts the following:
51-
#' * The result of calling a position function, such as `position_jitter()`.
52-
#' * A string naming the position adjustment. To give the position as a
53-
#' string, strip the function name of the `position_` prefix. For example,
54-
#' to use `position_jitter()`, give the position as `"jitter"`.
55-
#' * For more information and other ways to specify the position, see the
56-
#' [layer position][layer_positions] documentation.
5744
#' @param check_overlap If `TRUE`, text that overlaps previous text in the
5845
#' same layer will not be plotted. `check_overlap` happens at draw time and in
5946
#' the order of the data. Therefore data should be arranged by the label
@@ -166,28 +153,15 @@
166153
#' geom_text(aes(label = text), vjust = "inward", hjust = "inward")
167154
#' }
168155
geom_text <- function(mapping = NULL, data = NULL,
169-
stat = "identity", position = "identity",
156+
stat = "identity", position = "nudge",
170157
...,
171158
parse = FALSE,
172-
nudge_x = 0,
173-
nudge_y = 0,
174159
check_overlap = FALSE,
175160
size.unit = "mm",
176161
na.rm = FALSE,
177162
show.legend = NA,
178163
inherit.aes = TRUE)
179164
{
180-
if (!missing(nudge_x) || !missing(nudge_y)) {
181-
if (!missing(position)) {
182-
cli::cli_abort(c(
183-
"Both {.arg position} and {.arg nudge_x}/{.arg nudge_y} are supplied.",
184-
"i" = "Only use one approach to alter the position."
185-
))
186-
}
187-
188-
position <- position_nudge(nudge_x, nudge_y)
189-
}
190-
191165
layer(
192166
data = data,
193167
mapping = mapping,

tests/testthat/_snaps/geom-label.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# geom_label() throws meaningful errors
22

3-
Both `position` and `nudge_x`/`nudge_y` are supplied.
4-
i Choose one approach to alter the position.
3+
Ignoring unknown parameters: `nudge_x`
54

65
---
76

tests/testthat/_snaps/geom-sf.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77

88
---
99

10-
Both `position` and `nudge_x`/`nudge_y` are supplied.
11-
i Only use one approach to alter the position.
10+
Ignoring unknown parameters: `nudge_x`
1211

1312
---
1413

15-
Both `position` and `nudge_x`/`nudge_y` are supplied.
16-
i Only use one approach to alter the position.
14+
Ignoring unknown parameters: `nudge_x`
1715

1816
---
1917

tests/testthat/_snaps/geom-text.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# geom_text() checks input
22

3-
Both `position` and `nudge_x`/`nudge_y` are supplied.
4-
i Only use one approach to alter the position.
3+
Ignoring unknown parameters: `nudge_x`
54

tests/testthat/_snaps/prohibited-functions.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,11 @@
4343
$geom_density_2d_filled
4444
[1] "contour_var"
4545
46-
$geom_label
47-
[1] "nudge_x" "nudge_y"
48-
49-
$geom_sf_label
50-
[1] "nudge_x" "nudge_y"
51-
5246
$geom_sf_text
53-
[1] "nudge_x" "nudge_y" "check_overlap"
47+
[1] "check_overlap"
5448
5549
$geom_text
56-
[1] "nudge_x" "nudge_y" "check_overlap"
50+
[1] "check_overlap"
5751
5852
$geom_violin
5953
[1] "draw_quantiles"

tests/testthat/test-geom-label.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test_that("geom_label() throws meaningful errors", {
2-
expect_snapshot_error(geom_label(position = "jitter", nudge_x = 0.5))
2+
expect_snapshot_warning(geom_label(position = "jitter", nudge_x = 0.5))
33
expect_snapshot_error(labelGrob(label = 1:3))
44
})
55

tests/testthat/test-geom-sf.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ test_that("errors are correctly triggered", {
140140
)
141141
p <- ggplot(pts) + geom_sf() + coord_cartesian()
142142
expect_snapshot_error(ggplotGrob(p))
143-
expect_snapshot_error(geom_sf_label(position = "jitter", nudge_x = 0.5))
144-
expect_snapshot_error(geom_sf_text(position = "jitter", nudge_x = 0.5))
143+
expect_snapshot_warning(geom_sf_label(position = "jitter", nudge_x = 0.5))
144+
expect_snapshot_warning(geom_sf_text(position = "jitter", nudge_x = 0.5))
145145

146146
# #5204: missing linewidth should be dropped
147147
pts <- sf::st_sf(

tests/testthat/test-geom-text.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test_that("geom_text() checks input", {
2-
expect_snapshot_error(geom_text(position = "jitter", nudge_x = 0.5))
2+
expect_snapshot_warning(geom_text(position = "jitter", nudge_x = 0.5))
33
})
44

55
test_that("geom_text() drops missing angles", {

0 commit comments

Comments
 (0)