Plot s2dv climate data
Description
Plots s2dv_cube gridded, polygon and point climate data generated by clim4health functions.
c4h_plot(
data,
var = NULL,
sdate = NULL,
time = NULL,
ensemble = NULL,
ensemble_fun = mean,
boundaries = NULL,
mask_boundaries = FALSE,
title = NULL,
legend = NULL,
palette = "-RdBu",
centering = NULL,
bins = NULL,
bins_method = "equal",
bins_label = NULL,
coordgrid = FALSE,
...
)Arguments
data: s2dv_cube object with the climate data to be plotted.var: Numerical index or name of the variable to be plotted. Only required if more than one variable is available.sdate: Numerical index of the forecast starting time to be plotted. Defaults to NULL (all starting dates).time: Numerical index of the time to be plotted. Defaults to NULL (all times).ensemble: Numerical index of the ensemble member to be plotted. If set to TRUE, it aggregates all the ensemble members. Defaults to NULL (all ensemble members).ensemble_fun: Aggregation function used when ensemble = TRUE. Defaults to the mean.boundaries: Polygon boundaries to add to the map. Set to NULL for no boundaries (default), otherwise supply a polygonsfobject or set to “countries” for coarse country boundaries.mask_boundaries: If TRUE (default), mask the data to the provided boundaries.title: Optional plot title.legend: Optional legend title. If NULL (default), it uses the variable names.palette: GHR, RColorBrewer or colorspace palette. Use “-” before the palette name (e.g., “-Reds”) to reverse it. Alternatively, a vector of hex codes to create a continuous interpolated palette.centering: Value at which to center the colour palette. Defaults to NULL (no centering).bins: Number of bins for categorization of numerical variables. Defaults to NULL (no binning).bins_method: Method to compute the bins, only used whenbinsis no NULL. Possible values are “quantile” and “equal” (default).bins_label: Optional labels for the bins. They must have the same length as the number of bins. Defaults to NULL (default interval labels).coordgrid: If TRUE, display coordinate grids on the map....: Extra arguments indicating fixed aesthetics to be passed tostars::geom_stars, includinglwd,alphaandcolour.
Returns
A ggplot2 plot with the climate data.
See Also
c4h_plotskill for plotting forecast skill metrics from c4h_verify .
Examples
library("sf")
# Region municipalities
mun_path <- system.file("extdata", "areas", "munip_vallecauca.gpkg",
package = "clim4health")
mun <- read_sf(mun_path)
# Forecast
fcst_path <- system.file("extdata", "forecast", package = "clim4health")
fcst <- c4h_load(fcst_path, variable = "t2m", ext = 'nc')
c4h_plot(fcst, title = "Forecast", ensemble = TRUE)
# Reanalysis
rean_path <- system.file("extdata", "reanalysis", package = "clim4health")
rean <- c4h_load(rean_path, variable = "t2m", ext = 'nc')
c4h_plot(rean, title = "Reanalysis", boundaries = mun,
mask_boundaries = TRUE, coordgrid = TRUE)
# Hindcast
hind_path <- system.file("extdata", "hindcast", package = "clim4health")
hind <- c4h_load(hind_path, variable = "t2m", ext = 'nc')
c4h_plot(hind, title = "Hindcast", ensemble = TRUE)
# Stations
stations_path <- system.file("extdata", "stations", package = "clim4health")
stations <- c4h_load(stations_path, var = "temp_mean", ext = "csv")
c4h_plot(stations, title = "Stations", time = 1:2,
boundaries = mun, coordgrid = TRUE)
# Spatially aggregated data
fcst_aggr <- c4h_space(fcst, mun)
c4h_plot(fcst_aggr, ensemble = 1:5, lwd = 0.1,
title = "Temp. by municipality", coordgrid = TRUE)