knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(endemicr) library(sf)
# prepare hawaii boundaries hawaii_boundaries <- list( "../inst/boundary_main_islands/2010_Census_County_Boundaries.shp", "../inst/boundary_nwhi/Coastline_-_Northwest_Hawaiian_Islands__NWHI_.shp") # prepare fish range as string fish_range <- "../tests/testdata/example_fish/example_fish.shp" bad_fish <- "../tests/testdata/problem_fish/data_0.shp"
# prepare extent hawaii_extent <- lapply(hawaii_boundaries, function(x) { st_as_sfc( st_bbox( st_union(st_read(x)) ) ) }) # bind extents and get full extent hawaii_extent <- Reduce(c, hawaii_extent) hawaii_extent <- st_as_sfc( st_bbox(hawaii_extent) ) # plot for sanity plot(hawaii_extent, col = "aliceblue", border = "white", main = "Does this look like the right place?"); axis(1); axis(2) # add islands lapply(hawaii_boundaries, function(x) { x <- st_read(x) plot(x, add = TRUE, col = "grey", max.plot = 1) })
# read in the example fish Chaetodon ornatissimus fish_range_sf <- st_read(fish_range) # plot plot(fish_range_sf$geometry, col = "red", border = NA, main = "The global range of this fish", xaxs = "r"); axis(1); axis(2)
Hawaii is defined as a 50km buffer around the Hawaii boundaries. This area is divided into the main and north-west Hawaiian islands by a line between Niihau and Nihoa. For demonstration we add a line after Laysan.
# get a buffer around hawaii boundaries # this is done automatically in the function check_hawaii_endemic hawaii_buffer <- lapply(hawaii_boundaries, function(x) { x <- st_read(x) x <- st_transform(x, 2782) x <- st_buffer(x, 50 * 1000) x <- st_union(x) x <- st_transform(x, 4326) }) # Reduce and join hawaii_buffer <- Reduce(c, hawaii_buffer) # notice the overlap plot(hawaii_buffer, col = "grey90", main = "Notice the overlap"); axis(1); axis(2)
# the demarcation points are function defaults for now hawaii_regions <- demarcate_regions( area_of_interest = hawaii_buffer, region_demarcation_points = list( main_islands = c(-160.1, 21.8), nwhi = c(-161.9, 23) )) # plot for sanity check plot(hawaii_regions$regions, reset = F, main = "Does this look alright?"); axis(1); axis(2) plot(hawaii_regions$demarcation_areas, col = NA, add = T)
# proportionof the global range in each area of hawaii # this is an endemic fish range_in_hawaii <- check_endemic_hawaii( hawaii_land_features = hawaii_boundaries, buffer_distance_km = 500, species_range = bad_fish, region_demarcation_points = list( main_islands = c(-160.1, 21.8), nwhi = c(-161.9, 23) )) # print this range_in_hawaii
# check a global fish range_in_hawaii <- check_endemic_hawaii( hawaii_land_features = hawaii_boundaries, buffer_distance_km = 500, species_range = fish_range, region_demarcation_points = list( main_islands = c(-160.1, 21.8), nwhi = c(-161.9, 23) ))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.