geomtextpath icon indicating copy to clipboard operation
geomtextpath copied to clipboard

Long labels with arrow throw cryptic "Error: Cannot create zero-length unit vector ("unit" subsetting)" error

Open eliocamp opened this issue 1 year ago • 0 comments

When the label is too long, I get "Error: Cannot create zero-length unit vector ("unit" subsetting)". What is "too long" seems to be device/resolution dependent as the same code worked in other machines and in the reprex, likely due to different screen sizes.

Reprex follows:

library(ggplot2)

super_long_label <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
short_label <- "Lorem ipsum"

ggplot(mtcars, aes(mpg, cyl)) +
  geomtextpath::geom_labelsmooth(method = "lm" ,
                                 label = short_label,
                                 arrow = arrow())
#> `geom_smooth()` using formula = 'y ~ x'


ggplot(mtcars, aes(mpg, cyl)) +
  geomtextpath::geom_labelsmooth(method = "lm" ,
                                 label = super_long_label,
                                 arrow = arrow())
#> `geom_smooth()` using formula = 'y ~ x'
#> Error: Cannot create zero-length unit vector ("unit" subsetting)

ggplot(mtcars, aes(mpg, cyl)) +
  geomtextpath::geom_labelsmooth(method = "lm" ,
                                 label = super_long_label)
#> `geom_smooth()` using formula = 'y ~ x'

Created on 2023-10-23 with reprex v2.0.2

eliocamp avatar Oct 23 '23 14:10 eliocamp