Skip to content

Facet with geom_abline throwing errors and not working #196

Closed

Description

@patrick-miller

I am currently running into a couple errors when attempting to plot an abline for different facets. The first error involves not being able to set different slopes for different facets. The second error involves facet variables being reserved names.

Below is a reproducible example under version 0.4.0:

import plotnine as p9
import pandas as pd
df = pd.DataFrame({'list':['a','a','b','b'], 'x':[1,2,3,4], 'y':[1,2,6,8]})
df['category'] = df['list']
df_slope = pd.DataFrame({'category':['a','b'], 'intercept':[0,0], 'slope':[1,2]})
print(p9.__version__)

Plotting points with a facet works as expected:

(p9.ggplot(df, p9.aes(x='x', y='y')) + 
    p9.geom_point() +
    p9.facet_wrap('~category'))

image

Attempting to plot an abline with a facet throws an error.

(p9.ggplot(df_slope, p9.aes(intercept='intercept', slope='slope')) +
    p9.geom_abline() +
    p9.facet_wrap('~category'))

image

Attempting to plot both points and an abline does not throw an error, but it doesn't take the specified slope of 2 for facet b:

(p9.ggplot(df, p9.aes(x='x', y='y')) + 
    p9.geom_point() +
    p9.geom_abline(mapping=p9.aes(intercept='intercept', slope='slope'),
                   data=df_slope) +
    p9.facet_wrap('~category'))

image

Finally, there is another error that I'm getting when the name of the facet variable is reserved. When the variable is not reserved, everything works:

(p9.ggplot(df, p9.aes(x='x', y='y')) + 
    p9.geom_point() +
    p9.geom_abline(intercept=0, slope=1) +
    p9.facet_wrap('~category'))

image

When the facet variable is reserved, I get another error:

(p9.ggplot(df, p9.aes(x='x', y='y')) + 
    p9.geom_point() +
    p9.geom_abline(intercept=0, slope=1) +
    p9.facet_wrap('~list'))

image

It seems like this issue has come up in the past, but it was thought to be fixed (#48).

Activity

  1. has2k1 commented on Sep 26, 2018

    @has2k1
    Owner

    That is a bug. Here is a workaround

    (p9.ggplot(df, p9.aes(x='x', y='y')) + 
        p9.geom_point() +
        p9.geom_abline(p9.aes(intercept='intercept', slope='slope'),
                       data=df_slope) +
        p9.facet_wrap('~category'))
  2. patrick-miller commented on Sep 26, 2018

    @patrick-miller
    Author

    Thank you for the quick response, that works for both the issues.

  3. added a commit that references this issue on Oct 1, 2018
    50465ba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions