Questions tagged [ggrepel]
ggrepel: Repulsive Text and Label Geoms for '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.
20
questions
225
votes
3
answers
405k
views
Label points in geom_point
The data I'm playing with comes from the internet source listed below
nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv", sep=",")
What I want to do, is create a 2D points graph ...
16
votes
1
answer
15k
views
How do I include italic text in geom_text_repel or geom_text labels for ggplot?
Is it possible to pass partially italicized text labels into ggplot? I have tried using the expression and italic commands (expression(paste(italic("some text")))), but these cannot be passed into a ...
5
votes
2
answers
1k
views
Override horizontal positioning with ggrepel
I'm working on a chart similar to a slopegraph, where I'd like to put labels along one or both sides with ample blank space to fit them on both sides. In cases where labels are very long, I've wrapped ...
7
votes
1
answer
1k
views
How to combine repelling labels and shadow or halo text in ggplot2?
There are some nice solutions for either repelling labels in ggplot2 (e.g. ggrepel) or shadow text for labels (e.g. ggshadowtext and this answer). But nothing that allows us to combine these two ...
6
votes
2
answers
4k
views
Add directlabels to geom_smooth rather than geom_line
I recognize that this question is a close duplicate of this one, but the solution there no longer works (using method="last.qp"), so I'm asking it again.
The basic issue is that I'd like to use ...
3
votes
2
answers
1k
views
ggrepel labels outside (to the right) of ggplot area
library(tidyverse)
library(ggrepel)
df <- structure(list(Fruit = c("Yellow Pear", "Yellow Pear", "Yellow Pear",
"Yellow Pear", "Yellow Pear", "Yellow Pear", "Yellow Pear", "Yellow Pear",
"Yellow ...
3
votes
1
answer
2k
views
Move labels from geom_label_repel into ggplot margin
In the plot below I'd like to move the label "V-Engine" into the plot margin. Adjusting the nudge_x argument is moving the "S-Engine" label but not the "V-Engine" label.
library(ggplot2)
library(...
6
votes
2
answers
131
views
Programmatically label multiple ablines in R ggplot2
There are existing questions asking about labeling a single geom_abline() in ggplot2:
R ggplot2: Labelling a horizontal line on the y axis with a numeric value
R ggplot2: Labeling a horizontal line ...
1
vote
1
answer
569
views
How to align and label the stratum in ggalluvial using ggrepel (or otherwise)
I have some alluvial plots that I have generated using ggalluvial in R.
The code example below produces something close to what I want to achieve. For example,
library("ggalluvial")
par(mar =...
5
votes
1
answer
2k
views
Adding text annotation to a clustering scatter plot (tSNE)
I have XY data (a 2D tSNE embedding of high dimensional data) which I'd like to scatter plot. The data are assigned to several clusters, so I'd like to color code the points by cluster and then add a ...
7
votes
1
answer
2k
views
Is it possible to avoid axis label overlapping by ggrepel?
I am drawing heatmap with ggplot2. Several ticks on y axis need to be labeled. However,some of them are too close and overlap. I know ggrepel could separate text labels, but currently I have not ...
7
votes
1
answer
6k
views
ggplot2 pie plot with geom_text_repel
I am plotting multiple pie plots with ggplot2 and succeeded in having the labels plotted in the right positions, as:
df <- data.frame(annotation=rep(c("promoter", "intergenic", "intragene", "...
5
votes
1
answer
886
views
Using ggrepel and shadowtext on the same geom_text
I have a plot (made in R with ggplot2) that's the result of some singular value decomposition of a bunch of text data, so I basically have a data set of ~100 words used in some reviews and ~10 ...
7
votes
1
answer
2k
views
Repel text from edges in network
When drawing a network, it would be nice if the labels of the nodes could also avoid network edges. E.g. in the example below, it would be possible to move all the labels outside the network. I've ...
2
votes
1
answer
875
views
ggplot2 and sf: geom_sf_text within limits set by coord_sf
I am using sf and ggplot2 to read shapefiles as simple features and plot various maps. I have been working through the maps chapter in the ggplot2 book but could not really find an answer to the ...
2
votes
2
answers
481
views
Wrap long text in a text box
I have the following reproducible coefficient plot.
library(tidyverse)
tribble(~term, ~estimate, ~lower, ~upper, ~text,
"a", .25, .2, .3 , "Lorem ipsum dolor sit amet, consectetur adipiscing ...
2
votes
1
answer
377
views
Justifying lines of text within individual ggrepel labels
I have a plot where I'm labelling elements with multi-line ggrepel labels. I'd like to right-justify within some of these and left-justify within others. See example:
p <- ggplot() +
...
2
votes
0
answers
1k
views
Repel geom label and text in ggplot. And ordering geom points based on size
I have 2 data frames such as these:
df1 <- data.frame(
party = c("Blue Party", "Red Party"),
dim1 = c(0.03, -0.04),
dim2 = c(-0.05, 0.02),
sz = c(34, 42)
)
df2 <- data.frame(
var = c("...
1
vote
1
answer
377
views
using `rlang` for conditional labelling in `ggplot` using `ggrepel`
I am writing a custom function to create a scatterplot with labels attached to points. Here is a minimal rendition of the same.
# needed libraries
library(tidyverse)
library(ggplot2)
library(ggrepel)
...
0
votes
1
answer
552
views
Why does text appear in the legend?
library(ggplot2)
library(ggrepel)
set.seed(1234)
ss <- sample(1:32, 10)
df <- mtcars[ss, ]
ggplot(df, aes(wt, mpg))+ geom_point(col = "red") +
geom_label_repel(aes(label = rownames(df), fill ...