
Plot a simulated 'deweathered' trend, optionally with its input data
Source:R/plot_sim_trend.R
plot_sim_trend.RdThis function conveniently plots the trend from a simulated deweathered time series, with the option to overlay the trend from the original input data. The data can also be averaged over specified time intervals for clearer visualisation.
Usage
plot_sim_trend(
sim,
dw = NULL,
avg.time = NULL,
ylim = NULL,
names = c("Met Simulation", "Original Data"),
cols = "tol",
...,
.plot = TRUE,
.plot_engine = NULL
)Arguments
- sim
The output of
simulate_dw_met(); adata.framewith first columndateand second column a numeric pollutant.- dw
Optionally, the input model used to construct
sim. If provided, the original timeseries will be plotted alongside the simulated trend for easy comparison.- avg.time
Passed to
openair::timeAverage().- ylim
The limits of the y-axis.
- names
A character vector of length two, used to label the simulated dataset and the original dataset.
- cols
Colours to use for plotting. See
openair::openColours().- ...
Not currently used.
- .plot
When
FALSE, return adata.frameof plot data instead of a plot.- .plot_engine
The plotting engine to use. One of
"ggplot2", which returns a static plot, or"plotly", which returns a dynamic HTML plot.
Plotting Engines
deweather offers different plotting engines for different purposes. At
the moment, two plotting engines are supported:
"ggplot2", for static plotting. This engine produces plots which can be easily saved to a.png,.svg, or other 'static' file format. To save aggplot2plot, it is recommended to use theggplot2::ggsave()function."plotly", for dynamic plotting. This engine produces HTML plots which are suitable for embedding intoquartoorrmarkdowndocuments, or for use inshinyapplications. These can be saved using functions likehtmlwidgets::saveWidget().
The plotting engine is defined using the .plot_engine argument in any
plot_* function in deweather.
# use default
plot_dw_importance(dw)
# set to ggplot2 (static)
plot_dw_importance(dw, .plot_engine = "ggplot2")
# set to plotly (HTML)
plot_dw_importance(dw, .plot_engine = "plotly")When .plot_engine is not set, the engine defaults to "ggplot2".
However, this option can be overridden by using the deweather.plot_engine
global option.
# set once per session
options("deweather.plot_engine" = "plotly")
# now defaults to "plotly" over "ggplot2"
plot_dw_importance(dw)Note that not all arguments in a function may apply to all plotting
engines. For example, hexagonal binning in plot_tdw_testing_scatter() is
supported in ggplot2 but not in plotly at time of writing.
Examples
if (FALSE) { # \dontrun{
dw <- build_dw_model(aqroadside, "no2")
sim <- simulate_dw_met(dw)
plot_sim_trend(sim, dw, avg.time = "month")
} # }