Skip to content

Added plot to histogram examples #19

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

DataGary
Copy link

@DataGary DataGary commented Sep 9, 2023

Added vlines with mean and median stat to histogram.
Adding the legend is tricky, this is why I thought to include the example.

@has2k1
Copy link
Owner

has2k1 commented Feb 27, 2024

Thank you for the contribution. If you want a legend, the right way to do it is to create a meaningful dataset. Legends / guides are created to help interpret variables and the variables are the columns of dataframe.

statistics = pd.DataFrame({
    "kind": ["mean", "median"],
    "value": [diamonds.carat.mean(), diamonds.carat.median()]
})

(
    ggplot(diamonds, aes(x='carat'))
    + geom_histogram(binwidth=0.1)
    + geom_vline(aes(xintercept="value", color="kind"), statistics, linetype='dashed', size=1)
    + labs(color='Legend')
)

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

Successfully merging this pull request may close these issues.

2 participants