round_pushpin Repel overlapping text labels away from each other.

License: GPL-3.0

Language: R

Keywords: cran, ggplot2, rstats, text, visualization


Build Status CRAN_Status_Badge CRAN_Downloads_Badge


ggrepel 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.

ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
  geom_text_repel() +
  geom_point(color = 'red') +
  theme_classic(base_size = 16)


# The easiest way to get ggrepel is to install it from CRAN:

# Or get the the development version from GitHub:
# install.packages("devtools")

# Or use the service


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.

Related work

Academic Papers

An Efficient Algorithm for Scatter Chart Labeling

Sebastian Theophil, Arno Schödl

This paper presents an efficient algorithm for a new variation of the point 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 D3 plug-in for automatic label placement using simulated annealing

Evan Wang's plugin that extends D3 v3. He also described the approach in his paper.


A D3 layout that places labels avoiding overlaps, with strategies including simulated annealing, greedy and a strategy that removes overlapping labels.

Colin Eberhardt's implementation for D3 v4.


A Voronoi tessellation can assist in labeling scatterplots. The area of the Voronoi cell associated with each point determines whether the point is labeled: points with larger cells tend to have room to accommodate labels.



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.

The 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 wordcloud and FField packages with ggplot2.

Project Statistics

Sourcerank 15
Repository Size 18 MB
Stars 613
Forks 72
Watchers 28
Open issues 13
Dependencies 16
Contributors 12
Tags 31
Last updated
Last pushed

Top Contributors See all

Kamil Slowikowski Sean Hughes Alicia Schep Saulius Lukauskas Jean-Olivier Irisson Dang Trung Kien Malcolm Barrett Hiroaki Yutani Amir Masoud Abdol Zhian N. Kamvar Christophe Dervieux Ryan C. Thompson

Packages Referencing this Repo

Automatically Position Non-Overlapping Text Labels with 'ggplot2'
Latest release 0.8.1 - Updated - 613 stars

Recent Tags See all

0.8.0 May 09, 2018
0.7.3 February 09, 2018
0.7.2 December 19, 2017
0.7.1 November 19, 2017
0.7.0 September 28, 2017
0.6.12 July 17, 2017
0.6.11 July 08, 2017
0.6.10 May 12, 2017
0.6.9 March 07, 2017
0.6.8 February 12, 2017
0.6.7 January 09, 2017
0.6.6 November 29, 2016
0.6.5 November 23, 2016
0.6.4 November 08, 2016
0.6.3 October 14, 2016

Interesting Forks See all

round_pushpin Repel overlapping text labels away from each other.
R - Last pushed - 2 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-05-07 08:12:20 UTC

Login to resync this repository