thomasp85 / ggfx

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

Vector output seems not possible #27

Closed geotheory closed 1 year ago

geotheory commented 1 year ago

When we use ggfx::with_outer_glow (and presumably other ggfx functions) the resulting output is converted to bitmap. Is this intended behaviour?

require(tidyverse)
require(sf)

j0 = jsonlite::fromJSON('https://petition.parliament.uk/petitions/554276.json')
d0 = j0$data$attributes$signatures_by_constituency |> as_tibble()
g = sf::read_sf('https://petitionmap.unboxedconsulting.com/json/uk/uk/topo_wpc.json')
d = g |> left_join(d0, by = c(id = 'ons_code')) |> st_set_crs(4326) |> st_transform("EPSG:27700")

# vector output
p1 = ggplot() + 
  geom_sf(aes(fill = signature_count), data = d, col = 'white', linewidth=0.03) +
  coord_sf(ylim = c(5e4, 9.6e5)) +
  scale_fill_viridis_c(direction = -1) +
  theme_void() +
  # theme(plot.background = element_rect(fill = 'grey90', colour = NA)) +
  labs(fill = 'Signatures')

ggsave(p1, filename = 'map1.pdf', width = 30, height = 45); browseURL('map1.pdf')

# When we use with_outer_glow the resulting map bitmap
p2 = ggplot() + 
  ggfx::with_outer_glow(
    geom_sf(aes(fill = signature_count), data = d, col = 'white', linewidth=0.03),
    colour = 'lightblue1',
    sigma = 10,
    expand = 2
  ) +
  coord_sf(ylim = c(5e4, 9.6e5)) +
  scale_fill_viridis_c(direction = -1) +
  theme_void() +
  labs(fill = 'Signatures')

ggsave(p2, filename = 'map2.pdf', width = 30, height = 45); browseURL('map2.pdf')

Output of map2 looks like this up close:

image
thomasp85 commented 1 year ago

Yes, this is at he core of how ggfx works. Most of these filters have no vector graphic interpretation

geotheory commented 1 year ago

Cheers Thomas. I appreciate that. It might be an idea to make this clear somewhere because I couldn't find any reference in documentation or the github repo.