Automatically Position Non-Overlapping Text Labels with 'ggplot2'

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

Build Status CRAN_Status_Badge CRAN_Downloads_Badge

Overview

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.

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 examples page to learn more about how to use ggrepel in your project.

Examples

Click one of the images below to go to see the code example:

Hide some of the labels Always show all labels, even when they have too many overlaps Do not repel labels from data points Do not repel labels from plot (panel) edges Expand the scale to make room for labels Always (or never) draw line segments Make curved line segments or arrows Repel labels from data points with different
sizes Limit labels to a specific area Remove “a” from the legend Align labels on the top or bottom edge Align labels on the left or right edge Using ggrepel with stat_summary() Justify multiple lines of text with hjust Label jittered points Nudge labels in different directions with ggpp Label sf objects Shadows (or glow) under text labels Verbose timing information Word cloud Polar coordinates Unicode characters (Japanese) Mathematical expressions

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.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("ggrepel")

0.9.8 by Kamil Slowikowski, 7 months ago


https://ggrepel.slowkow.com/, https://github.com/slowkow/ggrepel


Report a bug at https://github.com/slowkow/ggrepel/issues


Browse source code at https://github.com/cran/ggrepel


Authors: Kamil Slowikowski [aut, cre] (ORCID: , Teun van den Brand [ctb] (ORCID: , Alicia Schep [ctb] , Sean Hughes [ctb] , Trung Kien Dang [ctb] , Saulius Lukauskas [ctb] , Jean-Olivier Irisson [ctb] (ORCID: , Zhian N Kamvar [ctb] , Thompson Ryan [ctb] , Dervieux Christophe [ctb] (ORCID: , Yutani Hiroaki [ctb] , Pierre Gramme [ctb] , Amir Masoud Abdol [ctb] , Malcolm Barrett [ctb] , Robrecht Cannoodt [ctb] (ORCID: , Michał Krassowski [ctb] (ORCID: , Michael Chirico [ctb] , Pedro Aphalo [ctb] , Francis Barton [ctb]


Documentation:   PDF Manual  


GPL-3 | file LICENSE license


Imports grid, Rcpp, rlang, S7, scales, withr

Depends on ggplot2

Suggests knitr, rmarkdown, testthat, svglite, vdiffr, gridExtra, ggpp, patchwork, devtools, prettydoc, ggbeeswarm, dplyr, magrittr, readr, stringr, marquee, rsvg, sf

Linking to Rcpp


Imported by AdverseEvents, AgeTopicModels, AgriDataTools, AgroR, AgroTech, Anaconda, BAQM, BRCore, BasketballAnalyzeR, BioThermR, CA3variants, CAESAR.Suite, CAinterprTools, CLONETv2, CRMetrics, ChemoSpecUtils, CimpleG, ClustAssess, CoNI, CoreMicrobiomeR, Coxmos, CytoProfile, DEET, DeSciDe, EIX, EpiTest, EstimateBreed, EvoPhylo, FactoMineR, Factoshiny, FinanceGraphs, FunnelPlotR, GABB, GDAtools, GOCompare, GREENREG, GUniFrac, HIViz, HLMdiag, HYPEtools, HetSeq, JPSurv, LSX, LipidomicsR, MAIHDA, MBAnalysis, MCAvariants, MassWateR, MetAlyzer, MetaNet, MicrobiomeStat, MuPETFlow, MultANOVA, MultiGroupO, MultiResponseR, MultiTraits, NACHO, NOVA, NetworkChange, NetworkInference, NeuralSTATIS, NeuralSens, ODMeans, OVtool, OmicFlow, PAC, PCBS, PathwaySpace, PsychWordVec, PvSTATEM, R4GoodPersonalFinances, RCPA, RChASM, RCtest, RGCCA, RIFanalysis, RNAseqQC, RSDA, RastaRocket, ReporterScore, ResIN, RoME, SHELF, SPARRAfairness, SensoMineR, SerolyzeR, Seurat, SkeletalVis, Slick, SpaCCI, SparseBiplots, Spectran, StabilizedRegression, StepReg, Umatrix, UnalR, VisualizeSimon2Stage, VoronoiBiomedPlot, WMFM, XYomics, Xplortext, admetshiny, adproclus, agregR, agriutilities, apm, aquats, auditor, autoGO, autostsm, baggr, barrel, bayesammi, bibliometrix, canadianmaps, caplot, caresid, cellGeometry, choroplethr, cinaR, clustrd, clustree, coda.plot, colorrepel, comorosmaps, conos, conquestr, conserveR, cophescan, correlationfunnel, corrr, dampack, dartR.sim, densityClust, diceplot, diffwrap, dilp, discourseGT, dittoViz, dmbc, douconca, dtwclust, dualScale, eat, epiomics, exmort, eyetools, facetsviz, factoextra, fastTopics, ferrn, fgeo.plot, fspls2, gMOIP, gWQS, gaQSAR, geneNR, geofacet, geosimilarity, germinationmetrics, gfer, ggExametrika, ggFishPlots, ggScatRidges, ggauto, ggbrain, ggdag, ggdemetra, ggfacto, gghalfnorm, gghighlight, gglycan, ggmosaic2, ggnetwork, ggplotplus, ggpubr, ggquickeda, ggraph, ggrecipes, ggseqplot, ggspectra, ggstatsplot, ggtangle, ggvegan, ggvolc, ggvolcano, giniCI, gosset, graphPAF, gwaRs, gwasforest, healthyR.ai, henna, hespdiv, hidecan, iCellR, icertool, idealstan, idm, inDAGO, inTextSummaryTable, influenceAUC, interca, investlabr, isobxr, ivd, ivdtools, ivolcano, iwaqr, jmv, jointVIP, jrSiCKLSNMF, jsmodule, keyATM, kindisperse, klovan, konfound, lame, lapop, lessSEM, mFD, mSigPlot, manhplot, matuR, mda.biber, metaGE, metainsight, metan, metaprotr, mglasso, mixpoissonreg, mizer, modelskill, morepls, multiscape, myTAI, necountries, netify, netmeta, nzilbb.vowels, o2plsda, omicsTools, opImputation, ordr, orisma, overviewR, pacta.loanbook, pacta.multi.loanbook, palaeoSig, patterncausality, pcreg, pctax, phynotype, plinkQC, plotthis, politeness, promor, protti, psre, qtl2ggplot, quanteda.textplots, r2dii.plot, r4lineups, rSRD, radiant.model, radiant.multivariate, randomForestExplainer, raptools, rbiom, riemannianStats, rnaCrosslinkOO, rnmamod, robustT2, rpcss, rwicc, sNPLS, sappviz, scCustomize, scNPM, scPairs, sccore, scrutiny, semfindr, semhelpinghands, semlbci, senseweight, shapviz, shoredate, sistmr, skewlmm, slendr, snplinkage, soc.ca, spatialGE, spectrakit, spotoroo, squat, statAfrikR, statgenSTA, statisR, stminsights, subscreen, success, swfscMisc, teal.modules.clinical, teal.modules.general, tepr, tetraclasse, text, themescopeR, thisplot, tidyestimate, tidyplots, tidywater, tmod, topr, triptych, unhcrthemes, unityForest, vannstats, visae, vistime, visualpred, visvow, vivainsights, wilson, wordmap, wpa.

Depended on by CAvariants, FactoClass, SetMethods, func2vis, lmap.

Suggested by AIDA, AlleleShift, AntibodyForests, AquaBEHER, BAwiR, BKBreed, BKMutate, BKQualit, BOLDNODE, BioGSP, BiplotML, Census2016, ConsensusOPLS, DALEXtra, DataVisualizations, FeNEU, FossilSim, GauPro, Guerry, HawaSpatial, IRTM, LikertMakeR, LorMe, MSEtool, MSUthemes, NHSRdatasets, OlinkAnalyze, OlinkAnalyzeVignettes, ProFAST, Rbearcat, SCpubr, Signac, TextMiningGUI, TransHDM, UCSCXenaShiny, ZIprop, actiwalkability, aum, baseballr, bayesiansurpriser, biplotEZ, birddog, blvim, bmstdr, brainGraph, card, cfbfastR, circumplex, coFAST, cogmod, confoundvis, countryatlas, coveffectsplot, covid19br, craftgrn, csalert, csmaps, cubble, dartR, dartR.base, deaviz, deeptime, diffHTS, dyngen, easyRasch2, easyRaschBayes, easybio, ecocomDP, epmfd, ergm.multi, ezplot, fairmodels, fastRhockey, fastrda, feasts, fect, forrel, genekitr, geofi, ggDoE, ggalluvial, ggautomap, ggbreak, ggchangepoint, ggeffects, ggfocus, ggformula, ggfortify, gggenomes, gghotelling, ggiraph, ggmapinset, ggmultiglyph, ggpedigree, ggpicrust2, ggpmisc, ggpop, ggpp, ggspark, ggspatial, ggsurveillance, ggtime, ggwordcloud, grandR, harmony, hoopR, httk, httkexamples, immunarch, insurancerating, kidsides, lande, lcars, limonaid, lisat, locuszoomr, logitr, lorbridge, manureshed, marginaleffects, mdsOpt, microeco, mongolmaps, mosaic, mrIML, multimedia, multivarious, mvMAPIT, mvgam, mwmap, numbat, nuts, oddsapiR, opticskxi, palimpsestr, parsnip, pcutils, pixarfilms, positron.tutorials, precisely, projpred, r4ds.tutorials, r4pde, rTPC, readyomics, rempsyc, repoRter.nih, ribd, rioplot, rliger, rmacrostrat, rnaturalearth, robustmatrix, roroph, rtrek, rxode2, salmonMSE, see, sigminer, signs, sjPlot, sotkanet, spinifex, staRdom, starvz, streamDAG, talkr, textplot, threesixtygiving, tidybayes, tidygeocoder, topicmodels.etm, topolow, ubiquity, usmap, wehoop, wpeR, wrappedtools, xkcd, xmap.


See at CRAN