Skip to content

Commit 014c5d2

Browse files
authored
Merge pull request #5115 from teunbrand/ecdf_scale_transform
`stat_ecdf()` responds to scale transform
2 parents 9468b69 + 12da45e commit 014c5d2

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# ggplot2 (development version)
22

3+
* Renamed computed aesthetic in `stat_ecdf()` to `ecdf`, to prevent incorrect
4+
scale transformations (@teunbrand, #5113 and #5112).
35
* Fixed misbehaviour of `draw_key_boxplot()` and `draw_key_crossbar()` with
46
skewed key aspect ratio (@teunbrand, #5082).
57
* `scale_*_binned()` handles zero-range limits more gracefully (@teunbrand,
68
#5066)
79
* Binned scales are now compatible with `trans = "date"` and `trans = "time"`
810
(@teunbrand, #4217).
911
* `ggsave()` warns when multiple `filename`s are given, and only writes to the
10-
first file (@teunbrand, #5114).
12+
first file (@teunbrand, #5114)
1113
* Fixed a regression in `geom_hex()` where aesthetics were replicated across
1214
bins (@thomasp85, #5037 and #5044)
1315
* Fixed spurious warning when `weight` aesthetic was used in `stat_smooth()`

R/stat-ecdf.r

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#' @param pad If `TRUE`, pad the ecdf with additional points (-Inf, 0)
2222
#' and (Inf, 1)
2323
#' @eval rd_computed_vars(
24-
#' y = "Cumulative density corresponding to `x`."
24+
#' ecdf = "Cumulative density corresponding to `x`."
2525
#' )
2626
#' @export
2727
#' @examples
@@ -73,7 +73,7 @@ stat_ecdf <- function(mapping = NULL, data = NULL,
7373
StatEcdf <- ggproto("StatEcdf", Stat,
7474
required_aes = c("x|y"),
7575

76-
default_aes = aes(y = after_stat(y)),
76+
default_aes = aes(x = after_stat(ecdf), y = after_stat(ecdf)),
7777

7878
setup_params = function(self, data, params) {
7979
params$flipped_aes <- has_flipped_aes(data, params, main_is_orthogonal = FALSE, main_is_continuous = TRUE)
@@ -103,7 +103,7 @@ StatEcdf <- ggproto("StatEcdf", Stat,
103103

104104
df_ecdf <- data_frame0(
105105
x = x,
106-
y = data_ecdf,
106+
ecdf = data_ecdf,
107107
.size = length(x)
108108
)
109109
df_ecdf$flipped_aes <- flipped_aes

man/stat_ecdf.Rd

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

tests/testthat/test-stat-ecdf.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ test_that("stat_ecdf works in both directions", {
1515
expect_snapshot_error(ggplot_build(p))
1616
})
1717

18+
# See #5113 and #5112
19+
test_that("stat_ecdf responds to axis transformations", {
20+
n <- 4
21+
answer <- c(seq(0, 1, length.out = n + 1), 1)
22+
p <- ggplot(data_frame0(x = seq_len(n)), aes(x)) + stat_ecdf()
23+
24+
ld <- layer_data(p)
25+
expect_equal(ld$y, answer)
26+
27+
ld <- layer_data(p + scale_y_sqrt())
28+
expect_equal(ld$y, sqrt(answer))
29+
})

0 commit comments

Comments
 (0)