Processing for figures

process_data(dat, group = NULL, facet = NULL, lbs = FALSE)

Arguments

dat

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

group

String. 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

Character vector. Faceting variable(s) of the data.

Default: NULL

lbs

Logical. TRUE/FALSE; indicate 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`

Value

List of 3 objects:

data

A data frame of the processed data ready for plotting.

group

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

Faceting variable(s) identifying the 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)
}
#> [[1]]
#> # A tibble: 322 × 8
#>    label      estimate estimate_upper estimate_lower model group_var fleet  year
#>    <chr>         <dbl>          <dbl>          <dbl> <chr> <chr>     <chr> <dbl>
#>  1 fishing_m…  0                   NA             NA 1     North     North  1874
#>  2 fishing_m…  0                   NA             NA 1     South     South  1874
#>  3 fishing_m…  0                   NA             NA 1     North     North  1875
#>  4 fishing_m…  0                   NA             NA 1     South     South  1875
#>  5 fishing_m…  0                   NA             NA 1     North     North  1876
#>  6 fishing_m…  3.20e-5             NA             NA 1     South     South  1876
#>  7 fishing_m…  0                   NA             NA 1     North     North  1877
#>  8 fishing_m…  3.20e-5             NA             NA 1     South     South  1877
#>  9 fishing_m…  0                   NA             NA 1     North     North  1878
#> 10 fishing_m…  3.20e-5             NA             NA 1     South     South  1878
#> # ℹ 312 more rows
#> 
#> [[2]]
#> [1] "fleet"
#> 
#> [[3]]
#> NULL
#>