Processing for figures

process_data(dat, group = NULL, facet = NULL, lbs = FALSE, method = "sum")

Arguments

dat

Pre-filtered data from filter_data following a long format data.

group

A string identifying the indexing variable of the data. To remove any groups and summarize data across all factors, set group = "none". Setting group = NULL will keep any grouping variables identified in the data by the function.

Default: NULL

Options: Including, but not limited to: "year", "area", "fleet", "sex", "none", NULL

facet

A string or vector of strings identifying the faceting variable(s) of the data.

Default: NULL

lbs

A logical value indicating whether to convert the y-axis values from kilograms to pounds. The default units match the default in the unit_label argument - 'metric tons'.

Default: `FALSE`

method

A string describing the method of summarizing data when group is set to "none".

Default: "sum"

Options: "sum" or "mean"

Value

List of 3 objects:

data

A data frame of the processed data ready for plotting.

group

A string identifying the grouping variable of the data. If NULL, no grouping variable is identified. If not NULL, the function will verify that the data is indexed by this variables, otherwise it will overwrite it to a different, valid indexed variable or NULL.

facet

A string or vector of strings identifying the faceting variable(s) of the data. If NULL, no faceting variable is identified. Any identified indexed variables found in this function will be added to facet.

Details

Automatically detects potential grouping and faceting data from a dataframe output from filter_data.

Examples

{
  filtered <- stockplotr::filter_data(
    dat = stockplotr:::example_data,
    label_name = "fishing_mortality$",
    geom = "line",
    module = "TIME_SERIES"
  )
  process_data(dat = filtered, method = "sum")
}
#> [[1]]
#> # A tibble: 322 × 8
#>    label      estimate estimate_upper estimate_lower model group_var  year fleet
#>    <chr>         <dbl>          <dbl>          <dbl> <chr> <chr>     <dbl> <chr>
#>  1 fishing_m…  0                   NA             NA label North      1874 North
#>  2 fishing_m…  0                   NA             NA label South      1874 South
#>  3 fishing_m…  0                   NA             NA label North      1875 North
#>  4 fishing_m…  0                   NA             NA label South      1875 South
#>  5 fishing_m…  0                   NA             NA label North      1876 North
#>  6 fishing_m…  3.20e-5             NA             NA label South      1876 South
#>  7 fishing_m…  0                   NA             NA label North      1877 North
#>  8 fishing_m…  3.20e-5             NA             NA label South      1877 South
#>  9 fishing_m…  0                   NA             NA label North      1878 North
#> 10 fishing_m…  3.20e-5             NA             NA label South      1878 South
#> # ℹ 312 more rows
#> 
#> [[2]]
#> [1] "fleet"
#> 
#> [[3]]
#> NULL
#>