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

Adjust expand_range() so zero range scales respect mul and add #161

Merged
merged 4 commits into from Jul 26, 2018

Conversation

dpseidel
Copy link
Collaborator

This seemed the most logical and minimal fix but if you have a different idea, let me know. Previously in expand_range(), zero_width was divided in half and added or subtracted on either side of the axis tick, resulting (from defaults) in a range of 1 (so when the original issue poster called geom_boxplot(width=0) there was no padding). Now instead, zero_width functions as our diff(range) and the equation matches that of non-zero ranges, respecting mul and add.

This fixes (the scales side of) the original issue (respecting mul and add parameters) but single ticket facets specifying a boxplot width ≥ than this range will still look tight. Looking into this further I found some weird bugs happening with the width argument to geom_boxplot and geom_violin. Will open a separate issue wherever appropriate once I have a better grasp on what's going on.

Fixes tidyverse/ggplot2#2281.

Does this deserve a news bullet for scales? What sorts of downstream tests should I run? Would those belong on this PR?

R/bounds.r Outdated
@@ -228,7 +228,7 @@ expand_range <- function(range, mul = 0, add = 0, zero_width = 1) {
if (is.null(range)) return()

if (zero_range(range)) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe extract out width to be something like:

width <- if (zero_range(range)) zero_width else diff(range)

@hadley
Copy link
Member

hadley commented Jul 25, 2018

Yes, needs a news bullet (can point to the ggplot2 issue)

I'd add a test just to make sure that mult and add affect expand_range() when the range is zero.

@hadley
Copy link
Member

hadley commented Jul 25, 2018

(and please double check that it fixes the motivating problem)

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.

Additive constant in expand= behaves unexpectedly on discrete axes in facets with one group
2 participants