Denmla
Denmla

Reputation: 135

Error - Visualisation data in ggplot2 with ggrepel package

I tried to draw a graph in the ggplot2 library with the addition of ggrepel:

set.seed(42)
ggplot(mtcars) +
  geom_point(aes(wt, mpg), size = 5, color = 'grey') +
  geom_label_repel(aes(wt, mpg, fill = factor(cyl), label = rownames(mtcars)),
                   fontface = 'bold', color = 'white',
                   box.padding = 0.35, point.padding = 0.5, 
                   segment.color = 'grey50') + 
  theme_classic(base_size = 16)

But I got the following error:

Error in convertUnit(x, unitTo, "x", "dimension", "x", "dimension", valueOnly = valueOnly) : 
  'x' argument must be a unit object

Thanks?

Upvotes: 3

Views: 778

Answers (1)

Kamil Slowikowski
Kamil Slowikowski

Reputation: 4614

The error is caused by:

box.padding = 0.35, point.padding = 0.5

ggrepel version 0.6.11 was changed to accept numbers such as 0.35 or the returned value from unit(0.35, "lines").

If you're using ggrepel before version 0.6.11, then please try using:

unit(0.35, "lines"), unit(0.5, "lines")

My guess is that you're probably using ggrepel 0.6.5 from CRAN. You might consider updating to the latest version from CRAN, which is 0.7.0.

Upvotes: 5

Related Questions