Skip to content

Commit 20a3e3b

Browse files
committed
Squashed commit of the following:
commit b049018 Merge: e1846bc ccf0ee5 Author: Thomas Knecht <[email protected]> Date: Mon Oct 7 12:29:23 2019 +0200 Resolve conflict Merge branch 'Add_position_nudgestack' of https://github.com/ThomasKnecht/ggplot2 into Add_position_nudgestack # Conflicts: # R/position-nudgestack.R commit e1846bc Author: Thomas Knecht <[email protected]> Date: Mon Oct 7 11:58:47 2019 +0200 Add package spezifications commit 5de0449 Author: Thomas Knecht <[email protected]> Date: Mon Oct 7 11:53:06 2019 +0200 Add package spezifications commit d9ec752 Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:20:41 2019 +0200 Style file commit e0368b0 Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 08:51:55 2019 +0200 Resolve conflict commit 325456a Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:49 2019 +0200 Add new examples commit 3210061 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 15:39:56 2019 +0200 Add the zoo-package to Suggestions commit 739ac7c Author: Thomas Knecht <[email protected]> Date: Wed Sep 18 15:55:02 2019 +0200 Add tests for correct nudging and stacking commit 662a5da Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:03:12 2019 +0200 Add validated svg for position_nudgestack commit 598b786 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:02:29 2019 +0200 Add test file with a doppelganger-test commit 90d1257 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:47:58 2019 +0200 Add time series example commit 415811c Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:44:37 2019 +0200 Add news commit 6e4398c Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:20:41 2019 +0200 Style file commit b61211d Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:20:41 2019 +0200 Style file commit 369a34b Author: Thomas Knecht <[email protected]> Date: Mon Sep 30 14:06:24 2019 +0200 Use tsbox for converting ts object to tibble commit e4e7ee0 Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 08:51:55 2019 +0200 Resolve conflict commit 4d66dad Author: Thomas Knecht <[email protected]> Date: Wed Sep 18 15:55:02 2019 +0200 Add tests for correct nudging and stacking commit 1b61750 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:02:29 2019 +0200 Add test file with a doppelganger-test commit 65e72fb Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:49 2019 +0200 Add new examples commit e5d61b5 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:06:00 2019 +0200 Adjust filter criterion in examples commit 8848fd9 Author: Thomas Knecht <[email protected]> Date: Mon Sep 30 14:06:24 2019 +0200 Use tsbox for converting ts object to tibble commit 28640d5 Author: Thomas Knecht <[email protected]> Date: Fri Sep 27 15:58:51 2019 +0200 Bugfix commit 59bc2a0 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:00:28 2019 +0200 Add position-nudgestack.R into man commit 71d567b Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:47:58 2019 +0200 Add time series example commit 3a1c71f Author: Thomas Knecht <[email protected]> Date: Wed Sep 18 15:55:02 2019 +0200 Add tests for correct nudging and stacking commit f26bb90 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:03:12 2019 +0200 Add validated svg for position_nudgestack commit 3ba06ab Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:02:29 2019 +0200 Add test file with a doppelganger-test commit fbf28dc Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:49 2019 +0200 Add new examples commit 5270a9d Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:20 2019 +0200 Delete packages from @examples commit 32d2203 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:06:00 2019 +0200 Adjust filter criterion in examples commit fc6ba5a Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 15:39:56 2019 +0200 Add the zoo-package to Suggestions commit b1bb9d1 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:00:28 2019 +0200 Add position-nudgestack.R into man commit d1c7ad8 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:58:38 2019 +0200 Add new position_nudgestack into NAMESPACE commit 621730d Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:56:35 2019 +0200 Add new position to DESCRIPTION commit 0750e55 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:47:58 2019 +0200 Add time series example commit ce942ac Author: Thomas Knecht <[email protected]> Date: Tue Sep 3 09:26:32 2019 +0200 Delete emtpy rows commit 86dfea0 Author: Thomas Knecht <[email protected]> Date: Tue Sep 3 09:09:06 2019 +0200 Add position_nudgestack commit ccf0ee5 Author: Thomas Knecht <[email protected]> Date: Mon Oct 7 11:58:47 2019 +0200 Add package spezifications commit 831d569 Author: Thomas Knecht <[email protected]> Date: Mon Oct 7 11:53:06 2019 +0200 Add package spezifications commit af4abb5 Merge: 0a89016 0ff81cb Author: Thomas Knecht <[email protected]> Date: Wed Oct 2 16:37:11 2019 +0200 Resolve conflict Merge branch 'Add_position_nudgestack' of https://github.com/ThomasKnecht/ggplot2 into Add_position_nudgestack # Conflicts: # R/position-nudgestack.R commit 0a89016 Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:44:37 2019 +0200 Add news commit 083454a Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:20:41 2019 +0200 Style file commit 9cdcf6a Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:20:41 2019 +0200 Style file commit 7d23e89 Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 08:51:55 2019 +0200 Resolve conflict commit 99eab52 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:49 2019 +0200 Add new examples commit 5fa6969 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 15:39:56 2019 +0200 Add the zoo-package to Suggestions commit 8642839 Author: Thomas Knecht <[email protected]> Date: Mon Sep 30 14:06:24 2019 +0200 Use tsbox for converting ts object to tibble commit f891dbc Author: Thomas Knecht <[email protected]> Date: Fri Sep 27 15:58:51 2019 +0200 Bugfix commit a960ca8 Author: Thomas Knecht <[email protected]> Date: Wed Sep 18 15:55:02 2019 +0200 Add tests for correct nudging and stacking commit 5b89b32 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:03:12 2019 +0200 Add validated svg for position_nudgestack commit 37f1bd6 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:02:29 2019 +0200 Add test file with a doppelganger-test commit e392ac8 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:49 2019 +0200 Add new examples commit d443b80 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:20 2019 +0200 Delete packages from @examples commit d967b8e Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:06:00 2019 +0200 Adjust filter criterion in examples commit b1c8b1a Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 15:39:56 2019 +0200 Add the zoo-package to Suggestions commit 55602af Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:00:28 2019 +0200 Add position-nudgestack.R into man commit 9f6aa7d Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:58:38 2019 +0200 Add new position_nudgestack into NAMESPACE commit 1b7c4c0 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:56:35 2019 +0200 Add new position to DESCRIPTION commit 6d76c3a Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:47:58 2019 +0200 Add time series example commit f67ae70 Author: Thomas Knecht <[email protected]> Date: Tue Sep 3 09:26:32 2019 +0200 Delete emtpy rows commit 14fd33d Author: Thomas Knecht <[email protected]> Date: Tue Sep 3 09:09:06 2019 +0200 Add position_nudgestack commit 0ff81cb Merge: 7214587 10fa001 Author: Thomas Knecht <[email protected]> Date: Wed Oct 2 13:46:28 2019 +0200 Merge remote-tracking branch 'upstream/master' into Add_position_nudgestack commit 10fa001 Author: Thomas Lin Pedersen <[email protected]> Date: Tue Oct 1 11:12:59 2019 +0200 Removing direction constraint from geoms (tidyverse#3506) commit 88c5bde Author: Mine Cetinkaya-Rundel <[email protected]> Date: Tue Oct 1 09:32:08 2019 +0100 Minor updates to data docs (tidyverse#3545) commit 7214587 Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:44:37 2019 +0200 Add news commit 28ba9bf Merge: daeb34e e688944 Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:32:12 2019 +0200 Merge branch 'Add_position_nudgestack' of https://github.com/ThomasKnecht/ggplot2 into Add_position_nudgestack commit daeb34e Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:20:41 2019 +0200 Style file commit e688944 Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:20:41 2019 +0200 Style file commit 9a45cc8 Author: Thomas Lin Pedersen <[email protected]> Date: Tue Oct 1 09:03:07 2019 +0200 scale_binned (tidyverse#3096) commit 02a038e Merge: 88f4a63 bde6844 Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 09:01:10 2019 +0200 Resolve conflict Merge branch 'Add_position_nudgestack' of https://github.com/ThomasKnecht/ggplot2 into Add_position_nudgestack # Conflicts: # R/position-nudgestack.R commit 88f4a63 Author: Thomas Knecht <[email protected]> Date: Mon Sep 30 14:06:24 2019 +0200 Use tsbox for converting ts object to tibble commit 752e476 Author: Thomas Knecht <[email protected]> Date: Fri Sep 27 15:58:51 2019 +0200 Bugfix commit 5271987 Author: Thomas Knecht <[email protected]> Date: Tue Oct 1 08:51:55 2019 +0200 Resolve conflict commit 771918d Author: Thomas Knecht <[email protected]> Date: Wed Sep 18 15:55:02 2019 +0200 Add tests for correct nudging and stacking commit da1e7be Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:03:37 2019 +0200 Delete packages from example commit a1573b3 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:03:12 2019 +0200 Add validated svg for position_nudgestack commit 59d2b6e Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:02:50 2019 +0200 Update vdiffr version commit 0e80c8a Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:02:29 2019 +0200 Add test file with a doppelganger-test commit 31cc104 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:49 2019 +0200 Add new examples commit dc6b78d Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:20 2019 +0200 Delete packages from @examples commit d35ea70 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:06:00 2019 +0200 Adjust filter criterion in examples commit 87c00fa Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 15:39:56 2019 +0200 Add the zoo-package to Suggestions commit f587fb8 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:01:48 2019 +0200 Add description of position_nudgestack commit 327a6cd Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:01:13 2019 +0200 Add position_nudgestack into description commit c97d54d Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:00:28 2019 +0200 Add position-nudgestack.R into man commit 7fbc0f7 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:58:38 2019 +0200 Add new position_nudgestack into NAMESPACE commit 9d894a8 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:56:35 2019 +0200 Add new position to DESCRIPTION commit 56e9b3b Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:47:58 2019 +0200 Add time series example commit 4535be6 Author: Mara Alexeev <[email protected]> Date: Tue Sep 3 08:26:07 2019 -0400 Clarify documentation in mpg: very minor (tidyverse#3515) * add helpful explanation of mpg$drv commit c8fa99f Author: Thomas Knecht <[email protected]> Date: Tue Sep 3 09:26:32 2019 +0200 Delete emtpy rows commit a290bb3 Author: Thomas Knecht <[email protected]> Date: Tue Sep 3 09:09:06 2019 +0200 Add position_nudgestack commit bde6844 Author: Thomas Knecht <[email protected]> Date: Mon Sep 30 14:06:24 2019 +0200 Use tsbox for converting ts object to tibble commit 0ee259c Author: bernie gray <[email protected]> Date: Mon Sep 30 06:54:57 2019 -0400 default formula argument to NULL in geom_smooth() (tidyverse#3307) commit fa000f7 Author: Dewey Dunnington <[email protected]> Date: Sun Sep 29 18:26:36 2019 -0300 Make position guides customizable (tidyverse#3398, closes tidyverse#3322) * Position guides can now be customized using the new `guide_axis()`, which can be passed to position `scale_*()` functions or via `guides()`. The new axis guide (`guide_axis()`) comes with arguments `check.overlap` (automatic removal of overlapping labels), `angle` (easy rotation of axis labels), and `n.dodge` (dodge labels into multiple rows/columns) * `CoordCartesian` gets new methods to resolve/train the new position guides commit 696fe9d Author: Thomas Knecht <[email protected]> Date: Fri Sep 27 15:58:51 2019 +0200 Bugfix commit b027238 Merge: 10b5e24 c32f856 Author: Thomas Knecht <[email protected]> Date: Wed Sep 18 16:38:27 2019 +0200 Merge branch 'Add_position_nudgestack' of https://github.com/TeddyLeeJones/ggplot2 into Add_position_nudgestack commit 10b5e24 Author: Thomas Knecht <[email protected]> Date: Wed Sep 18 15:55:02 2019 +0200 Add tests for correct nudging and stacking commit 4fb6996 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:03:37 2019 +0200 Delete packages from example commit 823c686 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:03:12 2019 +0200 Add validated svg for position_nudgestack commit e6df407 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:02:50 2019 +0200 Update vdiffr version commit be91893 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:02:29 2019 +0200 Add test file with a doppelganger-test commit f44e504 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:49 2019 +0200 Add new examples commit 3713420 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:20 2019 +0200 Delete packages from @examples commit 9291957 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:06:00 2019 +0200 Adjust filter criterion in examples commit ef5aef7 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 15:39:56 2019 +0200 Add the zoo-package to Suggestions commit 42c0fa3 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:01:48 2019 +0200 Add description of position_nudgestack commit 548f313 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:01:13 2019 +0200 Add position_nudgestack into description commit 7bb930c Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:00:28 2019 +0200 Add position-nudgestack.R into man commit 9bd40d6 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:58:38 2019 +0200 Add new position_nudgestack into NAMESPACE commit c5022d3 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:56:35 2019 +0200 Add new position to DESCRIPTION commit 8572437 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:47:58 2019 +0200 Add time series example commit 3d61c3a Author: Thomas Knecht <[email protected]> Date: Tue Sep 3 09:26:32 2019 +0200 Delete emtpy rows commit 2782c9d Author: Thomas Knecht <[email protected]> Date: Tue Sep 3 09:09:06 2019 +0200 Add position_nudgestack commit c32f856 Author: Thomas Knecht <[email protected]> Date: Wed Sep 18 15:55:02 2019 +0200 Add tests for correct nudging and stacking commit d5c58da Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:03:37 2019 +0200 Delete packages from example commit 015b2e3 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:03:12 2019 +0200 Add validated svg for position_nudgestack commit 2484f71 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:02:50 2019 +0200 Update vdiffr version commit e2c1fb6 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 18:02:29 2019 +0200 Add test file with a doppelganger-test commit a681f59 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:49 2019 +0200 Add new examples commit 02f6be4 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:09:20 2019 +0200 Delete packages from @examples commit def4755 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 16:06:00 2019 +0200 Adjust filter criterion in examples commit c1729d1 Author: Thomas Knecht <[email protected]> Date: Tue Sep 17 15:39:56 2019 +0200 Add the zoo-package to Suggestions commit 5ebe5d4 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:01:48 2019 +0200 Add description of position_nudgestack commit 99b4b5e Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:01:13 2019 +0200 Add position_nudgestack into description commit 971b110 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 14:00:28 2019 +0200 Add position-nudgestack.R into man commit e5e91ea Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:58:38 2019 +0200 Add new position_nudgestack into NAMESPACE commit fedef93 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:56:35 2019 +0200 Add new position to DESCRIPTION commit bcc75a3 Author: Thomas Knecht <[email protected]> Date: Mon Sep 16 13:47:58 2019 +0200 Add time series example commit 23e3241 Author: Mara Alexeev <[email protected]> Date: Tue Sep 3 08:26:07 2019 -0400 Clarify documentation in mpg: very minor (tidyverse#3515) * add helpful explanation of mpg$drv commit 01d7db0 Author: Thomas Knecht <[email protected]> Date: Tue Sep 3 09:26:32 2019 +0200 Delete emtpy rows commit a486906 Author: Thomas Knecht <[email protected]> Date: Tue Sep 3 09:09:06 2019 +0200 Add position_nudgestack
1 parent 115c396 commit 20a3e3b

