Skip to content

Commit 93a91fe

Browse files
committed
Conditionally set pad in geom_freqpoly.
Fixes #1560
1 parent ab42c2c commit 93a91fe

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

R/geom-freqpoly.r

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ geom_freqpoly <- function(mapping = NULL, data = NULL,
66
na.rm = FALSE,
77
show.legend = NA,
88
inherit.aes = TRUE) {
9+
10+
params <- list(na.rm = na.rm, ...)
11+
if (identical(stat, "bin")) {
12+
params$pad <- TRUE
13+
}
14+
915
layer(
1016
data = data,
1117
mapping = mapping,
@@ -14,10 +20,6 @@ geom_freqpoly <- function(mapping = NULL, data = NULL,
1420
position = position,
1521
show.legend = show.legend,
1622
inherit.aes = inherit.aes,
17-
params = list(
18-
na.rm = na.rm,
19-
pad = TRUE,
20-
...
21-
)
23+
params = params
2224
)
2325
}

tests/testthat/test-geom-freqpoly.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
context("freqpoly")
2+
3+
test_that("can do frequency polygon with categorical x", {
4+
df <- data.frame(x = rep(letters[1:3], 3:1))
5+
6+
p <- ggplot(df, aes(x)) + geom_freqpoly(stat = "count")
7+
d <- layer_data(p)
8+
9+
expect_is(d$x, "integer")
10+
expect_equal(d$x, 1:3)
11+
expect_equal(d$y, 3:1)
12+
})

0 commit comments

Comments
 (0)