Join 10350+ others. No spamming.
I promise!

Follow us at github.


slowkow/ggrepel

367

slowkow / ggrepel

R

:round_pushpin: Repel overlapping text labels away from each other.


READ ME

ggrepel

GitHub Version Build Status CRAN_Status_Badge CRAN_Downloads_Badge

Overview

ggrepel provides geoms for ggplot2 to repel overlapping text labels.

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

Installation

# The easiest way to get ggrepel is to install it from CRAN:
install.packages("ggrepel")

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

Usage

See the vignette for the code behind these examples:

Contributing

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

directlabels

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.

wordcloud

Pretty word clouds.

The wordcloud package implements a spiraling algorithm to prevent text labels from overlapping each other.

FField

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.