Before you start
There are many publicly available spatial datasets that can be downloaded using R. Programming data downloading using R instead of manually downloading data from websites can save lots of time and also enhances the reproducibility of your analysis. In this section, we will introduce some of such datasets and show how to download and process those data.
Direction for replication
Datasets
No datasets to download for this Chapter.
Packages
- Run the following code to install or load (if already installed) the
pacman
package, and then install or load (if already installed) the listed package inside thepacman::p_load()
function.
if (!require("pacman")) install.packages("pacman")
::p_load(
pacman# spatiotemporal data handling
stars, # raster data handling
terra, # raster data handling
raster, # vector data handling
sf, # data wrangling
dplyr, # string manipulation
stringr, # dates handling
lubridate, # data wrangling
data.table, # reshape
tidyr, # download USDA NASS data
tidyUSDA, # API key management
keyring, # download Daymet data
FedData, # download Daymet data
daymetr, # make maps
ggplot2, # make maps
tmap, # parallel processing
future.apply, # download CDL data
CropScapeR, # download PRISM data
prism, # extract raster values to sf
exactextractr )
- Run the following code to define the theme for map:
theme_set(theme_bw())
<- theme(
theme_for_map axis.ticks = element_blank(),
axis.text= element_blank(),
axis.line = element_blank(),
panel.border = element_blank(),
panel.grid.major = element_line(color='transparent'),
panel.grid.minor = element_line(color='transparent'),
panel.background = element_blank(),
plot.background = element_rect(fill = "transparent",color='transparent')
)