format_cropr: Format simulations and observations from CropR format to a...

View source: R/cropr_formatting.R

format_croprR Documentation

Format simulations and observations from CropR format to a format usable by CroplotR

Description

Format simulations (and observations if any) for plotting. This function can be used as a template to include other models in CroPlotR.

Usage

format_cropr(
  sim,
  obs = NULL,
  obs_sd = NULL,
  type = c("dynamic", "scatter"),
  select_dyn = c("sim", "common", "obs", "all"),
  select_scat = c("sim", "res"),
  all_situations = FALSE,
  successive = NULL,
  reference_var = NULL,
  verbose = TRUE
)

Arguments

sim

A simulation data.frame

obs

An observation data.frame

obs_sd

A data.frame with observation standard deviations

type

The type of plot required, either "dynamic" or "scatter"

select_dyn

Which data to plot when type= "dynamic"? See details.

select_scat

Which data to plot when type= "scatter"? See details.

all_situations

Boolean (default = FALSE). If TRUE, plot all situations on the same graph. If TRUE, sim and obs are respectively an element of the first element and the second element of the output of cat_situations.

successive

A list of lists containing the situations to be represented as a contiguous sequence when type = "dynamic" (dates should be contiguous) when type = "dynamic" (implies that the situations are correctly ordered).

reference_var

Variable selected on x-axis when type is scatter and select_scat is res. It is possible to select between observation and simulation of the reference variable.

verbose

Logical value for displaying information while running.

Details

The select_dyn argument can be:

  • "sim" (the default): all variables with simulations outputs, and observations when there are some

  • "common": variables with simulations outputs and observations in common (used when type= "scatter" )

  • "obs": all variables with observations, and simulations outputs when there are some

  • "all": all variables with any observations or simulations outputs

The select_scat argument can be:

  • "sim" (the default): plots observations in X and simulations in Y.

  • "res": plots observations in X and residuals(observations-simulations)in Y.

Value

A pre-formatted data.frame or NULL if the formatting is not possible (e.g. type="scatter" but no common variables in obs and sim).

Examples

## Not run: 
# remotes::install_github("SticsRPacks/SticsRPacks")
workspace <- system.file(file.path("extdata", "stics_example_1"),
  package = "CroPlotR"
)
situation <- SticsRFiles::get_usms_list(
  file =
    file.path(workspace, "usms.xml")
)[1]
sim <- SticsRFiles::get_sim(workspace = workspace, usm = situation)
obs <- SticsRFiles::get_obs(workspace = workspace, usm = situation)
formated_df <- format_cropr(
  sim$`IC_Wheat_Pea_2005-2006_N0`,
  obs$`IC_Wheat_Pea_2005-2006_N0`
)
options(max.print = 100)
formated_df

## End(Not run)

SticsRPacks/CroPloteR documentation built on April 1, 2024, 9:25 a.m.