thomasp85 / ggfx

Filters and Shaders for 'ggplot2'
https://ggfx.data-imaginist.com
Other
166 stars 4 forks source link

Pixelated output from with_mask() #26

Open courtney-bryce-hilton opened 1 year ago

courtney-bryce-hilton commented 1 year ago

Hi,

Love the package. But I've been having some issue recently when using the with_mask function. The output is quite pixelated, to the point of being unusable for a few use-cases (generative art).

Below is a reproducible example that just plots some random points, where if using a mask, the result is pixelated regardless of how the image is exported. I am using the latest version of ggfx from the github repo and ggplot2 ‘3.4.0’.

Thanks in advance for any help

library(tidyverse)
library(ggfx)

test_data <- tibble(
  x = rnorm(2000, 0, 10),
  y = rnorm(2000, 0, 10),
)

circle <- tibble(
  x = cos(seq(0, 2*pi, length.out = 360)),
  y = sin(seq(0, 2*pi, length.out = 360))
) |> 
  mutate(across(everything(), ~ .x * 25))

# the output here is very pixelated
ggplot() +
  lims(x = c(-30, 30), y = c(-30, 30)) +
  coord_equal() +
  theme_void() +
  as_reference(
    geom_polygon(aes(x = x, y = y), circle),
    id = 'circle'
  ) +
  with_mask(
    geom_point(data = test_data, aes(x,y)),
    mask = ch_alpha('circle'),
    invert = FALSE,
    ignore_background = FALSE
  )

  # however if I just plot without the mask as a usual ggplot, it is fine:
  ggplot(test_data, aes(x,y)) +
  geom_point() +
  lims(x = c(-30, 30), y = c(-30, 30)) +
  coord_equal() +
  theme_void()