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

Plot forgets the order of categorical values #381

Closed
swenlaur opened this issue Apr 9, 2020 · 1 comment
Closed

Plot forgets the order of categorical values #381

swenlaur opened this issue Apr 9, 2020 · 1 comment
Labels

Comments

@swenlaur
Copy link

swenlaur commented Apr 9, 2020

If you draw a plot with a discrete x-scale and the first geom does not use all x-values and the second geom introduces new values that should be in front of old ones they are added to the end. Example code snippet

VarNames = CategoricalDtype(['x_{}'.format(i) for i in range(10)], ordered = True)
df1 = DataFrame({'x': ['x_1', 'x_2']}).assign(x = lambda df: df['x'].astype(VarNames))
df2 = DataFrame({'x': ['x_0', 'x_2']}).assign(x = lambda df: df['x'].astype(VarNames))

p = ggplot(df1) + geom_point(aes(x =  'x', y = 'x'), size=6) 
p = p + geom_point(aes(x =  'x', y = 'x'), data=df2, color = 'red', size = 3)
p 
@has2k1 has2k1 added the bug label Apr 9, 2020
@TyberiusPrime
Copy link
Contributor

obviously, this is a bug.
Quick workaround for now, specify the limits on the x-scale:

p = p + scale_x_discrete(limits=VarNames.categories)

@has2k1 has2k1 added the Addressed in Next Version The issue has been fixed, but it has not in the current official release. label Apr 14, 2020
@has2k1 has2k1 removed the Addressed in Next Version The issue has been fixed, but it has not in the current official release. label Jun 5, 2020
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

3 participants