Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't reorder data during faceting. #2694

Merged
merged 3 commits into from Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion R/facet-grid-.r
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion R/facet-wrap.r
Expand Up @@ -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()) {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-facet-map.r
Expand Up @@ -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)
Expand All @@ -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)
Expand Down