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

position_dodge not working with categorical y and continous x variables #841

Open
fbnrst opened this issue Jul 15, 2024 · 1 comment
Open

Comments

@fbnrst
Copy link

fbnrst commented Jul 15, 2024

I illustrate the problem with the dots dataset:

import pandas as pd
from plotnine import *

dots = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/dots.csv')

Now, I plot with categorical x and continuous y variable:

(
    ggplot(dots, aes(y='coherence', x='align', color='choice'))
    + geom_point(position = position_dodge(width=0.8))
)

image

This worked fine. Now, I swap the x- and y-axis:

(
    ggplot(dots, aes(x='coherence', y='align', color='choice'))
    + geom_point(position = position_dodge(width=0.8))
)

image
Now, position_dodge did not work anymore.

ggplot2 gives me what I would expect (I execute the following in a Jupyter notebook)

%load_ext rpy2.ipython
%%R -i dots
library(ggplot2)
(
    ggplot(dots, aes(x=coherence, y=align, color=choice))
    + geom_point(position = position_dodge(width=0.8))
)

image

Software versions:

import session_info
session_info.show()
-----
pandas              2.2.2
plotnine            0.13.6
session_info        1.0.0
-----

Click to view modules imported as dependencies

-----
IPython             8.26.0
jupyter_client      8.6.2
jupyter_core        5.7.2
-----
Python 3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:23:07) [GCC 12.3.0]
Linux-3.10.0-1062.18.1.el7.x86_64-x86_64-with-glibc2.17
-----
Session information updated at 2024-07-15 16:29
@has2k1
Copy link
Owner

has2k1 commented Jul 15, 2024

This does not work because geoms have yet not acquired awareness of their orientation. The interim solution if possible is to use coord_flip to flip from the canonical orientation.

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

No branches or pull requests

2 participants