ggrepel is an R package that provides geoms for ggplot2 to repel overlapping text labels:
geom_text_repel()geom_label_repel()
Text labels repel away from each other, away from data points, and away from edges of the plotting area.
library(ggrepel)
ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
geom_text_repel() +
geom_point(color = 'red') +
theme_classic(base_size = 16)
Check it out on GitHub 👇
Here’s an animation that shows how the repulsion and attraction algorithm works:
Thanks to all of the wonderful people who have contributed issues and pull requests over the years! 🙏
Reply by Email