14 files changed

+499
-10
lines changed

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ Suggests:
5555
sf (>= 0.7-3),
5656
svglite (>= 1.2.0.9001),
5757
testthat (>= 2.1.0),
58-
vdiffr (>= 0.3.0)
58+
vdiffr (>= 0.3.0),
59+
tsbox
5960
Enhances: sp
6061
License: GPL-2 | file LICENSE
6162
URL: http://ggplot2.tidyverse.org, https://github.com/tidyverse/ggplot2
@@ -182,6 +183,7 @@ Collate:
182183
'position-jitter.r'
183184
'position-jitterdodge.R'
184185
'position-nudge.R'
186+
'position-nudgestack.R'
185187
'position-stack.r'
186188
'quick-plot.r'
187189
'range.r'

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export(PositionIdentity)
204204
export(PositionJitter)
205205
export(PositionJitterdodge)
206206
export(PositionNudge)
207+
export(PositionNudgeStack)
207208
export(PositionStack)
208209
export(Scale)
209210
export(ScaleBinned)
@@ -432,6 +433,7 @@ export(position_identity)
432433
export(position_jitter)
433434
export(position_jitterdodge)
434435
export(position_nudge)
436+
export(position_nudgestack)
435437
export(position_stack)
436438
export(qplot)
437439
export(quickplot)

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+
* Added `position_nudgestack()`, which allows to nudge stacked columns. (@ThomasKnecht )
4+
35
* A new scale type has been added, that allows binning of aesthetics at the
46
scale level. It has versions for both position and non-position aesthetics and
57
comes with two new guides (`guide_bins` and `guide_coloursteps`) (@thomasp85, #3096)

R/position-nudgestack.R

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#' Simultaneously nudge and stack
2+
#'
3+
#' This is primarily used for set stacked columns between the ticks on the
4+
#' x-axis.
5+
#'
6+
#' @family position adjustments
7+
#' @param x,y Amount of vertical and horizontal distance to move.
8+
#' @param vjust Vertical adjustment for geoms that have a position
9+
#' (like points or lines), not a dimension (like bars or areas). Set to
10+
#' `0` to align with the bottom, `0.5` for the middle,
11+
#' and `1` (the default) for the top.
12+
#' @param reverse If `TRUE`, will reverse the default stacking order.
13+
#' This is useful if you're rotating both the plot and legend.
14+
#' @export
15+
#' @examples
16+
#' ESM <- tsbox::ts_tbl(EuStockMarkets)
17+
#'
18+
#' ESM_prep <- ESM %>%
19+
#' dplyr::mutate(time = as.Date(paste0(format(time, "%Y-%m"), "-1"))) %>%
20+
#' dplyr::group_by(id, time) %>%
21+
#' dplyr::summarize(value = mean(value)) %>%
22+
#' dplyr::filter(time >= "1995-01-01" & time < "1998-01-01")
23+
#'
24+
#' ggplot(data = ESM_prep, mapping = aes(x = time, y = value, fill = id)) +
25+
#' geom_col(position = position_nudgestack(x = 15))
26+
position_nudgestack <- function(x = 0, y = 0, vjust = 1, reverse = FALSE) {
27+
ggproto(NULL, PositionNudgeStack,
28+
x = x,
29+
y = y,
30+
vjust = vjust,
31+
reverse = reverse
32+
)
33+
}
34+
35+
#' @rdname ggplot2-ggproto
36+
#' @format NULL
37+
#' @usage NULL
38+
#' @export
39+
PositionNudgeStack <- ggproto("PositionNudgeStack", Position,
40+
x = 0,
41+
y = 0,
42+
vjust = 1,
43+
fill = FALSE,
44+
reverse = FALSE,
45+
46+
setup_params = function(self, data) {
47+
list(
48+
x = self$x,
49+
y = self$y,
50+
var = if (!is.null(self$var)) self$var else stack_var(data),
51+
fill = self$fill,
52+
vjust = self$vjust,
53+
reverse = self$reverse
54+
)
55+
},
56+
57+
setup_data = function(self, data, params) {
58+
if (is.null(params$var)) {
59+
return(data)
60+
}
61+
62+
data$ymax <- switch(params$var,
63+
y = data$y,
64+
ymax = ifelse(data$ymax == 0, data$ymin, data$ymax)
65+
)
66+
67+
remove_missing(
68+
data,
69+
vars = c("x", "xmin", "xmax", "y"),
70+
name = "position_stack"
71+
)
72+
},
73+
74+
compute_layer = function(self, data, params, layout) {
75+
if (is.null(params$var)) {
76+
return(data)
77+
}
78+
79+
negative <- data$ymax < 0
80+
negative[is.na(negative)] <- FALSE
81+
82+
neg <- data[negative, , drop = FALSE]
83+
pos <- data[!negative, , drop = FALSE]
84+
85+
if (any(negative)) {
86+
neg <- collide(neg, NULL, "position_stack", pos_stack,
87+
vjust = params$vjust,
88+
fill = params$fill,
89+
reverse = params$reverse
90+
)
91+
}
92+
if (any(!negative)) {
93+
pos <- collide(pos, NULL, "position_stack", pos_stack,
94+
vjust = params$vjust,
95+
fill = params$fill,
96+
reverse = params$reverse
97+
)
98+
}
99+
100+
data <- rbind(neg, pos)[match(seq_len(nrow(data)), c(which(negative), which(!negative))), ]
101+
102+
# transform only the dimensions for which non-zero nudging is requested
103+
if (any(params$x != 0)) {
104+
if (any(params$y != 0)) {
105+
transform_position(data, function(x) x + params$x, function(y) y + params$y)
106+
} else {
107+
transform_position(data, function(x) x + params$x, NULL)
108+
}
109+
} else if (any(params$y != 0)) {
110+
transform_position(data, NULL, function(y) y + params$y)
111+
} else {
112+
data # if both x and y are 0 we don't need to transform
113+
}
114+
}
115+
)

man/ggplot2-ggproto.Rd

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/position_dodge.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/position_identity.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/position_jitter.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/position_jitterdodge.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/position_nudge.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/position_nudgestack.Rd

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/position_stack.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)