knitr::opts_chunk$set(echo = TRUE, eval = TRUE, warning=FALSE, message=FALSE) # install and load packages pkgs<- c( "ggplot2", "dplyr", "ggplot2", "magrittr", "here", "usmap", "sbtools", "devtools", "USAvian", "taxize") new.packages <- pkgs[!(pkgs %in% installed.packages()[,"Package"])] if(length(new.packages)) install.packages(new.packages) suppressMessages(lapply(pkgs, library, character.only = TRUE)) rm(new.packages,pkgs)
We are curating a list of data sources, currently located here. Import this file as an object to easily retrieve the URL for relevant information:
# Available abbreviations can be found using: data("data_sources")
We want to define, based on the column abbrev
in the data frame data sources
, which data sets we want to import:
# abbrevs<-"mbjv" # choose a single data abbrevs <- c("bcr_persistent", "iba", "flyways", "mbjv") # or multiple data # make sure that each abbreviation we specified is listed in the `data sources`: if(any(abbrevs %in% unique(data_sources$abbrev))==FALSE){ "some abbrevs do not appear in data_sources$abbrev. please check."}
Next we can download the data. This function will not overwrite existing files with the same names.
download_data(abbrevs=abbrevs, dir= here("data/data-raw")) # this will create a new directory if it does not already exist zip_files <- unzip_data(abbrevs)
Unzip the files associated with 'abbrevs'. For some reason this isn't working inside an RMD chunk, but works as expected here.....
r zip_files <- unzip_data(abbrevs)
categorized_files <- categorize_data(zip_files)
Next, import selected data into memory.
data <- import_data(abbrevs = abbrevs)
Create the base map for adding layers
# in 2019 package usmap used US Census county boundaries ## state boundaries usa_states <- plot_usmap(regions="states")+ labs(title="US States, US Census Bureau (YYYY)") ## county boundaries usa_counties <- plot_usmap(regions="counties")+ labs(title="US Counties, US Census Bureau (YYYY)") # for specific regions, see https://www2.census.gov/geo/pdfs/maps-data/maps/reference/us_regdiv.pdf ## southeast usa_se <- plot_usmap(include = c("FL", "GA", "MS", "SC", "NC", "AL", "AR", "LA", "TN")) + labs(title = "Southeastern US", subtitle = "States in the Southeastern US") ## or use the usmap to grab predefined census regions # usa_sa <- usmap::plot_usmap(include = .south_atlantic) # usa_s <- usmap::plot_usmap(include = .south_region)
str(usmap::us_map())
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
You can also embed plots, for example:
plot(pressure)
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.