hafen / trelliscopejs

TrelliscopeJS R Package
https://hafen.github.io/trelliscopejs
Other
263 stars 37 forks source link

Error with facet_trelliscope when plotting sf objects with ggplot2 #68

Open juanmayorgahenao opened 5 years ago

juanmayorgahenao commented 5 years ago

Does facet_trelliscope() work with ggplot2::geom_sf()? The funtion is failing on me when facet_wrap() works fine.

nc %>% select(SID74, SID79, geom) %>% gather(VAR, SID, -geom) %>% geom_sf(data = nc2, aes(fill = SID)) + facet_wrap(~ VAR)

The above works. But this fails:

nc %>% select(SID74, SID79, geom) %>% gather(VAR, SID, -geom) %>% geom_sf(data = nc2, aes(fill = SID)) + trelliscopejs::facet_trelliscope(~ VAR)

hafen commented 5 years ago

Interesting. I haven't tried it with geom_sf(). Can you send a reproducible example?

juanmayorgahenao commented 5 years ago
library(sf)
#> Linking to GEOS 3.7.0, GDAL 2.3.1, PROJ 5.2.0
library(tidyverse)

demo(nc, ask = FALSE, echo = FALSE)
#> Reading layer `nc.gpkg' from data source `/Library/Frameworks/R.framework/Versions/3.5/Resources/library/sf/gpkg/nc.gpkg' using driver `GPKG'
#> Simple feature collection with 100 features and 14 fields
#> Attribute-geometry relationship: 0 constant, 8 aggregate, 6 identity
#> geometry type:  MULTIPOLYGON
#> dimension:      XY
#> bbox:           xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> epsg (SRID):    4267
#> proj4string:    +proj=longlat +datum=NAD27 +no_defs

nc_2 <- nc %>% 
  select(SID74, SID79, geom) %>% 
  gather(VAR, SID, -geom) 

ggplot() + 
  geom_sf(data = nc_2, aes(fill = SID)) + 
  facet_wrap(~VAR) # works


ggplot() + 
  geom_sf(data = nc_2, aes(fill = SID))+
  trelliscopejs::facet_trelliscope(~ VAR) 
#> using data from the first layer
#> Warning in bind_rows_(x, .id): Vectorizing 'sfc_MULTIPOLYGON' elements may
#> not preserve their attributes

#> Warning in bind_rows_(x, .id): Vectorizing 'sfc_MULTIPOLYGON' elements may
#> not preserve their attributes

#> Warning in bind_rows_(x, .id): Vectorizing 'sfc_MULTIPOLYGON' elements may
#> not preserve their attributes

#> Warning in bind_rows_(x, .id): Vectorizing 'sfc_MULTIPOLYGON' elements may
#> not preserve their attributes
#> Error in FUN(X[[i]], ...): (list) object cannot be coerced to type 'double'

Created on 2018-10-26 by the reprex package (v0.2.1.9000)