Skip to content

Don't reorder data during faceting. #2694

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

Merged
merged 3 commits into from
Jul 10, 2018

Conversation

clauswilke
Copy link
Member

This addresses the underlying reason for #2693, data are reordered during faceting. With this patch, data order is not changed anymore in facet_grid() or facet_wrap(). This enables data vectors to be provided via aes() or as parameters.

library(ggplot2)

df <- data.frame(x = 1:4,
                 y = 1:4,
                 label1 = c("a", "b", "a", "b"),
                 label2 = c("c", "c", "d", "d"),
                 colour =  c("magenta", "green", "red", "cyan"))

ggplot(df, aes(x, y, colour = df$colour)) +
  geom_point(size = 3) +
  facet_wrap(~label1) +
  scale_colour_identity()

ggplot(df, aes(x, y, colour = df$colour)) +
  geom_point(size = 3) +
  facet_grid(label1~label2) +
  scale_colour_identity()

# things still work if some data points are removed by scale limits
ggplot(df, aes(x, y, colour = df$colour)) +
  geom_point(size = 3) +
  facet_wrap(~label1) +
  scale_x_continuous(limits = c(1.5, 3.5)) +
  scale_colour_identity()
#> Warning: Removed 2 rows containing missing values (geom_point).

ggplot(df, aes(x, y, colour = df$colour)) +
  geom_point(size = 3) +
  facet_grid(label1~label2) +
  scale_x_continuous(limits = c(1.5, 3.5)) +
  scale_colour_identity()
#> Warning: Removed 2 rows containing missing values (geom_point).

Created on 2018-06-10 by the reprex package (v0.2.0).

@hadley
Copy link
Member

hadley commented Jun 11, 2018

Let's hold of merging this until after the release.

@hadley
Copy link
Member

hadley commented Jul 8, 2018

Can you please add a news bullet?

Thanks for diagnosing this — it's going to fix a lot of broken plots in the wild!

@clauswilke clauswilke force-pushed the issue-2693-facets branch from 5f42807 to db34b88 Compare July 9, 2018 03:25
@clauswilke
Copy link
Member Author

News bullet added.

NEWS.md Outdated
(@mikmart, #2488).

# ggplot2 3.0.0
## Minor bug fixes and improvements
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this heading please? It's easier to add these just before release. (http://style.tidyverse.org/news.html#news-bullets)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good you flagged that. I had also messed up the main heading in the rebase. Should be good now.

@clauswilke clauswilke merged commit 9b640c5 into tidyverse:master Jul 10, 2018
@clauswilke clauswilke deleted the issue-2693-facets branch July 10, 2018 13:27
@lock
Copy link

lock bot commented Jan 6, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jan 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants