if (!requireNamespace("librarian", quietly =TRUE)) {# If not installed, install the packageinstall.packages("librarian")}librarian::shelf( dplyr, here, ggplot2, ggspatial, glue, jsonlite, leaflet, prettymapr, sf)
# merge the no & yesmergedDF <- dplyr::full_join(yesDF, noDF, by =c(".geo", "occurrenceStatus"))# parse the .geo columnmergedDF <- 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 outmergedDF$basisOfRecord <-"MachineObservation"mergedDF$eventDate <-"2022"# estimatedmergedDF$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 palettepal <-c("present"="green", "absent"="red")# Convert data to sf objectsf_data <-st_as_sf(data, coords =c("lon", "lat"), crs =4326)# Create the ggplotp <-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)