Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Created January 5, 2019 00:22
Show Gist options
  • Save yutannihilation/15ff434ef45df222cf864e87b29e2969 to your computer and use it in GitHub Desktop.
Save yutannihilation/15ff434ef45df222cf864e87b29e2969 to your computer and use it in GitHub Desktop.

c.f. yutannihilation/gghighlight#81

library(ggplot2)
library(gghighlight)
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3

data(tornados, package = "GISTools")

nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
us_states <- st_as_sf(us_states)
#> Loading required package: sp

# fail
ggplot(nc) +
  geom_sf(data = us_states) + # Supplemental Layer 2
  geom_sf(aes(fill = AREA)) + # Target Layer for gghighlight
  gghighlight(grepl("^[A-C]", NAME))
#> Error in merge_mapping(layer, plot_mapping): No mapping found on this layer!

# fail
ggplot(nc, aes(geometry = geometry)) +
  geom_sf(data = us_states) + # Supplemental Layer 2
  geom_sf(aes(fill = AREA)) + # Target Layer for gghighlight
  gghighlight(grepl("^[A-C]", NAME))
#> Error in if (aes_param_name %in% names(geom$default_aes) && is.na(geom$default_aes[[aes_param_name]])) {: missing value where TRUE/FALSE needed

Created on 2019-01-05 by the reprex package (v0.2.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment