knitr::opts_chunk$set(echo = TRUE, message = F, warning = F)
For Christopher Costello costello@bren.ucsb.edu, facilitated by Reniel Cabral rcabral@bren.ucsb.edu.
bbnj R packageInstall the bbnj R package (and devtools if needed).
install.packages(devtools) devtools::install_github("ecoquants/bbnj")
See list of datasets in bbnj reference. Datasets are "lazy-loaded"" with library(bbnj), meaning available in path but not showing up in Environment tab of RStudio.
library(tidyverse) library(raster) library(bbnj) # list bbnj datasets in RStudio: data(package="bbnj") # list raster layers within stacks (s_*) names(s_fish_gfw) names(s_bio_gmbi) # get rasters from stacks profit_fishing <- raster(s_fish_gfw, "mean_scaled_profits_with_subsidies") %>% gap_fill_raster() nspp_tunas <- raster(s_bio_gmbi, "nspp_tunas.n.billfishes") nspp_sharks <- raster(s_bio_gmbi, "nspp_sharks") # stack wanted rasters for later cropping s <- stack(profit_fishing, nspp_tunas, nspp_sharks) names(s) <- c("profit_fishing", "nspp_tunas", "nspp_sharks")
You'll need to run the raster::drawExtent() function interactively (ie not "knitting") within RStudio, outputting to console.
aoi_rds <- "aoi.rds" s_aoi_rds <- "s_aoi.rds" if (interactive()){ # draw your own area of interest plot(nspp_tunas) aoi <- raster::drawExtent() saveRDS(aoi, file = aoi_rds) } else { # load existing aoi <- readRDS(aoi_rds) } # show area of interest aoi plot(nspp_tunas) plot(aoi, col = "red", lwd = 2, add = T) # crop raster s_aoi <- raster::crop(s, aoi) # save and plot saveRDS(s_aoi, file = s_aoi_rds) plot(s_aoi)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.