Jobos Bay NERRS MCC

Author

Tylar Murray

(code) import libraries & functions
if (!requireNamespace("librarian", quietly = TRUE)) {
  # If not installed, install the package
  install.packages("librarian")
}

librarian::shelf(
  dplyr,
  here,
  ggplot2,
  ggspatial,
  glue,
  jsonlite,
  leaflet,
  prettymapr,
  sf
)
load the raw data
yesDF <- read.csv(here("data/raw/YES_Mangroves_Jobos.csv")) %>%
  select(".geo", "occurrenceStatus")
noDF <- read.csv(here("data/raw/NO_Mangroves_Jobos.csv")) %>%
  select(".geo", "occurrenceStatus")
basic data reshaping
# merge the no & yes
mergedDF <- dplyr::full_join(yesDF, noDF, by = c(".geo", "occurrenceStatus"))

# parse the .geo column
mergedDF <- mergedDF %>%
  mutate(
    coordinates = lapply(`.geo`, function(x) fromJSON(x)$coordinates),
    lon = sapply(coordinates, function(x) x[1]),
    lat = sapply(coordinates, function(x) x[2]),
    coordinates = NULL,  # rm coordinates now that lat, lon extracted
    `.geo` = NULL  # rm old geom column
  )
add some require DwC fields
# occurrenceID intentionally left out
# TODO: are these red mangroves or red/white/black all together.
#       if the latter, eudicots is the taxa that encapsulates all; not helpful. 
# scientificNameID intentionally left out
# geodeticDatum intentionally left out
# kingdom intentionally left out
# countryCode intentionally left out
mergedDF$basisOfRecord <- "MachineObservation"
mergedDF$eventDate <- "2022"  # estimated
mergedDF$coordinateUncertaintyInMeters <- 2
# reformat occurrenceStatus [1,0] to ["present","absent"]
mergedDF$occurrenceStatus <- ifelse(mergedDF$occurrenceStatus == 1, 'present', 'absent')
# TODO: samplingProtocol link here
# TODO: could use mergedDF$vitality <- "alive"
# TODO: use occurrenceRemarks here?
show points on map
data <- mergedDF

# Define a color palette
pal <- c("present" = "green", "absent" = "red")

# Convert data to sf object
sf_data <- st_as_sf(data, coords = c("lon", "lat"), crs = 4326)

# Create the ggplot
p <- ggplot(data = sf_data) +
  annotation_map_tile(type = "osm") +
  geom_sf(aes(color = occurrenceStatus), size = 3, alpha = 0.4) +
  scale_color_manual(values = pal, name = "Occurrence Status") +
  theme_minimal() +
  theme(
    legend.position = "bottomright",
    legend.title = element_text(size = 12),
    legend.text = element_text(size = 10)
  ) +
  ggtitle("Occurrence Status Map")

# Save the plot as a .png image
# ggsave("static_map_jobos.png", plot = p, width = 8, height = 6)
print(p)
Loading required namespace: raster
Zoom: 12

write reshaped data to file
write.csv(mergedDF, here("data/dwc/mangrove-jobos.csv"), row.names = FALSE)
. .
MCC Logo NERRS Logo