diff --git a/NEWS.md b/NEWS.md index c0416accec..19cdf00f9b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,13 @@ # ggplot2 3.0.0.9000 -* `geom_hex()` now understands the `size` and `linetype` aesthetics - (@mikmart, #2488). +* `geom_hex()` now understands the `size` and `linetype` aesthetics + (@mikmart, #2488). +* Data is no longer internally reordered when faceting. This makes it safer to + feed data columns into `aes()` or into parameters of geoms or stats. However, + doing so remains discouraged (@clauswilke). + + # ggplot2 3.0.0 ## Breaking changes diff --git a/R/facet-grid-.r b/R/facet-grid-.r index 435a98a7f4..c36d1fd20a 100644 --- a/R/facet-grid-.r +++ b/R/facet-grid-.r @@ -288,7 +288,7 @@ FacetGrid <- ggproto("FacetGrid", Facet, data$PANEL <- layout$PANEL[match(keys$x, keys$y)] } - data[order(data$PANEL), , drop = FALSE] + data }, draw_panels = function(panels, layout, x_scales, y_scales, ranges, coord, data, theme, params) { if ((params$free$x || params$free$y) && !coord$is_free()) { diff --git a/R/facet-wrap.r b/R/facet-wrap.r index 281ae1f2f7..ad7ba3ca23 100644 --- a/R/facet-wrap.r +++ b/R/facet-wrap.r @@ -199,7 +199,7 @@ FacetWrap <- ggproto("FacetWrap", Facet, keys <- plyr::join.keys(facet_vals, layout, by = names(vars)) data$PANEL <- layout$PANEL[match(keys$x, keys$y)] - data[order(data$PANEL), ] + data }, draw_panels = function(panels, layout, x_scales, y_scales, ranges, coord, data, theme, params) { if ((params$free$x || params$free$y) && !coord$is_free()) { diff --git a/tests/testthat/test-facet-map.r b/tests/testthat/test-facet-map.r index 5a7f1caa27..045b1c4781 100644 --- a/tests/testthat/test-facet-map.r +++ b/tests/testthat/test-facet-map.r @@ -31,7 +31,7 @@ test_that("grid: missing facet columns are duplicated", { loc_a <- panel_map_one(facet, df_a, plot_data = df) expect_equal(nrow(loc_a), 4) - expect_equal(loc_a$PANEL, factor(1:4)) + expect_equal(loc_a$PANEL, factor(c(1, 3, 2, 4))) loc_b <- panel_map_one(facet, df_b, plot_data = df) expect_equal(nrow(loc_b), 4) @@ -47,8 +47,8 @@ test_that("wrap: missing facet columns are duplicated", { loc_a <- panel_map_one(facet, df_a, plot_data = df) expect_equal(nrow(loc_a), 4) - expect_equal(loc_a$PANEL, factor(1:4)) - expect_equal(loc_a$a, c(1, 1, 2, 2)) + expect_equal(loc_a$PANEL, factor(c(1, 3, 2, 4))) + expect_equal(loc_a$a, c(1, 2, 1, 2)) loc_b <- panel_map_one(facet, df_b, plot_data = df) expect_equal(nrow(loc_b), 4)