Post processing of filtered data

process_data(dat, group = NULL, facet = NULL, 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. If you want to just summarize the data across all factors, set group = "none".

facet

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

method

A string describing the method of summarizing data when group is set to "none". Options are "sum" or "mean". Default is "sum".

Value

Automatically detects potential grouping and faceting data from a dataframe output from filter_data. It returns the following 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.

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: 294 × 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      1876 North
#>  2 fishing_m…  3.20e-5             NA             NA label South      1876 South
#>  3 fishing_m…  0                   NA             NA label North      1877 North
#>  4 fishing_m…  3.20e-5             NA             NA label South      1877 South
#>  5 fishing_m…  0                   NA             NA label North      1878 North
#>  6 fishing_m…  3.20e-5             NA             NA label South      1878 South
#>  7 fishing_m…  0                   NA             NA label North      1879 North
#>  8 fishing_m…  3.20e-5             NA             NA label South      1879 South
#>  9 fishing_m…  0                   NA             NA label North      1880 North
#> 10 fishing_m…  3.70e-4             NA             NA label South      1880 South
#> # ℹ 284 more rows
#> 
#> [[2]]
#> [1] "fleet"
#> 
#> [[3]]
#> NULL
#>