Tool:ggrepel: repel overlapping text labels in ggplot2
0
15
Entering edit mode
9.0 years ago
Kamil ★ 2.3k

ggrepel is an R package that provides geoms to repel overlapping text labels away from each other in a plot created by ggplot2.

Installation

Install the stable release from CRAN:

install.packages('ggrepel')

Or, install the latest development version from github:

install.packages('devtools')
devtools::install_github('slowkow/ggrepel')

Examples

See the vignette for more usage examples:

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

animation of ggrepel

R visualization • 17k views
ADD COMMENT
1
Entering edit mode

You might want to indicate that it's dependant on ggplot2 version 2.0+, as it took a while for me to figure out why it was silently failing to install.

ADD REPLY
0
Entering edit mode

Thanks for catching this! I missed it.

ADD REPLY
0
Entering edit mode

Thank you, Thank you. A million times thank you.

ADD REPLY
0
Entering edit mode

Well done! This great!

ADD REPLY
0
Entering edit mode

Dear Kamil,

great implementation regarding the text labels, especially for volcano plots with a lot of gene symbols !! I have only one small question: if still with the similar code above, I have still some text labels not clearly shown, by which arguments can I control or improve the distance between these possible overlapping layers ?

Best,
Efstathios

ADD REPLY
1
Entering edit mode

Efstathios, thanks for your question!

Please see if the examples in the vignette might help to learn about the arguments. Try 'box.padding'.

If you need further help, could I ask you to continue this discussion in a new issue on the github repo? If you do not use github, feel free to create a new post on this page, under "Add your answer". Consider sharing a code example and an image of the plot to clarify the problem.

ADD REPLY
0
Entering edit mode

Dear Kamil,

i will check first the additional capabilities and your suggestions-if i continue having issues, i will post the code and a supportive image !!

Thanks,

Efstathios

ADD REPLY
0
Entering edit mode

Thanks for the ggrepel Kamil. I also suggested this to someone last month

ADD REPLY
0
Entering edit mode

Dear Kamil, Thanks a lot for the ggrepel!

One question: is it possible to remove linking lines between datapoints and labels that are close to each other, e.g. for Chrysler Imperial (bottom right corner) or Toyota Corolla (top left corner) on your example. This will make the plot even nicer.

Thanks in advance, Grant

ADD REPLY

Login before adding your answer.

Traffic: 2161 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6