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

Ensure all keys in guide_bins(..., reverse = TRUE) #4442

Merged
merged 1 commit into from
Apr 27, 2021

Conversation

thomasp85
Copy link
Member

Fix #4210

This fixes a bug when reversing the bin guide because the terminal row that held irrelevant NA values ended up as the first row

@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Apr 22, 2021
Comment on lines +167 to +172
if (guide$reverse) {
key <- key[rev(seq_len(nrow(key))), ]
# Move last row back to last
aesthetics <- setdiff(names(key), ".label")
key[, aesthetics] <- key[c(seq_len(nrow(key))[-1], 1), aesthetics]
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we reverse the bins before appending NA at the bottom?

  bin_at <- scale$map(bin_at)
  if (guide$reverse) {
    bin_at <- rev(bin_at)
  }
  key <- new_data_frame(setNames(list(c(bin_at, NA)), aes_column_name))
  key$.label <- scale$get_labels(all_breaks)

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is that bin_at and the derivatives gets calculated at two different branches so we would have to duplicate the logic there

Copy link
Member

Choose a reason for hiding this comment

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

bin_at and the derivatives gets calculated at two different branches

I meant something like this, not inside the if branches.

master...yutannihilation:poc/pr-4442

Since I needed some minutes to figure out what the added code does, I was hoping to make the logic simple, but it seems my attempt is no shorter than this pull request... Please ignore my comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Top key missing in guide_bins when reverse = TRUE
2 participants