From 8d48bc2ffc1e3d0833c6b32d93332c3079dcd58f Mon Sep 17 00:00:00 2001 From: Ioannis Kosmidis Date: Mon, 8 Jul 2019 12:23:28 +0100 Subject: [PATCH 1/5] Experimenting with solutions --- R/position-stack.r | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/position-stack.r b/R/position-stack.r index e54de07451..69a5493350 100644 --- a/R/position-stack.r +++ b/R/position-stack.r @@ -176,7 +176,11 @@ PositionStack <- ggproto("PositionStack", Position, return(data) } + ## ymax_position <- ifelse(is.na(data$ymax), data$y, data$ymax) + ## negative <- ymax_position < 0 + negative <- data$ymax < 0 + neg <- data[negative, , drop = FALSE] pos <- data[!negative, , drop = FALSE] From aa63070c3c6f48b3b5630fd0657421edcfe4680c Mon Sep 17 00:00:00 2001 From: Ioannis Kosmidis Date: Mon, 8 Jul 2019 12:50:38 +0100 Subject: [PATCH 2/5] NA in negative treated as FALSE --- R/position-stack.r | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/position-stack.r b/R/position-stack.r index 69a5493350..1e32c2330f 100644 --- a/R/position-stack.r +++ b/R/position-stack.r @@ -176,10 +176,9 @@ PositionStack <- ggproto("PositionStack", Position, return(data) } - ## ymax_position <- ifelse(is.na(data$ymax), data$y, data$ymax) - ## negative <- ymax_position < 0 - negative <- data$ymax < 0 + negative <- data$ymax < 0 + negative[is.na(negative)] <- FALSE neg <- data[negative, , drop = FALSE] pos <- data[!negative, , drop = FALSE] From 100ab2fd70327ed0562b178185e9e21698ba35d7 Mon Sep 17 00:00:00 2001 From: Ioannis Kosmidis Date: Mon, 8 Jul 2019 12:55:37 +0100 Subject: [PATCH 3/5] Added news item --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 7d61546d9a..43d801d486 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # ggplot2 (development version) +* stacking text when calculating the labels and the y axis with + `stat_summary()` now works (@ikosmidis, #2709) + * `expand_scale()` was deprecated in favour of `expansion()` for setting the `expand` argument of `x` and `y` scales (@paleolimbot). From 6d38753110430e17004c18bcb97a43fb2e20280e Mon Sep 17 00:00:00 2001 From: Ioannis Kosmidis Date: Mon, 8 Jul 2019 13:05:02 +0100 Subject: [PATCH 4/5] Deleted redundant line --- R/position-stack.r | 1 - 1 file changed, 1 deletion(-) diff --git a/R/position-stack.r b/R/position-stack.r index 1e32c2330f..0466a84919 100644 --- a/R/position-stack.r +++ b/R/position-stack.r @@ -176,7 +176,6 @@ PositionStack <- ggproto("PositionStack", Position, return(data) } - negative <- data$ymax < 0 negative <- data$ymax < 0 negative[is.na(negative)] <- FALSE From c66e5af02019ea6315d4ed5ed3a8e675fda69ce0 Mon Sep 17 00:00:00 2001 From: Dewey Dunnington Date: Wed, 17 Jul 2019 13:29:10 -0400 Subject: [PATCH 5/5] add test for stacking when ymax is NA --- tests/testthat/test-position-stack.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test-position-stack.R b/tests/testthat/test-position-stack.R index 313dae16a5..f3be540a16 100644 --- a/tests/testthat/test-position-stack.R +++ b/tests/testthat/test-position-stack.R @@ -52,3 +52,9 @@ test_that("data with no extent is stacked correctly", { expect_equal(layer_data(p0)$y, c(-75, -115)) expect_equal(layer_data(p1)$y, c(0, -75)) }) + +test_that("position_stack() can stack correctly when ymax is NA", { + df <- data_frame(x = c(1, 1), y = c(1, 1)) + p <- ggplot(df, aes(x, y, ymax = NA_real_)) + geom_point(position = "stack") + expect_equal(layer_data(p)$y, c(1, 2)) +})