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

scale_discrete(drop=True) has no effect (it incorrectly includes unused categories) #139

Closed
jdanbrown opened this issue May 19, 2018 · 1 comment
Labels

Comments

@jdanbrown
Copy link
Contributor

from pandas.api.types import CategoricalDtype

class_cat = CategoricalDtype(
    ordered=True,
    categories=['foo', 'bar'] + list(mpg['class'].unique()),
)

Unused categories are incorrectly included with drop=True (the default):

(mpg
    .astype({'class': 'str'})
    .astype({'class': class_cat})
    .pipe(ggplot)
    + geom_bar(aes(x='class'))
    + scale_x_discrete(drop=True)
)

image

Same as drop=False:

(mpg
    .astype({'class': 'str'})
    .astype({'class': class_cat})
    .pipe(ggplot)
    + geom_bar(aes(x='class'))
    + scale_x_discrete(drop=False)
)

image

@has2k1 has2k1 added the bug label May 19, 2018
@has2k1 has2k1 closed this as completed in 9e52a25 May 19, 2018
@jdanbrown
Copy link
Contributor Author

Looks great, thanks!

(mpg
    .astype({'class': 'str'})
    .astype({'class': class_cat})
    .pipe(ggplot)
    + geom_bar(aes(x='class'))
)

a

(mpg
    .astype({'class': 'str'})
    .astype({'class': class_cat})
    .pipe(ggplot)
    + geom_bar(aes(x='class'))
    + scale_x_discrete(drop=True)
)

b

(mpg
    .astype({'class': 'str'})
    .astype({'class': class_cat})
    .pipe(ggplot)
    + geom_bar(aes(x='class'))
    + scale_x_discrete(drop=False)
)

c

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

No branches or pull requests

2 participants