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

abnormal legend #757

Open
wangjiawen2013 opened this issue Mar 12, 2024 · 3 comments
Open

abnormal legend #757

wangjiawen2013 opened this issue Mar 12, 2024 · 3 comments

Comments

@wangjiawen2013
Copy link

wangjiawen2013 commented Mar 12, 2024

Hi,
I made a figure using:

ggplot(obs,aes(x='library_id',y='percentage',fill='leiden')) + geom_bar(stat='identity') + scale_fill_manual(values=adata.uns['leiden_colors']) + theme(axis_text_x=element_text(angle=45))

The legend is weired, some items were lost (1, 19, 20, and so on):
image

When using plotnine_prism() with the same data, it looks well:
image

I don't want to use plotnine_prism() theme, so how to adjust the legend ?

@has2k1
Copy link
Owner

has2k1 commented Mar 12, 2024

You can set the number of columns that works for you

+ guides(fill=guide_legend(ncol=2))

and/or adjust the height of the keys

+ theme(legend_key_height=10)

@wangjiawen2013
Copy link
Author

Thanks, I'll try it.
And can plotnine adjust the columns automatically according to the number the keys ? When there are less keys, the legend is one column, while it's two columns when there are lots keys ?

@has2k1
Copy link
Owner

has2k1 commented Mar 13, 2024

Thanks, I'll try it. And can plotnine adjust the columns automatically according to the number the keys ? When there are less keys, the legend is one column, while it's two columns when there are lots keys ?

No it does not, but it is something we could look into. While I don't think the problem of the overflowing legend can go away entirely, it could become an even rarer edge-case.

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