Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggrepel remove line around labels

Tags:

r

ggrepel

How can I remove the line around geom_label_repel. Using label.size = 0 appears to have no visible effect. I could set `colour

library(ggplot2)
library(ggrepel)
ggplot(mtcars, aes(wt, mpg, color = wt)) +
  geom_point(color = 'red') +
  geom_label_repel(aes(label = rownames(mtcars)), label.size = 0, fill = "white") +
  theme_classic(base_size = 16)

Entering a geom_text_repel after a blank geom_label_repel occasionally works, but is not reliable: the boxes may appear in a different location to the text.

enter image description here

like image 234
Hugh Avatar asked May 31 '17 03:05

Hugh


2 Answers

As eipi10 noted in the comment, set label.size=NA:

library(ggplot2)
library(ggrepel)
ggplot(mtcars, aes(wt, mpg, color = wt)) +
  geom_point(color = 'red') +
  geom_label_repel(aes(label = rownames(mtcars)), label.size = NA, fill = "white") +
  theme_classic(base_size = 16)
like image 147
Hugh Avatar answered Sep 27 '22 23:09

Hugh


You can omit the label boxes using the geom_text_repel geom.

library(ggplot2)
library(ggrepel)
g <- ggplot(mtcars, aes(wt, mpg, color = wt)) +
  geom_point(color = 'red') +
  theme_classic(base_size = 16)

g + geom_label_repel(aes(label = rownames(mtcars)), fill = "white")

enter image description here

g + geom_text_repel(aes(label = rownames(mtcars)))

enter image description here

Also, according to the help page:

Currently geom_label_repel ... is considerably slower than geom_text_repel.

like image 27
Megatron Avatar answered Sep 27 '22 23:09

Megatron