Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with custom filter and theme_void() #29

Open
nrennie opened this issue Aug 25, 2023 · 1 comment
Open

Error with custom filter and theme_void() #29

nrennie opened this issue Aug 25, 2023 · 1 comment

Comments

@nrennie
Copy link

nrennie commented Aug 25, 2023

Adding theme_void() to a plot with a custom filter using Magick results in an error. When testing with other theme functions such as theme_minimal() or theme_classic() it works fine. Small reprex based on the example in the documentation:

library(ggplot2)
library(ggfx)

# Example from documentation
implode <- function(x, factor = 0.5) {
  vp <- magick::image_read(get_viewport_area(x))
  vp <- magick::image_implode(vp, factor = factor)
  set_viewport_area(x, as.raster(vp, native = TRUE))
}

ggplot(mtcars, aes(x = factor(gear), y = disp)) +
  with_custom(
    geom_boxplot(aes(fill = as.factor(gear))),
    filter = implode
  ) 

# Adding theme_void() returns an error
# Other theme_*() functions don't seem to have this issue
ggplot(mtcars, aes(x = factor(gear), y = disp)) +
  with_custom(
    geom_boxplot(aes(fill = as.factor(gear))),
    filter = implode
  ) +
  theme_void()
#> Error in .subset(raster, index): only 0's may be mixed with negative subscripts

Created on 2023-08-25 with reprex v2.0.2

@MartinMSPedersen
Copy link

MartinMSPedersen commented Sep 5, 2023

You can define your own theme and can get the same effect as theme_void().

library(ggplot2)
library(ggfx)

# Example from documentation
implode <- function(x, factor = 0.5) {
  vp <- magick::image_read(get_viewport_area(x))
  vp <- magick::image_implode(vp, factor = factor)
  set_viewport_area(x, as.raster(vp, native = TRUE))
}

nothing <- 
    theme(
          plot.background = element_rect(fill = "#ffffff"),
          panel.background = element_rect(fill = "#ffffff"),
          panel.grid = element_blank(),
          axis.title = element_blank(),
          axis.text = element_blank(),
          axis.ticks = element_blank(),
          legend.position = "none"
    )
        
ggplot(mtcars, aes(x = factor(gear), y = disp)) +
  with_custom(
    geom_boxplot(aes(fill = as.factor(gear))),
    filter = implode
  ) + 
  nothing

nothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants