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

Feature request / offer: element_text_repel() #248

Open
teunbrand opened this issue Jan 13, 2024 · 0 comments · May be fixed by #266
Open

Feature request / offer: element_text_repel() #248

teunbrand opened this issue Jan 13, 2024 · 0 comments · May be fixed by #266

Comments

@teunbrand
Copy link

Hi Kamil and others,

I have been musing for a while that it'd be great if we could have axis text repelled.
This could be great for e.g. heatmaps that highlight only some rows or columns.
For example, in the plot below there is ample spacing for 'Texas', 'New York' and 'California' but the states starting with 'M' are a little bit cramped.

library(ggplot2)

df <- reshape2::melt(as.matrix(USArrests))

ggplot(df, aes(Var2, Var1, fill = value)) +
  geom_tile() +
  scale_y_discrete(
    breaks = c("Missouri", "Mississippi", "Minnesota", "Michigan", 
               "Massachusetts", "New York", "California", "Texas")
  )

Created on 2024-01-13 with reprex v2.0.2

I'm reasonably confident that it should be possible to capture that axis repelling into an element_text_repel() theme setting that you can feed to the axis text elements.
If this is something you think might be a good fit for {ggrepel}, I'll be happy to prepare a PR and discuss further.
Thanks for reading!

@teunbrand teunbrand linked a pull request Dec 2, 2024 that will close this issue
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 a pull request may close this issue.

1 participant