From 408dd80b4096c8b72bd58a38eb663519dbb10981 Mon Sep 17 00:00:00 2001 From: AnneLyng Date: Mon, 8 Jul 2019 12:14:15 +0200 Subject: [PATCH 1/4] added documentation to geom_area --- NEWS | 8 ++++++++ R/geom-ribbon.r | 3 ++- man/geom_ribbon.Rd | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 080474291a..0a5435d22c 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +ggplot2 3.2.0.9000 +---------------------------------------------------------------- + +* Corrected documentation for `geom_area` aethestic (`ymax` to + `y`). (@AnneLyng, #2873) + + + ggplot2 1.0.1 ---------------------------------------------------------------- diff --git a/R/geom-ribbon.r b/R/geom-ribbon.r index fb292cb0fa..cb45c2063c 100644 --- a/R/geom-ribbon.r +++ b/R/geom-ribbon.r @@ -2,7 +2,8 @@ #' #' For each x value, `geom_ribbon` displays a y interval defined #' by `ymin` and `ymax`. `geom_area` is a special case of -#' `geom_ribbon`, where the `ymin` is fixed to 0. +#' `geom_ribbon`, where the `ymin` is fixed to 0 and `y` is used instead +#' of `ymax`. #' #' An area plot is the continuous analogue of a stacked bar chart (see #' [geom_bar()]), and can be used to show how composition of the diff --git a/man/geom_ribbon.Rd b/man/geom_ribbon.Rd index af2288135e..347eadeab4 100644 --- a/man/geom_ribbon.Rd +++ b/man/geom_ribbon.Rd @@ -62,7 +62,8 @@ the default plot specification, e.g. \code{\link[=borders]{borders()}}.} \description{ For each x value, \code{geom_ribbon} displays a y interval defined by \code{ymin} and \code{ymax}. \code{geom_area} is a special case of -\code{geom_ribbon}, where the \code{ymin} is fixed to 0. +\code{geom_ribbon}, where the \code{ymin} is fixed to 0 and \code{y} is used instead +of \code{ymax}. } \details{ An area plot is the continuous analogue of a stacked bar chart (see From ec767d6f0d6ea5a9eb8c1b6cb900ec8cbf58de0e Mon Sep 17 00:00:00 2001 From: AnneLyng Date: Mon, 8 Jul 2019 13:30:36 +0200 Subject: [PATCH 2/4] geom_area docu. - updated minor comments --- NEWS | 8 -------- NEWS.md | 3 +++ R/geom-ribbon.r | 4 ++-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 0a5435d22c..080474291a 100644 --- a/NEWS +++ b/NEWS @@ -1,11 +1,3 @@ -ggplot2 3.2.0.9000 ----------------------------------------------------------------- - -* Corrected documentation for `geom_area` aethestic (`ymax` to - `y`). (@AnneLyng, #2873) - - - ggplot2 1.0.1 ---------------------------------------------------------------- diff --git a/NEWS.md b/NEWS.md index 7d61546d9a..2c50b720ca 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # ggplot2 (development version) +* Corrected documentation for `geom_area` aethestic (`ymax` to + `y`). (@AnneLyng, #2873) + * `expand_scale()` was deprecated in favour of `expansion()` for setting the `expand` argument of `x` and `y` scales (@paleolimbot). diff --git a/R/geom-ribbon.r b/R/geom-ribbon.r index cb45c2063c..17df0ed118 100644 --- a/R/geom-ribbon.r +++ b/R/geom-ribbon.r @@ -1,7 +1,7 @@ #' Ribbons and area plots #' -#' For each x value, `geom_ribbon` displays a y interval defined -#' by `ymin` and `ymax`. `geom_area` is a special case of +#' For each x value, `geom_ribbon()` displays a y interval defined +#' by `ymin` and `ymax`. `geom_area()` is a special case of #' `geom_ribbon`, where the `ymin` is fixed to 0 and `y` is used instead #' of `ymax`. #' From 9000d5048b8a848beb3c0bb2b9fd14fa1217a606 Mon Sep 17 00:00:00 2001 From: AnneLyng Date: Mon, 8 Jul 2019 15:55:23 +0200 Subject: [PATCH 3/4] reverse discrete scales - get_limits --- NEWS.md | 2 ++ R/scale-discrete-.r | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4e88d301a1..08ccd08178 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ggplot2 (development version) +* Allowed reversing of discrete scales by re-writing `get_limits()` (@AnneLyng, #3115) + * Added weight aesthetic option to `stat_density()` and made scaling of weights the default (@annennenne, #2902) diff --git a/R/scale-discrete-.r b/R/scale-discrete-.r index 6ba8b89d7e..afcc4a0794 100644 --- a/R/scale-discrete-.r +++ b/R/scale-discrete-.r @@ -83,9 +83,17 @@ ScaleDiscretePosition <- ggproto("ScaleDiscretePosition", ScaleDiscrete, }, get_limits = function(self) { - if (self$is_empty()) return(c(0, 1)) - - self$limits %||% self$range$range %||% integer() + if (self$is_empty()) { + c(0, 1) + } else if (!is.null(self$limits) & !is.function(self$limits)){ + self$limits + } else if (is.null(self$limits)) { + self$range$range + } else if (is.function(self$limits)) { + self$limits(self$range$range) + } else { + integer(0) + } }, is_empty = function(self) { From 26bdc8407d5d1dbdd670f7a3ce96e9d39f5104e9 Mon Sep 17 00:00:00 2001 From: Dewey Dunnington Date: Tue, 16 Jul 2019 14:11:20 -0400 Subject: [PATCH 4/4] add functional limit test --- tests/testthat/test-scale-discrete.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test-scale-discrete.R b/tests/testthat/test-scale-discrete.R index 094d97ce84..79b5c74a17 100644 --- a/tests/testthat/test-scale-discrete.R +++ b/tests/testthat/test-scale-discrete.R @@ -69,3 +69,9 @@ test_that("discrete scale shrinks to range when setting limits", { expect_equal(layer_scales(p)$x$dimension(c(0, 1)), c(0, 3)) }) + +test_that("discrete position scales can accept functional limits", { + scale <- scale_x_discrete(limits = rev) + scale$train(c("a", "b", "c")) + expect_identical(scale$get_limits(), c("c", "b", "a")) +})