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

Conversation

@clauswilke
Copy link
Member

@clauswilke clauswilke commented Jun 10, 2018

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 hadley commented Jun 11, 2018

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

@hadley
Copy link
Member

@hadley 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 Jul 9, 2018
@clauswilke clauswilke force-pushed the issue-2693-facets branch from db34b88 to 6460e56 Jul 10, 2018
@clauswilke
Copy link
Member Author

@clauswilke clauswilke commented Jul 10, 2018

News bullet added.

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

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

@hadley hadley Jul 10, 2018

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

@clauswilke clauswilke Jul 10, 2018

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

hadley
hadley approved these changes Jul 10, 2018
@clauswilke clauswilke merged commit 9b640c5 into tidyverse:master Jul 10, 2018
4 checks passed
@clauswilke clauswilke deleted the issue-2693-facets branch Jul 10, 2018
@lock
Copy link

@lock 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
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants