thomasp85 / ggfx

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

Functions tripping up on geom_sf()? #15

Closed jdsher closed 3 years ago

jdsher commented 3 years ago

Very possible I've missed some key understanding, but at first pass it appears that some functions, specifically as_reference()and with_shadow() do not work with sf objects/geom_sf(). Looks to be some incompatibility with sf's geometry list columns? I keep getting Error in UseMethod("with_shadow") : no applicable method for 'with_shadow' applied to an object of class "list"

Reprex:

library(tidyverse)
library(sf)
library(ggfx)

nc <- st_read(system.file("shape/nc.shp", package="sf"))

ggplot(nc) +
  as_reference(
    geom_sf(data = nc,
            aes(fill = BIR79)),
    id = "nc"
)

ggplot(nc) +
  with_shadow(
    geom_sf(aes(fill = BIR79)),
    sigma = 3
)
thomasp85 commented 3 years ago

Thank you for the report - it is an oversight on my part. geom_sf() returns a list instead of a layer and I didn't plan for that

k-hench commented 3 years ago

I hope it is not impolite to comment on a closed issue :hand_over_mouth: Yet, I wanted to give a quick heads up since I regularly use {ggfx} with geom_sf() and it works just fine. I simply catch the first element of said returned list - like so:

library(rnaturalearth)
library(sf)
library(ggfx)
library(ggplot2)

canada <- ne_states(country = "Canada", returnclass = "sf")

canada_inset <- st_buffer(canada, -.7)

ggplot() +
  as_reference(
    geom_sf(data = canada_inset)[[1]],
    id = 'inset' ) +
  geom_sf(data = canada) +
  with_blend(
    with_blur( geom_sf(data = canada_inset,
                       size = 3,
                       color = rgb(0,0,0,.4), 
                       fill = "transparent")[[1]],
               sigma = 3),
    bg_layer = 'inset',
    blend_type = 'in') +
  coord_sf(crs = 3347)

(link to the plot on imgur - I believe it is not displayed on github...)

Created on 2021-04-08 by the reprex package (v2.0.0)

thomasp85 commented 3 years ago

Not impolite at all. However, the release version of ggfx handles geom_sf() just fine so there is no need to jump through any hoops to get it working🙂

k-hench commented 3 years ago

awesome - I missed that update :+1: :star_struck: