#check range of longs (check for NAs)
min(rogo_data$GISBLong);max(rogo_data$GISBLong);check(is.na(rogo_data$GISBLong))
## [1] -152.9167
## [1] -58.25
## FALSE 
##  4807
#check range of lats (check for NAs)
min(rogo_data$GISBLat);max(rogo_data$GISBLat);check(is.na(rogo_data$GISBLat))
## [1] 28.41667
## [1] 73.13333
## FALSE 
##  4807

After checking over your original code, I couldn’t find a problem with it. I was curious whether you had made a lat/long mistake and were defining an area with nothing in it. I wrote small dataframes with your specified bounding boxes for visualization.

qmg_box<-tribble(
  ~GISBLong, ~GISBLat,
  -110, 71,
  -110, 66,
  -95, 66,
  -95, 71)

baf_box<-tribble(
  ~GISBLong, ~GISBLat,
  -88, 71,
  -88, 61,
  -62, 61,
  -62, 71)

shi_box<-tribble(
  ~GISBLong, ~GISBLat,
  -88, 66,
  -88, 63,
  -80, 63,
  -80, 66)

Here, I see what is happening. The BAF bounding box is including all of the SHI sites, so when the unassigned sites are evaluated in the logic, they SHI sites have already been assigned, thus why you’re getting NAs.

world <- ne_countries(scale = "medium", returnclass = "sf")


ggplot(data = world) + geom_sf() + 
  coord_sf(xlim = c(-140,-55),ylim = c(28,73),expand = FALSE) + 
  geom_polygon(data = qmg_box, aes(GISBLong, GISBLat), fill = NA, color = "#00BFC4", size = 2) +
  geom_polygon(data = baf_box, aes(GISBLong, GISBLat), fill = NA, color = "#F8766D", size = 2) +
  geom_polygon(data = shi_box, aes(GISBLong, GISBLat), fill = NA, color = "#C77CFF", size = 2) +
  geom_point(data = rogo_data, aes(GISBLong,GISBLat))

There are a few ways you could fix this. I think the safest way is to define non-overlapping bounding boxes (especially since they don’t need to overlap to capture all the data in their given area).

I made the western edge of the BAF bounding box terminate at -80 (the eastern edge of SHI).

rogo_gps<-rogo_data %>% 
  mutate(origin = case_when(
    GISBLong <= -95 & GISBLong >= -110 & GISBLat >= 66 & GISBLat <= 71 ~ "QMG", 
    GISBLong <= -62 & GISBLong >= -80 & GISBLat >= 61 & GISBLat <= 71 ~ "BAF",
    GISBLong <= -80 & GISBLong >= -88 & GISBLat >= 63 & GISBLat <= 66 ~ "SHI", 
    TRUE ~ "other sites"))

Check to make sure this worked.

check(rogo_gps$origin)
##         BAF other sites         QMG         SHI 
##         547        1814        2123         323

Update bounding box.

baf_box_new<-tribble(
  ~GISBLong, ~GISBLat,
  -80, 71,
  -80, 61,
  -62, 61,
  -62, 71)

Revisualize assignment and color by “origin.”

ggplot(data = world) + geom_sf() + 
  coord_sf(xlim = c(-125,-55),ylim = c(55,73),expand = FALSE) + 
  geom_polygon(data = qmg_box, aes(GISBLong, GISBLat), fill = NA, color = "#00BFC4", size = 2) +
  geom_polygon(data = baf_box_new, aes(GISBLong, GISBLat), fill = NA, color = "#F8766D", size = 2) +
  geom_polygon(data = shi_box, aes(GISBLong, GISBLat), fill = NA, color = "#C77CFF", size = 2) +
  geom_point(data = rogo_gps, aes(GISBLong,GISBLat, color = origin))