From 5d700675d30a201db04146777eb07c59ef9d5156 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Tue, 16 Jan 2024 20:16:47 +0100 Subject: [PATCH] Fix #314 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ R/aaa.R | 12 ++++++++++++ R/arc_bar.R | 14 +------------- R/diagonal.R | 4 ++-- R/ellipse.R | 2 +- R/link.R | 2 +- R/regon.R | 2 +- R/spiro.R | 2 +- man/facet_grid_paginate.Rd | 2 +- man/gather_set_data.Rd | 1 + man/geom_autohistogram.Rd | 3 ++- man/geom_delvor.Rd | 2 ++ man/geom_mark_hull.Rd | 2 ++ man/geom_sina.Rd | 3 ++- man/scale_unit.Rd | 2 +- man/trans_reverser.Rd | 2 +- 17 files changed, 34 insertions(+), 25 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b9c3e12a..37df2d00 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -42,7 +42,7 @@ Imports: vctrs, systemfonts LinkingTo: Rcpp, RcppEigen -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 Suggests: sessioninfo, concaveman, diff --git a/NEWS.md b/NEWS.md index ed091dfd..8d58e093 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ggforce (development version) +* Fixed a bug that would cause reordering of data in some geoms (#314) + # ggforce 0.4.1 * Fixed a sanitizer error in the decent calculations used for the mark geoms diff --git a/R/aaa.R b/R/aaa.R index a053dfc8..e9f74ccf 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -26,3 +26,15 @@ combine_aes <- function(aes1, aes2) { empty_data <- function(x) { length(x) == 0 || nrow(x) == 0 } + +# This function is like base::make.unique, but it +# maintains the ordering of the original names if the values +# are sorted. +make_unique <- function(x, sep = '.') { + if (!anyDuplicated(x)) return(x) + groups <- match(x, unique(x)) + suffix <- unsplit(lapply(split(x, groups), seq_along), groups) + max_chars <- nchar(max(suffix)) + suffix_format <- paste0('%0', max_chars, 'd') + paste0(x, sep, sprintf(suffix_format, suffix)) +} diff --git a/R/arc_bar.R b/R/arc_bar.R index e5a2c7c6..9d71eda0 100644 --- a/R/arc_bar.R +++ b/R/arc_bar.R @@ -184,25 +184,13 @@ geom_arc_bar <- function(mapping = NULL, data = NULL, stat = 'arc_bar', ) } -# This function is like base::make.unique, but it -# maintains the ordering of the original names if the values -# are sorted. -make_unique <- function(x, sep = '.') { - if (!anyDuplicated(x)) return(x) - groups <- match(x, unique(x)) - suffix <- unsplit(lapply(split(x, groups), seq_along), groups) - max_chars <- nchar(max(suffix)) - suffix_format <- paste0('%0', max_chars, 'd') - paste0(x, sep, sprintf(suffix_format, suffix)) -} - arcPaths <- function(data, n) { trans <- radial_trans(c(0, 1), c(0, 2 * pi), pad = 0) data <- data[data$start != data$end, ] data$nControl <- ceiling(n / (2 * pi) * abs(data$end - data$start)) data$nControl[data$nControl < 3] <- 3 extraData <- !names(data) %in% c('r0', 'r', 'start', 'end', 'group') - data$group <- make_unique(as.character(data$group)) + data$group <- make_unique(data$group) paths <- lapply(seq_len(nrow(data)), function(i) { path <- data_frame0( a = seq(data$start[i], data$end[i], length.out = data$nControl[i]), diff --git a/R/diagonal.R b/R/diagonal.R index 91a4033b..05d237cd 100644 --- a/R/diagonal.R +++ b/R/diagonal.R @@ -106,7 +106,7 @@ StatDiagonal <- ggproto('StatDiagonal', Stat, compute_panel = function(data, scales, n = 100, strength = 0.5, flipped_aes = FALSE) { if (empty_data(data)) return(data) data <- flip_data(data, flipped_aes) - data$group <- make_unique(as.character(data$group)) + data$group <- make_unique(data$group) end <- data end$x <- end$xend end$y <- end$yend @@ -212,7 +212,7 @@ StatDiagonal0 <- ggproto('StatDiagonal0', Stat, compute_panel = function(data, scales, strength = 0.5, flipped_aes = FALSE) { if (empty_data(data)) return(data) data <- flip_data(data, flipped_aes) - data$group <- make_unique(as.character(data$group)) + data$group <- make_unique(data$group) end <- data end$x <- end$xend end$y <- end$yend diff --git a/R/ellipse.R b/R/ellipse.R index c49b7ec1..5d17cb9b 100644 --- a/R/ellipse.R +++ b/R/ellipse.R @@ -69,7 +69,7 @@ StatEllip <- ggproto('StatEllip', Stat, }, compute_panel = function(self, data, scales, n = 360) { if (empty_data(data)) return(data) - data$group <- make_unique(as.character(data$group)) + data$group <- make_unique(data$group) n_ellipses <- nrow(data) data <- data[rep(seq_len(n_ellipses), each = n), ] points <- rep(seq(0, 2 * pi, length.out = n + 1)[seq_len(n)], diff --git a/R/link.R b/R/link.R index 82f33078..5a89832b 100644 --- a/R/link.R +++ b/R/link.R @@ -85,7 +85,7 @@ NULL StatLink <- ggproto('StatLink', Stat, compute_panel = function(data, scales, n = 100) { extraCols <- !names(data) %in% c('x', 'y', 'xend', 'yend', 'group', 'PANEL') - data$group <- make_unique(as.character(data$group)) + data$group <- make_unique(data$group) data <- lapply(seq_len(nrow(data)), function(i) { path <- data_frame0( x = seq(data$x[i], data$xend[i], length.out = n), diff --git a/R/regon.R b/R/regon.R index 28459e4f..7fcc00ed 100644 --- a/R/regon.R +++ b/R/regon.R @@ -60,7 +60,7 @@ StatRegon <- ggproto('StatRegon', Stat, if (n %% 2 == 0) p <- p + p[2] / 2 p * 2 * pi })) - data$group <- make_unique(as.character(data$group)) + data$group <- make_unique(data$group) data <- data[rep(seq_len(nrow(data)), data$sides), ] x_tmp <- sin(pos) * data$r y_tmp <- cos(pos) * data$r diff --git a/R/spiro.R b/R/spiro.R index 45efeaa2..4adf8229 100644 --- a/R/spiro.R +++ b/R/spiro.R @@ -68,7 +68,7 @@ StatSpiro <- ggproto('StatSpiro', Stat, if (is.null(data$x0)) data$x0 <- 0 if (is.null(data$y0)) data$y0 <- 0 n_spiro <- nrow(data) - data$group <- make_unique(as.character(data$group)) + data$group <- make_unique(data$group) if (is.null(revolutions)) { revo <- attr(fractions(data$r / data$R), 'fracs') revo <- as.numeric(sub('/.*$', '', revo)) diff --git a/man/facet_grid_paginate.Rd b/man/facet_grid_paginate.Rd index 310e143c..36773d93 100644 --- a/man/facet_grid_paginate.Rd +++ b/man/facet_grid_paginate.Rd @@ -21,7 +21,7 @@ facet_grid_paginate( ) } \arguments{ -\item{facets}{This argument is soft-deprecated, please use \code{rows} +\item{facets}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Please use \code{rows} and \code{cols} instead.} \item{margins}{Either a logical value or a character diff --git a/man/gather_set_data.Rd b/man/gather_set_data.Rd index 3aa3a8ef..64bc2717 100644 --- a/man/gather_set_data.Rd +++ b/man/gather_set_data.Rd @@ -24,4 +24,5 @@ that can be used by geom_parallel_sets. \examples{ data <- reshape2::melt(Titanic) head(gather_set_data(data, 1:4)) +head(gather_set_data(data, c("Class","Sex","Age","Survived"))) } diff --git a/man/geom_autohistogram.Rd b/man/geom_autohistogram.Rd index 734d0e1c..169c9fb9 100644 --- a/man/geom_autohistogram.Rd +++ b/man/geom_autohistogram.Rd @@ -73,7 +73,8 @@ to the paired geom/stat.} \item{bw}{The smoothing bandwidth to be used. If numeric, the standard deviation of the smoothing kernel. If character, a rule to choose the bandwidth, as listed in -\code{\link[stats:bandwidth]{stats::bw.nrd()}}.} +\code{\link[stats:bandwidth]{stats::bw.nrd()}}. Note that automatic calculation of the bandwidth does +not take weights into account.} \item{adjust}{A multiplicate bandwidth adjustment. This makes it possible to adjust the bandwidth while still using the a bandwidth estimator. diff --git a/man/geom_delvor.Rd b/man/geom_delvor.Rd index 775e699c..19bc35a6 100644 --- a/man/geom_delvor.Rd +++ b/man/geom_delvor.Rd @@ -252,6 +252,7 @@ the bounding box} } \examples{ +\dontshow{if (requireNamespace("deldir", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Voronoi # You usually wants all points to take part in the same tesselation so set # the group aesthetic to a constant (-1L is just a convention) @@ -290,4 +291,5 @@ ggplot(iris, aes(Sepal.Length, Sepal.Width)) + ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_delaunay_segment2(aes(colour = Species, group = -1), size = 2, lineend = 'round') +\dontshow{\}) # examplesIf} } diff --git a/man/geom_mark_hull.Rd b/man/geom_mark_hull.Rd index 3d522db4..0b566719 100644 --- a/man/geom_mark_hull.Rd +++ b/man/geom_mark_hull.Rd @@ -213,6 +213,7 @@ removed data. } \examples{ +\dontshow{if (requireNamespace("concaveman", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ## requires the concaveman packages ggplot(iris, aes(Petal.Length, Petal.Width)) + geom_mark_hull(aes(fill = Species, filter = Species != 'versicolor')) + @@ -261,6 +262,7 @@ ggplot(iris, aes(Petal.Length, Petal.Width)) + geom_mark_hull(aes(fill = Species, label = Species), con.cap = 0) + geom_point() +\dontshow{\}) # examplesIf} } \seealso{ Other mark geoms: diff --git a/man/geom_sina.Rd b/man/geom_sina.Rd index 869e378e..e98b466f 100644 --- a/man/geom_sina.Rd +++ b/man/geom_sina.Rd @@ -89,7 +89,8 @@ abbreviated, e.g. "d"). See \code{Details}.} \item{bw}{The smoothing bandwidth to be used. If numeric, the standard deviation of the smoothing kernel. If character, a rule to choose the bandwidth, as listed in -\code{\link[stats:bandwidth]{stats::bw.nrd()}}.} +\code{\link[stats:bandwidth]{stats::bw.nrd()}}. Note that automatic calculation of the bandwidth does +not take weights into account.} \item{kernel}{Kernel. See list of available kernels in \code{\link[=density]{density()}}.} diff --git a/man/scale_unit.Rd b/man/scale_unit.Rd index deae7a59..727187ba 100644 --- a/man/scale_unit.Rd +++ b/man/scale_unit.Rd @@ -10,7 +10,7 @@ scale_x_unit(...) scale_y_unit(...) } \arguments{ -\item{...}{Passed on to \code{units::scale_x_unit()} or \code{units::scale_y_unit()}} +\item{...}{Passed on to \code{units::scale_x_units()} or \code{units::scale_y_units()}} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} These are the default scales for the units diff --git a/man/trans_reverser.Rd b/man/trans_reverser.Rd index d718daba..d58e3d83 100644 --- a/man/trans_reverser.Rd +++ b/man/trans_reverser.Rd @@ -8,7 +8,7 @@ trans_reverser(trans) } \arguments{ \item{trans}{A trans object or an object that can be converted to one using -\code{\link[scales:trans_new]{scales::as.trans()}}} +\code{\link[scales:new_transform]{scales::as.trans()}}} } \value{ A trans object