tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.48k stars 2.02k forks source link

custom guide with `theme_void()` will throw a warning message #5856

Closed Hy4m closed 5 months ago

Hy4m commented 5 months ago

Greetings

I am trying to add an inside guide with theme_void(), and I'm not sure why throwing a warning message (In rep(padding, length.out = 4) : 'x' is NULL so the result will be NULL). But when we use other theme, it's OK.

Here is a simple example

library(ggplot2) ## 3.5.0.9000

    p <- ggplot(mpg, aes(displ, hwy)) + geom_point()

    ## it's OK
    p + 
      guides(custom = guide_custom(grid::circleGrob(),
                                     title = "My circle",
                                     width = unit(2, "cm"),
                                     height = unit(2, "cm")))

    ## but will throw a warning message when add theme_void()
    p + 
      guides(custom = guide_custom(grid::circleGrob(),
                                   title = "My circle",
                                   width = unit(2, "cm"),
                                   height = unit(2, "cm"))) +
      theme_void()
teunbrand commented 5 months ago

Hi there, thanks for the report! This indeed looks like a bug, but in the meanwhile I'd just recommend to add theme(legend.margin = margin()) after theme_void().

We probably should let theme_void() have empty padding, or let guide_custom() deal with NULL padding.