I used the code below to create 2 plots. The first plot resulted in the labels overlapping and the appearance of unwanted letters in the legend. So, in the plot 2, I used the geom_text(show.legend = FALSE)
and geom_text_repel(max.overlaps = Inf)
snippets to get around this situation. However, it doesn't work and still generates copies of the labels. I hope you can contribute with some solution or strategy that solves this situation.
# packages
library(ggplot2)
library(ggrepel)
# creating dataframe
fruits <- c('apple', 'banana', 'orange', 'pineapple', 'pear')
axis_x <- c(1.1, 1.2, 1.25, 1.3, 4)
axis_y <- c(1.1, 1.2, 1.25, 1.3, 4)
df <- data.frame(fruits, axis_x, axis_x)
# Plot 1
ggplot(df, aes(x = axis_x, y = axis_y, colour = fruits, label = fruits)) +
geom_point() +
geom_text()
# Plot 2
ggplot(df, aes(x = axis_x, y = axis_y, colour = fruits, label = fruits)) +
geom_point() +
geom_text(show.legend = FALSE) +
geom_text_repel(max.overlaps = Inf)
Pages accessed in an attempt to resolve the problem:
https://cran.r-project.org/web/packages/ggrepel/vignettes/ggrepel.html
Labeling with geom_text and geom_text_repel
How do I include strikethrough text in geom_text_repel or geom_text labels for ggplot?
http://www.sthda.com/english/wiki/ggplot2-texts-add-text-annotations-to-a-graph-in-r-software
...and many others
Maybe a little late, but I just stumbled over your post: I use geom_text_repel like this to avoid overlaying points and letters in the legend:
Then you should only see the legend from geom_point.