Skip to content

Commit

Permalink
Fix documentation bugs
Browse files Browse the repository at this point in the history
In addition implement direction parameter in `psosition_dodge_and_nudge()`
  • Loading branch information
aphalo committed Dec 8, 2021
1 parent df6c111 commit 169e2f6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Date: 2021-12-08
Authors@R:
c(
person("Pedro J.", "Aphalo", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3385-972X")),
person("Kamil", "Slowikowski", role = "ctb"), comment = c(ORCID = "0000-0002-2843-6370")),
person("Michał", "Krassowski", role = "ctb"), comment = c(ORCID = "0000-0002-9638-7785"))
person("Kamil", "Slowikowski", role = "ctb", comment = c(ORCID = "0000-0002-2843-6370")),
person("Michał", "Krassowski", role = "ctb", comment = c(ORCID = "0000-0002-9638-7785"))
)
Maintainer: Pedro J. Aphalo <[email protected]>
Description: Extensions to 'ggplot2' respecting the grammar of graphics
Expand Down
19 changes: 14 additions & 5 deletions R/position-nudge-dodge.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#' position, or the width of a single element?.
#' @param x,y Amount of vertical and horizontal distance to move. A numeric
#' vector of length 1, or of the same length as rows there are in `data`,
#' @param direction One of "none" or "split". A value of "none"
#' replicates the behavior of [ggplot2::position_nudge]. At the moment
#' "split" changes the sign of the nudge at zero, which is suiatble for column
#' plots with negative slices.
#'
#' @seealso [ggplot2::position_nudge()], [ggrepel::position_nudge_repel()].
#'
Expand Down Expand Up @@ -66,6 +70,11 @@ position_dodge_and_nudge <- function(width = 1,
ggplot2::ggproto(NULL, PositionDodgeAndNudge,
x = x,
y = y,
.fun = switch(direction,
none = I,
split = sign,
center = sign,
sign),
width = width,
preserve = match.arg(preserve)
)
Expand All @@ -82,7 +91,7 @@ PositionDodgeAndNudge <-

setup_params = function(self, data) {
c(
list(nudge_x = self$x, nudge_y = self$y),
list(nudge_x = self$x, nudge_y = self$y, .fun = self$.fun),
ggplot2::ggproto_parent(ggplot2::PositionDodge, self)$setup_params(data)
)
},
Expand All @@ -97,17 +106,17 @@ PositionDodgeAndNudge <-
if (any(params$nudge_x != 0)) {
if (any(params$nudge_y != 0)) {
data <- ggplot2::transform_position(data,
function(x) x + params$nudge_x * .fun(x),
function(y) y + params$nudge_y * .fun(y))
function(x) x + params$nudge_x * params$.fun(x),
function(y) y + params$nudge_y * params$.fun(y))
} else {
data <- ggplot2::transform_position(data,
function(x) x + params$nudge_x * .fun(x),
function(x) x + params$nudge_x * params$.fun(x),
NULL)
}
} else if (any(params$nudge_y != 0)) {
data <- ggplot2::transform_position(data,
function(x) x,
function(y) y + params$nudge_y * .fun(y))
function(y) y + params$nudge_y * params$.fun(y))
}
# add original position
data$x_orig <- x_orig
Expand Down
5 changes: 3 additions & 2 deletions man/ggpp-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/position_dodge_and_nudge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified tests/testthat/Rplots.pdf
Binary file not shown.

0 comments on commit 169e2f6

Please sign in to comment.