Created
May 16, 2018 16:25
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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