Provides text and label geoms for 'ggplot2' that help to avoid overlapping text labels. Labels repel away from each other and away from the data points.
ggrepel provides geoms for ggplot2 to repel overlapping text labels:
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)
install.packages("ggrepel")# Or get the the development version from GitHub:# install.packages("devtools")devtools::install_github("slowkow/ggrepel")# Or use the install-github.me servicesource("")
See the vignette for the code behind these examples:
Please submit an issue to report bugs or ask questions.
Please contribute bug fixes or new features with a pull request to this repository.
Sebastian Theophil, Arno Schödl
feature labeling problem. The goal is to position the largest number of point labels such that they do not intersect each other or their points. First we present an algorithm using a greedy algorithm with limited lookahead. We then present an algorithm that iteratively regroups labels, calling the first algorithm on each group, thereby identifying a close to optimal labeling order. The presented algorithm is being used in a commercial product to label charts, and our evaluation shows that it produces results far superior to those of other labeling algorithms.
This might be a good start for a revision of ggrepel.
A small library for automatically adjusting text position in matplotlib plots to minimize overlaps.
Ilya Flyamer's Python library that extends matplotlib.
An extensible framework for automatically placing direct labels onto multicolor 'lattice' or 'ggplot2' plots. Label positions are described using Positioning Methods which can be re-used across several different plots. There are heuristics for examining "trellis" and "ggplot" objects and inferring an appropriate Positioning Method.
Pretty word clouds.
wordcloud package implements a spiraling algorithm to prevent text
labels from overlapping each other.
Force field simulation of interaction of set of points. Very useful for placing text labels on graphs, such as scatterplots.
I found that functions in the
FField package were not ideal for repelling
overlapping rectangles, so I wrote my own.
See this gist for examples of how to use the
geom_label_repel(..., point.padding=NA). Reported by @mlell in
See below for other changes made after ggrepel 0.7.0
Add support for
position parameter. See issue 69. This allows us to
add text labels to points positioned with
Please note that this feature will not work with ggplot2 2.2.1 or older.
FIXES (thanks to @AliciaSchep and @aphalo)
Fix warning about
hjust. See issue 93.
Fix bug when subset of points is labeled in
See issue 92.
CHANGES (thanks to @AliciaSchep)
Add code to avoid intersecting line segments. See issue 34.
Fix intersection between lines and rectangles, to reproduce the same aesthetically pleasant behavior as in version 0.6.5.
This is an improvement on the sloppy implementation introduced in 0.6.8. See commit 28633d for more information.
Reproduce identical plots by usign
seed = 1 to set the seed in
geom_label_repel(). By default, no seed will be set.
CHANGES (thanks to @seaaan)
unit()instead of only units. See issue 79.
FIXES (thanks to @zkamvar)
ylim. See pull 74.
FIXES (thanks to @pcroteau)
facet_gridthat have no labeled points. See pull 70.
NEW FEATURE (thanks to @AliciaSchep)
geom_label_repel(). See pull 68.
CHANGES (thanks to @lukauskas)
geom_label_repel(). See pull 67.
FIXES (thanks to @fawda123)
parse = TRUEin
geom_label_repel(). See issue 60.
CHANGES (thanks to @jiho)
geom_label_repel() to control text, label
background, label border, and segment.
segment.colour as well as
By default, map text color and text alpha to the segment color unless they are overridden.
FIXES (thanks to @jiho)
coord_polar(). See issue 56.
point.padding=NAto ignore data points in repulsion calculations.
Stop the labels from escaping the plot boundaries instead of applying a force at the boundary.
allow recreating identical plots. Fixes issue 33.
repel_boxes.cpp. Dampen forces to tune how the labels move. The result looks better, at least for the examples in the vignette.
segment.alpha as an option for
angle aesthetic for
geom_text_repel(), the same way as done in
nudge_y out of the aesthetics function
makes ggrepel consistent with ggplot2 functions
geom_label(). Backwards incompatible with 0.5.1.
segment.color as an option for
repel_boxes.cpp. Do not weight repulsion force by ratios of bounding
box heights and widths. This seems to perform better, especially after
rotating text labels.
point.paddingso that users can configure how far labels are pushed away from data points.
Optimize C++ code for a 2.5X speed improvment.
Delete unnecessary .Rd files.
geom_label_repel(). Now there is no gap between the end of the segment and the label border.
spring_force()so that it never returns NaN.
nudge_yto better control positioning of labels.
arrow parameter to allow plotting arrows that point to the labeled data
points rather than plain line segments.
Always draw segments, even if the labeled point is very close to the label.
point.padding so that horizontal and vertical padding is calculated
Tweak forces to improve layout near borders and in crowded areas.
Add new parameter
point.padding to add padding around the labeled points.
The line segment will stop before reaching the coordinates of the point. The
text labels are also now padded from the line segment to improve legibility.
Add volcano plot to the vignette usage examples.
Add Travis continuous integration to test against R-devel, R-release, and R-oldrel.
Dampen repulsion force to slightly improve algorithm efficiency.
Remove unused imports:
Update NAMESPACE with new version of roxygen.
Use spring force to attract each label to its own point.
Change default maximum iterations from 10,000 to 2000.
Update man pages.
Remove unused code.
Remove unsupported parameters:
Remove unused imports.
Add fudge width to help with legends.
expand=TRUE to allow text to be placed in the expanded plot area.
Add man/ folder.
Add links to ggplot2 docs in vignette.
repel_boxes(), just for your reference.