title: ggplot2 question: Error in FUN(X[[i]], ...) : object 'HR' not found
body: <p>I'm stuck with a ggplot2 question. This time I'm using two datasets to plot them in ggplot2 (1=6 polygons overlapping together, 2=5 GPS points). I can plot them both separately, but not together in the same plot.</p>
  <p>Every time I do that, I get this error code: Error in FUN(X[[i]], ...) : object 'HR' not found</p>
  <p>If anyone can take a second look, I'll be super grateful! Thank you.</p>
  <h2>Code here</h2>
  <pre><code>library(ggplot2)
  library(sf)
  library(sp)
  library(viridis)
  library(ggnewscale)
  
  #they plot well separately
  
  poly_sf4&lt;-st_as_sf(poly_sf3)
  ggplot(poly_sf4) +
  geom_sf()
  
  roost_sf3&lt;- st_as_sf(roost_sf2) 
  ggplot(roost_sf3) +
  geom_sf()
  
  #but not together 
  
  theme_set(theme_light())
  
  june_only &lt;- ggplot(subset(poly_sf4, Sequence %in% 1),#the data is the sf object,
                 #set aesthetics based on the other columns/vars in the sf df
                 aes(color = HR, fill = HR, alpha = HR)) + 
          geom_sf(size = 1) + 
          scale_alpha_manual(name = &quot;HR:&quot;, 
                            values = c(0.2,0.4)) +
          scale_color_manual(name = &quot;HR:&quot;,
                             values = viridis(3)[1:2]) + 
          scale_fill_manual(name = &quot;HR:&quot;,
                            values = viridis(3)[1:2]) + 
          theme(legend.position=&quot;bottom&quot;, 
                legend.text = element_text(size = 15), 
                legend.title = element_text(size = 15), 
                legend.key.size = unit(0.5, &quot;cm&quot;), 
                text = element_text(size=10)) 
   
   
                
  june_only_roost     &lt;- june_only + 
            new_scale_colour() + 
    geom_sf(data=roost_sf3, aes(colour=Existing), size=3) +
         scale_color_manual(name = &quot;Existing:&quot;, 
                             values = viridis(10)[5:7])  
   
                
  june_only_roost 
  
  #Error in FUN(X[[i]], ...) : object 'HR' not found
  </code></pre>
  <h2>Data</h2>
  <pre><code>#Data 01: Polygons
  
  poly_sf3 &lt;- structure(list(id = &quot;NSF&quot;, area = 18.3641861686707, Month = &quot;01: Jun 2019&quot;, 
      geometry = structure(list(structure(list(structure(c(365367.33618389, 
      365264.754631496, 364731.911588065, 364810.96801954, 365050.261906325, 
      365346.205227799, 365367.33618389, 155179.53820745, 154761.691240949, 
      155005.189675172, 155114.59881625, 155249.352539069, 155198.343585666, 
      155179.53820745), .Dim = c(7L, 2L))), class = c(&quot;XY&quot;, &quot;POLYGON&quot;, 
      &quot;sfg&quot;))), class = c(&quot;sfc_POLYGON&quot;, &quot;sfc&quot;), precision = 0, bbox = structure(c(xmin = 364731.911588065, 
      ymin = 154761.691240949, xmax = 365367.33618389, ymax = 155249.352539069
      ), class = &quot;bbox&quot;), crs = structure(list(input = &quot;EPSG:32648&quot;, 
          wkt = &quot;PROJCS[\&quot;WGS 84 / UTM zone 48N\&quot;,\n    GEOGCS[\&quot;WGS 84\&quot;,\n        DATUM[\&quot;WGS_1984\&quot;,\n            SPHEROID[\&quot;WGS 84\&quot;,6378137,298.257223563,\n                AUTHORITY[\&quot;EPSG\&quot;,\&quot;7030\&quot;]],\n            AUTHORITY[\&quot;EPSG\&quot;,\&quot;6326\&quot;]],\n        PRIMEM[\&quot;Greenwich\&quot;,0,\n            AUTHORITY[\&quot;EPSG\&quot;,\&quot;8901\&quot;]],\n        UNIT[\&quot;degree\&quot;,0.0174532925199433,\n            AUTHORITY[\&quot;EPSG\&quot;,\&quot;9122\&quot;]],\n        AUTHORITY[\&quot;EPSG\&quot;,\&quot;4326\&quot;]],\n    PROJECTION[\&quot;Transverse_Mercator\&quot;],\n    PARAMETER[\&quot;latitude_of_origin\&quot;,0],\n    PARAMETER[\&quot;central_meridian\&quot;,105],\n    PARAMETER[\&quot;scale_factor\&quot;,0.9996],\n    PARAMETER[\&quot;false_easting\&quot;,500000],\n    PARAMETER[\&quot;false_northing\&quot;,0],\n    UNIT[\&quot;metre\&quot;,1,\n        AUTHORITY[\&quot;EPSG\&quot;,\&quot;9001\&quot;]],\n    AXIS[\&quot;Easting\&quot;,EAST],\n    AXIS[\&quot;Northing\&quot;,NORTH],\n    AUTHORITY[\&quot;EPSG\&quot;,\&quot;32648\&quot;]]&quot;), class = &quot;crs&quot;), n_empty = 0L), 
      Sequence = 1, HR = &quot;MCP&quot;), sf_column = &quot;geometry&quot;, agr = structure(c(id = NA_integer_, 
  area = NA_integer_, Month = NA_integer_, Sequence = NA_integer_, 
  HR = NA_integer_), .Label = c(&quot;constant&quot;, &quot;aggregate&quot;, &quot;identity&quot;
  ), class = &quot;factor&quot;), row.names = 11L, class = c(&quot;sf&quot;, &quot;data.frame&quot;
  ))
  
  
  #Data 02: 5 gps points 
  
  roost_sf2 &lt;- new(&quot;SpatialPointsDataFrame&quot;, data = structure(list(Name = c(&quot;Ro-Giraffe&quot;, 
  &quot;Ro-Cape Buffalo&quot;, &quot;Ro-MLR&quot;, &quot;Ro-Night Safari Entrance (felled)&quot;, 
  &quot;Ro-Elephant&quot;, &quot;Ro-Tram Station&quot;), descriptio = c(NA_character_, 
  NA_character_, NA_character_, NA_character_, NA_character_, NA_character_
  ), timestamp = c(NA_character_, NA_character_, NA_character_, 
  NA_character_, NA_character_, NA_character_), begin = c(NA_character_, 
  NA_character_, NA_character_, NA_character_, NA_character_, NA_character_
  ), end = c(NA_character_, NA_character_, NA_character_, NA_character_, 
  NA_character_, NA_character_), altitudeMo = c(NA_character_, 
  NA_character_, NA_character_, NA_character_, NA_character_, NA_character_
  ), tessellate = c(&quot;-1&quot;, &quot;-1&quot;, &quot;-1&quot;, &quot;-1&quot;, NA, NA), extrude = c(&quot;0&quot;, 
  &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, NA, NA), visibility = c(&quot;-1&quot;, &quot;-1&quot;, &quot;-1&quot;, &quot;-1&quot;, 
  NA, NA), drawOrder = c(NA_character_, NA_character_, NA_character_, 
  NA_character_, NA_character_, NA_character_), icon = c(NA_character_, 
  NA_character_, NA_character_, NA_character_, NA_character_, NA_character_
  ), Existing = c(&quot;Yes&quot;, &quot;Yes&quot;, &quot;No&quot;, &quot;No&quot;, &quot;Yes&quot;, &quot;New&quot;)), class = &quot;data.frame&quot;, row.names = c(NA, 
  -6L)), coords.nrs = numeric(0), coords = structure(c(103.789426, 
  103.786853, 103.787402, 103.788971, 103.785468833941, 103.788364169811, 
  1.399106, 1.401148, 1.404815, 1.404159, 1.40226000499339, 1.40343003798172, 
  0, 0, 0, 0, 0, 0), .Dim = c(6L, 3L), .Dimnames = list(NULL, c(&quot;coords.x1&quot;, 
  &quot;coords.x2&quot;, &quot;coords.x3&quot;))), bbox = structure(c(103.785468833941, 
  1.399106, 0, 103.789426, 1.404815, 0), .Dim = 3:2, .Dimnames = list(
      c(&quot;coords.x1&quot;, &quot;coords.x2&quot;, &quot;coords.x3&quot;), c(&quot;min&quot;, &quot;max&quot;))), 
      proj4string = new(&quot;CRS&quot;, projargs = &quot;+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0&quot;))
  </code></pre>