Skip to content

Commit fa8004e

Browse files
izahnhadley
authored andcommitted
Order path data in GeomSmooth (tidyverse#2029)
Fixes tidyverse#2028
1 parent e801f8d commit fa8004e

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

NEWS.md

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

3+
* `geom_smooth` now orders by the `x` aesthetic, making it easier to pass
4+
pre-computed values without manual ordering (@izahn, #2028).
5+
36
* Fixed bug in `coord_polar` that prevented moving the radius axis
47
to the right (@thomasp85, #2005).
58

R/geom-smooth.r

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ geom_smooth <- function(mapping = NULL, data = NULL,
114114
#' @usage NULL
115115
#' @export
116116
GeomSmooth <- ggproto("GeomSmooth", Geom,
117+
setup_data = function(data, params) {
118+
GeomLine$setup_data(data, params)
119+
},
117120
draw_group = function(data, panel_params, coord) {
118121
ribbon <- transform(data, colour = NA)
119122
path <- transform(data, alpha = NA)

tests/testthat/test-geom-smooth.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
context("geom_smooth")
2+
3+
test_that("Data is ordered by x", {
4+
df <- data.frame(x = c(1, 5, 2, 3, 4), y = 1:5)
5+
6+
ps <- ggplot(df, aes(x, y))+
7+
geom_smooth(stat = "identity", se = FALSE)
8+
9+
expect_equal(layer_data(ps)[c("x", "y")], df[order(df$x), ])
10+
})

0 commit comments

Comments
 (0)