Skip to content

scale_x_discrete with numeric drops axis with no warning #2970

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

Closed
ptoche opened this issue Oct 30, 2018 · 2 comments
Closed

scale_x_discrete with numeric drops axis with no warning #2970

ptoche opened this issue Oct 30, 2018 · 2 comments
Labels
feature a feature request or enhancement scales 🐍

Comments

@ptoche
Copy link

ptoche commented Oct 30, 2018

Discrete scales are not designed to work with numeric data, this is clear. However, a careless/naive user could attempt to apply a discrete scale to continuous data. I suggest issuing a warning when a discrete scale is applied to continuous data.

Use case: I absent-mindedly tried to apply scale_x_discrete to a continuous scale (the data was intended to be discrete, but was actually numeric) and discovered that the axis was dropped altogether and no warning issued. I hadn't noticed the problem until I used expand_scale inside the scale_x_discrete. Before that I was able to set limits inside scale_x_discrete without losing the axis, so alarm bells hadn't sounded. A warning would save time debugging and/or potentially avoid producing an incorrect plot.

library(ggplot2)

# factor/character + scale_x_discrete + expand_scale 
ggplot(mpg, aes(as.factor(hwy), displ)) +
    geom_point() +
    scale_x_discrete(expand = expand_scale(add = c(5, 5))) 

# num/int + scale_x_discrete + expand_scale : drops the x axis
ggplot(mpg, aes(hwy, displ)) +
    geom_point() +
    scale_x_discrete(expand = expand_scale(add = c(5, 5))) 

# num/int + scale_x_continuous + expand_scale
ggplot(mpg, aes(hwy, displ)) +
    geom_point() +
    scale_x_continuous(expand = expand_scale(add = c(10, 10))) 

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

@ptoche ptoche changed the title scale_x_discrete with numeric no warning + drops the axis scale_x_discrete with numeric drops axis with no warning Nov 6, 2018
@paleolimbot paleolimbot added feature a feature request or enhancement scales 🐍 labels May 23, 2019
@hadley
Copy link
Member

hadley commented Jun 18, 2019

This appears to be a deliberate choice:

expand_range4(c_range, expand)
— so it would require extremely careful analysis to determine if this was always a false positive or is actually needed for existing plots in the wild. It's my sense that this analysis would be sufficiently time consuming as not to be worthwhile, given the payoff.

@hadley hadley closed this as completed Jun 18, 2019
@lock
Copy link

lock bot commented Dec 15, 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 Dec 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement scales 🐍
Projects
None yet
Development

No branches or pull requests

3 participants