ggplot_dt {SeaVal} | R Documentation |
plotting function for spatial data
Description
Plots spatial data from a data.table. The data table needs to contain columns named 'lon' and 'lat'. The grid needs to be regular.
If spatial data is contained for several levels (e.g. mutliple times or multiple ensemble members), only the data for the first level is plotted.
By default, the first column that is not recognized as a dimension variable is plotted, see data_col
. For the most common data-columns, reasonable
color scales are selected automatically.
Usage
ggplot_dt(
dt,
data_col = NULL,
mn = NULL,
discrete_cs = FALSE,
rr = NULL,
low = NULL,
mid = NULL,
high = NULL,
name = data_col,
midpoint = NULL,
breaks = NULL,
na.value = "gray75",
oob = NULL,
guide = guide_colorbar(barwidth = 0.5, barheight = 10),
...,
binwidth = NULL,
bin_midpoint = midpoint,
add_map = TRUE,
extent = NULL,
expand.x = c(0, 0),
expand.y = c(0, 0),
dimension_check = TRUE
)
Arguments
dt |
Data table containing the data for plotting. |
data_col |
The name of the column in dt containing the data for plotting. If nothing is provided (the default), the first column that is not a dimension variable or 'member' is selected. |
mn |
optional plot title |
discrete_cs |
Logical. Should the color scale be discretized? |
rr , low , mid , high , name , breaks , na.value , oob , guide , ... |
Arguments for the color scale, passed to scale_fill_gradient2 or scale_fill_steps2 (depending on whether discrete_cs == TRUE).
rr replaces limits (specifying the range of the color scale) for consistency with the older plotting functions from the PostProcessing package.
|
midpoint |
midpoint of the color scale, passed to |
binwidth , bin_midpoint |
only used when |
add_map |
logical, defaults to |
extent |
An optional four-element vector in the order xmin,xmax,ymin,ymax for specifying the spatial extent of the plot. Default is to fit the extent to the data. |
expand.x , expand.y |
vectors with two entries to be added to xlims/ylims of the plot. E.g. expand.x = c(-0.5,0.5) expands the plot by half a longitude both on the right and left hand side |
dimension_check |
Logical. By default the function checks that there are not multiple values per coordinate
(and subsets to the first level if there are several, e.g. to the first year and month (by appearance in |
Value
a ggplot object.
Author(s)
Claudio Heinrich
Examples
ex_dt = chirps_monthly[lat <0 & month == 12 & year == 2020]
pp = ggplot_dt(ex_dt)
if(interactive()) plot(pp)