Skip to content

Commit d9f2cd4

Browse files
author
Dana Paige Seidel
authored
Fix sec.axis() when used with tidyeval (#2797)
Fixes #2788
1 parent 0770163 commit d9f2cd4

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ggplot2 3.0.0.9000
22

3+
* `sec_axis()` now works as expected when used in combination with tidy eval
4+
(@dpseidel, #2788).
5+
36
* `stat_contour()`, `stat_density2d()`, `stat_bin2d()`, `stat_binhex()`
47
now calculate normalized statistics including `nlevel`, `ndensity`, and
58
`ncount`. Also, `stat_density()` now includes the calculated statistic

R/axis-secondary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
106106

107107
transform_range = function(self, range) {
108108
range <- structure(data.frame(range), names = '.')
109-
f_eval(self$trans, range)
109+
rlang::eval_tidy(rlang::f_rhs(self$trans), data = range)
110110
},
111111

112112

tests/testthat/test-sec-axis.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,27 @@ test_that("sec axis works with skewed transform", {
4646
breaks = derive()))
4747
)
4848
})
49+
50+
test_that("sec axis works with tidy eval", {
51+
f <- function(df, .x, .y, .z) {
52+
x <- enquo(.x)
53+
y <- enquo(.y)
54+
z <- enquo(.z)
55+
56+
g <- ggplot(df, aes(x = !!x, y = !!y)) +
57+
geom_bar(stat = "identity") +
58+
geom_point(aes(y = !!z)) +
59+
scale_y_continuous(sec.axis = sec_axis(~. / 10))
60+
61+
g
62+
}
63+
64+
t <- tibble(x = letters, y = seq(10, 260, 10), z = 1:26)
65+
66+
p <- f(t, x, y, z)
67+
68+
scale <- layer_scales(p)$y
69+
breaks <- scale$break_info()
70+
71+
expect_equal(breaks$major_source / 10, breaks$sec.major_source)
72+
})

0 commit comments

Comments
 (0)