Skip to content

geom_density and coord_flip don't work together #596

Closed

Description

@bhvieira
from plotnine import *
import numpy as np
import pandas as pd

df = pd.DataFrame({'values': np.random.normal(0,10,1000), 'group': ['a']*500 + ['b']*500})
# 
plot = (
    ggplot(df, aes(x = 'values', y='..density..', fill = 'group'))
    + geom_density(alpha = 0.7)
)

plot+coord_flip()

This results in:

output


For reference, the code in ggplot2 works fine:

library(ggplot2)

df = data.frame(values = rnorm(0,10,n = 1000), group = rep(c('a','b'), each = 500))
# 
plot = (
    ggplot(df, aes(x = values, y=..density.., fill = group))
    + geom_density(alpha = 0.7)
)

plot+coord_flip()

This results in:

outcome2

Activity

  1. bhvieira commented on Jun 1, 2022

    @bhvieira
    ContributorAuthor

    I'm positive this happens to other similar geoms btw, like geom_area and freq_poly

  2. bhvieira commented on Jun 2, 2022

    @bhvieira
    ContributorAuthor

    The culprit is something to do with fill_between in https://github.com/has2k1/plotnine/blob/main/plotnine/geoms/geom_ribbon.py#L56

  3. added 2 commits that reference this issue on Jun 2, 2022
    e02db98
    696a3bb
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