# Install {cliamteR} package# remotes::install_github("mikejohnson51/AOI") # suggested!# remotes::install_github("mikejohnson51/climateR")# Data Import and Wrangling Toolslibrary(sf) # Handling simple features in Rlibrary(terra) # Handling rasters in Rlibrary(tidyterra) # Rasters with ggplot2library(tidyverse) # All things tidy# Final plot toolslibrary(scales) # Nice Scales for ggplot2library(fontawesome) # Icons display in ggplot2library(ggtext) # Markdown text in ggplot2library(showtext) # Display fonts in ggplot2library(colorspace) # Lighten and Darken colours# Package to explorelibrary(climateR) # Climate Datalibrary(AOI) # Get area of interest# Making tables in Rlibrary(gt) # Beautiful Tablesbts =12# Base Text Sizesysfonts::font_add_google("Asap Condensed", "body_font")showtext::showtext_auto()theme_set(theme_minimal(base_size = bts,base_family ="body_font" ) +theme(text =element_text(colour ="grey20",lineheight =0.3,margin =margin(0,0,0,0, "pt") ) ))# Some basic caption stuff# A base Colourbg_col <-"white"seecolor::print_color(bg_col)# Colour for highlighted texttext_hil <-"grey30"seecolor::print_color(text_hil)# Colour for the texttext_col <-"grey20"seecolor::print_color(text_col)# Caption stuff for the plotsysfonts::font_add(family ="Font Awesome 6 Brands",regular = here::here("docs", "Font Awesome 6 Brands-Regular-400.otf"))github <-""github_username <-"aditya-dahiya"xtwitter <-""xtwitter_username <-"@adityadahiyaias"social_caption_1 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{github};</span> <span style='color: {text_hil}'>{github_username} </span>")social_caption_2 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{xtwitter};</span> <span style='color: {text_hil}'>{xtwitter_username}</span>")plot_caption <-paste0("**Data**: {geodata} package "," | **Code:** ", social_caption_1, " | **Graphics:** ", social_caption_2 )rm(github, github_username, xtwitter, xtwitter_username, social_caption_1, social_caption_2)
getTerraClim()
The getTerraClim() function in the {climateR} package provides access to TerraClimate data, a high-resolution dataset that offers monthly climate and water balance variables from 1958 onward. These variables include key climate indicators such as precipitation, temperature, soil moisture, wind speed, and evaporation metrics.
Code
terraClim_vars <- tibble::tibble(Variable =c("aet", "def", "PDSI", "pet", "ppt", "q", "soil", "srad", "swe", "tmax", "tmin", "vap", "vpd", "ws"),Units =c("mm", "mm", "unitless", "mm", "mm", "mm", "mm", "W/m^2", "mm", "degC", "degC", "kPa", "kPa", "m/s"),Description =c("Water evaporation amount", "Potential evaporation minus actual evaporation","Palmer Drought Severity Index","Potential evaporation amount","Precipitation amount","Runoff amount","Soil moisture content","Downwelling shortwave flux in air","Liquid water content of surface snow","Maximum air temperature","Minimum air temperature","Water vapor partial pressure in air","Vapor pressure deficit","Wind speed"))terraClim_vars |> gt::gt() |> gtExtras::gt_theme_538()
Table 1: Summary of Climate and Hydrological Variables in getTerraClim()
Variable
Units
Description
aet
mm
Water evaporation amount
def
mm
Potential evaporation minus actual evaporation
PDSI
unitless
Palmer Drought Severity Index
pet
mm
Potential evaporation amount
ppt
mm
Precipitation amount
q
mm
Runoff amount
soil
mm
Soil moisture content
srad
W/m^2
Downwelling shortwave flux in air
swe
mm
Liquid water content of surface snow
tmax
degC
Maximum air temperature
tmin
degC
Minimum air temperature
vap
kPa
Water vapor partial pressure in air
vpd
kPa
Vapor pressure deficit
ws
m/s
Wind speed
Code
# Get a nice map of India from Survey of India (simplified to# save on computing time)india_vec <-read_sf( here::here("data", "india_map","India_Country_Boundary.shp" )) |># Simplify to save computing timest_simplify(dTolerance =3000) |># Keep on bigger szed polygons and multiploygonsfilter(!st_is_empty(geometry)) |>arrange(desc(Area)) |>slice(1:2) |>select(-Area) |>st_transform("EPSG:4326")india_vec |>ggplot() +geom_sf()india_vec2 <-aoi_get(country ="India") |>st_cast("POLYGON")climate_raw <-getTerraClim( india_vec2,varname ="ppt",startDate ="2021-01-01")ggplot() +geom_spatraster(data = climate_raw$ppt )object.size(climate_raw)