Skip to content

Instantly share code, notes, and snippets.

@SimonGoring
Created May 16, 2018 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonGoring/de62c06919839523c888eb37def68b7d to your computer and use it in GitHub Desktop.
Save SimonGoring/de62c06919839523c888eb37def68b7d to your computer and use it in GitHub Desktop.
Obtain data from the v2.0 Neotoma data API and plot it using R.
# Use the newer Neotoma API to pull sites with Fagus into a map from a JSON response.
# Used as part of the Data Demo Derby (hosted by EarthRates)
small_occ <- httr::GET('http://api-dev.neotomadb.org/v2.0/data/occurrence/?taxonname=Fagus&limit=5000')
small_content <- httr::content(small_occ)
library(dplyr)
site_table <- small_content$data %>%
purrr::map(function(x) {
point <- geojsonR::FROM_GeoJson(x$site$location)
if(point$type == "Point") {
coords <- data.frame(lon = point$coordinates[1],
lat = point$coordinates[2])
} else {
coords <- data.frame(lat = NA, lon = NA)
}
data.frame(ages = ifelse(is.null(x$age$age), NA, x$age$age), coords)
}) %>%
bind_rows()
plot(site_table$lat~site_table$lon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment