inst/markdown/02.tables.md

title: "Snow crab tables" author: - name: Snow crab group # orcid: 0000-0003-3632-5723 # email: jae.choi@dfo-mpo.gc.ca # email: choi.jae.seok@gmail.com # corresponding: true affiliation: - name: Bedford Institute of Oceanography, Fisheries and Oceans Canada city: Dartmouth state: NS url: www.bio.gc.ca date: 2024-08-17 keywords: - snow crab fishery assessment - basic tables abstract: | Snow crab demographic structure and basic fishery performance tables. toc: true number-sections: true highlight-style: pygments bibliography: media/references.bib

csl: media/canadian-journal-of-fisheries-and-aquatic-sciences.csl # see https://www.zotero.org/styles for more

license: "CC BY" copyright: holder: Jae S. Choi year: 2024 citation: container-title: https://github.com/jae0/bio.snowcrab/ doi: NA funding: "The snow crab scientific survey was funded by the snow crab fishers of Maritimes Region of Atlantic Canada." editor: render-on-save: false format: html: code-fold: true html-math-method: katex embed-resources: true pdf: pdf-engine: lualatex docx: default beamer: pdf-engine: lualatex

````{=html} <!-- NOTES: Make sure to have pulled observer data:

year.assessment = 2023
p = bio.snowcrab::load.environment( year.assessment=year.assessment )
yrs = 1996:year.assessment # redo all years
observer.db( DS="rawdata.redo", yrs=yrs )
observer.db( DS="bycatch.redo", yrs=yrs )  
observer.db( DS="odb.redo", p=p ) # 3 minutes
observer.db( DS="bycatch_clean_data.redo", p=p, yrs=p$yrs ) # 3 minutes

quarto options:

The reserved prefixes are: fig, tbl, lst, tip, nte, wrn, imp, cau, thm, lem, cor, prp, cnj, def, exm, exr, sol, rem, eq, sec. avoid using underscores (_) in labels and IDs as this can cause problems when rendering to PDF with LaTeX.

Elephant{#fig-elephant} Default @fig-elephant Figure 1 Capitalized @Fig-elephant Figure 1 Custom Prefix [Fig @fig-elephant] Fig 1 No Prefix [-@fig-elephant] 1

::: {#fig-elephants layout-ncol=2} Surus{#fig-surus} Hanno{#fig-hanno} Famous Elephants :::

See @fig-elephants for examples. In particular, @fig-hanno.

or:

| label: fig-plots

| fig-cap: "Plots"

| fig-subcap:

| - "Plot 1"

| - "Plot 2"

| layout-ncol: 2

| Col1 | Col2 | Col3 | |------|------|------| | A | B | C | | E | F | G | | A | G | G |

: My Caption {#tbl-letters}

See @tbl-letters.

or ::: {#tbl-letters}

| Col1 | Col2 | Col3 | |------|------|------| | A | B | C | | E | F | G | | A | G | G |

My Caption

:::

@fig-AAAA further explores the impact of temperature on ozone level.

#| label: fig-AAAA
#| fig-cap: "Temperature and ozone level."
#| tbl-cap: "Fishery performance statistics."
#| eval: true
#| output: true

Black-Scholes (@eq-black-scholes) is a mathematical model:

$$ \frac{\partial \mathrm C}{ \partial \mathrm t } + \frac{1}{2}\sigma^{2} \mathrm S^{2} \frac{\partial^{2} \mathrm C}{\partial \mathrm C^2} + \mathrm r \mathrm S \frac{\partial \mathrm C}{\partial \mathrm S}\ = \mathrm r \mathrm C $$ {#eq-black-scholes}

Introduction {#sec-introduction}

See @sec-introduction

citations: https://quarto.org/docs/authoring/citations.html; https://pandoc.org/MANUAL.html#citations

Blah Blah [see @knuth1984, pp. 33-35; also @wickham2015, chap. 1]

Blah Blah (see Knuth 1984, 33–35; also Wickham 2015, chap. 1)

Blah Blah [@knuth1984, pp. 33-35, 38-39 and passim]

Blah Blah (Knuth 1984, 33–35, 38–39 and passim)

Blah Blah [@wickham2015; @knuth1984].

Blah Blah (Wickham 2015; Knuth 1984).

Wickham says blah [-@wickham2015]

Wickham says blah (2015)

@knuth1984 says blah.

Knuth (1984) says blah.

@knuth1984 [p. 33] says blah.

Knuth (1984, 33) says blah.

CSL: default is Chicago Manual of Style author-date format

https://github.com/citation-style-language/styles https://www.zotero.org/styles

References

::: {#refs} :::


-->
````

# Set up environment

First set up environment. Data comes from:

-   At seas observations of fishery (ISSDB)
-   Dockside monitoring (Marfis)
-   Snow crab survey

These are mostly imported and formatted in [01_snowcrab](https://github.com/jae0/bio.snowcrab/inst/scripts/01_snowcrab.R). The methods are mostly outlined in @Choi_et_al_2005b.

```{r}
#| label: setup
#| eval: true
#| output: false

  require(aegis)

  # Get data and format based upon parameters:
  year.assessment = 2023
  p = bio.snowcrab::load.environment( year.assessment=year.assessment )

  # loadfunctions( "aegis")
  # loadfunctions( "bio.snowcrab")  # in case of local edits

  # require(ggplot2)
  # require(data.table)

  require(gt)  # table formatting

  outtabledir = file.path( p$annual.results, "tables" )

  years = as.character(1996: year.assessment)

  regions = c("cfanorth", "cfasouth", "cfa4x")
  nregions = length(regions)

  FD = fishery_data()  # mass in tonnes
  fda = FD$summary_annual
  dt = as.data.frame( fda[ which(fda$yr %in% c(year.assessment - c(0:10))),] )
  dt =  dt[,c("region", "yr", "Licenses", "TAC", "landings", "effort", "cpue")] 
  names(dt) = c("Region", "Year", "Licenses", "TAC", "Landings", "Effort", "CPUE") 
  rownames(dt) = NULL
  odb0 = setDT(observer.db("odb"))
  odb0$region = NA
  for ( reg in regions) {
    r = polygon_inside(x = odb0, region = aegis.polygons::polygon_internal_code(reg), planar=FALSE)
    odb0$region[r] = reg
  }

Fishery statistics from at sea observations

NENS:

#| label: table-fishery-nens-perf
#| tbl-cap: "Fishery performance statistics in NENS. Units are: TACs and Landings (tons, t), Effort ($\\times 10^3$ trap hauls, th) and CPUE (kg/th)."
#| eval: true
#| output: true

ii = which(dt$Region=="cfanorth")
oo = dt[ii, c("Year", "Licenses", "TAC", "Landings", "Effort", "CPUE")] 
gt::gt(oo) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

SENS:

#| label: table-fishery-sens-perf
#| tbl-cap: "Fishery performance statistics in SENS. Units are: TACs and Landings (tons, t), Effort ($\\times 10^3$ trap hauls, th) and CPUE (kg/th)."
#| eval: true
#| output: true

ii = which(dt$Region=="cfasouth")
oo = dt[ii, c("Year", "Licenses", "TAC", "Landings", "Effort", "CPUE")] 
gt::gt(oo) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

4X:

#| label: table-fishery-4x-perf
#| tbl-cap: "Fishery performance statistics in 4X. Units are: TACs and Landings (tons, t), Effort ($\\times 10^3$ trap hauls, th) and CPUE (kg/th). There were no landings or TACs in 2018/2019 due to indications of low abundance. The 2022 season is ongoing."
#| eval: true
#| output: true

ii = which(dt$Region=="cfa4x")
oo = dt[ii, c("Year", "Licenses", "TAC", "Landings", "Effort", "CPUE")] 
gt::gt(oo) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

At sea observed data

Carapace condition from observed data \< 95mm CW

#| label: setup-observer-data
#| eval: true
#| output: false
  odb = odb0[ cw < 95 & prodcd_id==0 & shell %in% c(1:5) & region %in% regions & sex==0, ]  # male

NENS:

#| label: table-fishery-nens-sublegal
#| tbl-cap: "Fishery performance statistics in NENS. Distribution of at sea observations of males less than 95 mm CW by year and shell condition."
#| eval: true
#| output: true

resN = dcast( odb0[ region=="cfanorth", .(N=.N), by=.(fishyr, shell) ], fishyr  ~ shell, value.var="N", fill=0, drop=FALSE, na.rm=TRUE )
if ( "NA" %in% names(resN) ) resN$"NA" = NULL
names(resN) = c("Year", "CC1", "CC2", "CC3", "CC4", "CC5" )
resN$Total = rowSums( resN[, 2:6 ], na.rm=TRUE)
resN[, 2:6 ] = round(resN[, 2:6 ] / resN$Total * 100, digits=2)
gt::gt(resN) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

SENS:

#| eval: true
#| output: true
#| label: table-fishery-sens-sublegal
#| tbl-cap: "Fishery performance statistics in SENS. Distribution of at sea observations of males less than 95 mm CW by year and shell condition."
resS = dcast( odb0[ region=="cfasouth", .(N=.N), by=.(fishyr, shell) ], fishyr  ~ shell, value.var="N", fill=0, drop=FALSE, na.rm=TRUE )
if ( "NA" %in%  names(resS)) resS$"NA" = NULL
names(resS) = c("Year", "CC1", "CC2", "CC3", "CC4", "CC5" )
resS$Total = rowSums( resS[, 2:6 ], na.rm=TRUE)
resS[, 2:6 ] = round(resS[, 2:6 ] / resS$Total * 100, digits=2)
gt::gt(resS) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

4X:

#| eval: true
#| output: true
#| label: table-fishery-4x-sublegal
#| tbl-cap: "Fishery performance statistics in 4X. Distribution of at sea observations of males less than 95 mm CW by year and shell condition."
resX = dcast( odb0[ region=="cfa4x", .(N=.N), by=.(fishyr, shell) ], fishyr  ~ shell, value.var="N", fill=0, drop=FALSE, na.rm=TRUE )
if ("NA" %in% names(resX)) resX$"NA" = NULL
names(resX) = c("Year", "CC1", "CC2", "CC3", "CC4", "CC5" )
resX$Total = rowSums( resX[, 2:6 ], na.rm=TRUE)
resX[, 2:6 ] = round(resX[, 2:6 ] / resX$Total * 100, digits=2)
gt::gt(resX) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

Carapace condition from observed data >= 95mm CW

#| eval: true
#| output: false
odb = odb0[ cw >= 95 & cw < 170  & prodcd_id==0 & shell %in% c(1:5) & region %in% regions & sex==0, ]  # male

NENS:

#| eval: true
#| output: true
#| label: table-fishery-nens-comm
#| tbl-cap: "Fishery performance statistics in NENS. Distribution of at sea observations of males greater than 95 mm CW by year and shell condition."
resN = dcast( odb[ region=="cfanorth", .(N=.N), by=.(fishyr, shell) ], fishyr  ~ shell, value.var="N", fill=0, drop=FALSE, na.rm=TRUE )
names(resN) = c("Year", "CC1", "CC2", "CC3", "CC4", "CC5" )
resN$Total = rowSums( resN[, 2:6 ], na.rm=TRUE)
resN[, 2:6 ] = round(resN[, 2:6 ] / resN$Total * 100, digits=2)
gt::gt(resN) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

SENS:

#| eval: true
#| output: true
#| label: table-fishery-sens-comm
#| tbl-cap: "Fishery performance statistics in SENS. Distribution of at sea observations of males greater than 95 mm CW by year and shell condition."
resS = dcast( odb[ region=="cfasouth", .(N=.N), by=.(fishyr, shell) ], fishyr  ~ shell, value.var="N", fill=0, drop=FALSE, na.rm=TRUE )
names(resS) = c("Year", "CC1", "CC2", "CC3", "CC4", "CC5" )
resS$Total = rowSums( resS[, 2:6 ], na.rm=TRUE)
resS[, 2:6 ] = round(resS[, 2:6 ] / resS$Total * 100, digits=2)
gt::gt(resS) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

4X:

#| eval: true
#| output: true
#| label: table-fishery-4x-comm
#| tbl-cap: "Fishery performance statistics in 4X. Distribution of at sea observations of males greater than 95 mm CW by year and shell condition."
resX = dcast( odb[ region=="cfa4x", .(N=.N), by=.(fishyr, shell) ], fishyr  ~ shell, value.var="N", fill=0, drop=FALSE, na.rm=TRUE )
names(resX) = c("Year", "CC1", "CC2", "CC3", "CC4", "CC5" )
resX$Total = rowSums( resX[, 2:6 ], na.rm=TRUE)
resX[, 2:6 ] = round(resX[, 2:6 ] / resX$Total * 100, digits=2)
gt::gt(resX) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

Percent soft from observed data

There are two possible definitions:

#| eval: true
#| output: true
odb = odb0[ cw >= 95 & cw < 170  & prodcd_id==0 & shell %in% c(1:5) & region %in% regions & sex==0, ]  # male
shell_condition = odb[ !is.na(odb$region), .N, by=.(region, fishyr, shell) ]
shell_condition[, total:=sum(N, na.rm=TRUE), by=.(region, fishyr)]
shell_condition$percent = round(shell_condition$N / shell_condition$total, 3) * 100
shell_condition$Year = shell_condition$fishyr

NENS:

#| eval: true
#| output: true
#| label: table-fishery-nens-soft-durometer
#| tbl-cap: "Fishery performance statistics in NENS. Distribution of at sea observations of males soft-shelled based on durometer (<68) and shell condition (1 and 2, SC)."
softN  = odb[ region=="cfanorth" & durometer <  68, .(Soft=.N), by=.(fishyr ) ] 
totalN = odb[ region=="cfanorth" & is.finite(durometer) , .(Total=.N), by=.(fishyr) ] 
resN = softN[totalN, on="fishyr"]
resN = resN[, .(Year=fishyr, Soft=round(Soft/Total*100,2), Total=Total) ]  
ssN = shell_condition[ region=="cfanorth" & shell %in% c(1,2), .(SoftSC=sum(percent), TotalSC=unique(total)[1]), by=.(Year)]
resN = resN[ssN, on="Year"]
gt::gt(resN) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

SENS:

#| eval: true
#| output: true
#| label: table-fishery-sens-soft-durometer
#| tbl-cap: "Fishery performance statistics in SENS. Distribution of at sea observations of males soft-shelled  based on durometer (<68) and shell condition (1 and 2, SC)."
softS  = odb[ region=="cfasouth" & durometer <  68, .(Soft=.N), by=.(fishyr ) ] 
totalS = odb[ region=="cfasouth" & is.finite(durometer) , .(Total=.N), by=.(fishyr) ] 
resS = softS[totalS, on="fishyr"]
resS = resS[, .(Year=fishyr, Soft=round(Soft/Total*100,2), Total=Total) ]  
ssS = shell_condition[ region=="cfasouth" & shell %in% c(1,2), .(SoftSC=sum(percent), TotalSC=unique(total)[1]), by=.(Year)]
resS = resS[ssS, on="Year"]
gt::gt(resS) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

4X:

#| eval: true
#| output: true
#| label: table-fishery-4x-soft-durometer
#| tbl-cap: "Fishery performance statistics in 4X. Distribution of at sea observations of males soft-shelled  based on durometer (<68) and shell condition (1 and 2, SC)."
softX  = odb[ region=="cfa4x" & durometer <  68, .(Soft=.N), by=.(fishyr ) ] 
totalX = odb[ region=="cfa4x" & is.finite(durometer) , .(Total=.N), by=.(fishyr) ] 
resX = softX[totalX, on="fishyr"]
resX = resX[, .(Year=fishyr, Soft=round(Soft/Total*100,2), Total=Total) ]  
ssX = shell_condition[ region=="cfa4x" & shell %in% c(1,2), .(SoftSC=sum(percent), TotalSC=unique(total)[1]), by=.(Year)]
resX = resX[ssX, on="Year"]
gt::gt(resX) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

Compare discard rates Maritimes:

NENS:discard

#| eval: true
#| output: true
#| warning: false
#| error: false 
#| label: table-fishery-nens-discard
#| tbl-cap: "Fishery performance statistics in NENS. Average by-catch discard rate by weight observed (kg/trap haul; and standard deviation, SD)."
region="cfanorth"
o = observer.db( DS="bycatch_summary", p=p,  yrs=p$yrs, region=region )   
resN = o$eff_summ[ order(fishyr), ]
names(resN) = c("Year", "Discards", "SD")
resN$Discards = round( resN$Discards*100, 2)
resN$SD = round( resN$SD*100, 2)
gt::gt(resN) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
  summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
  footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
  row_group.padding = gt::px(1))

SENS:

#| eval: true
#| output: true
#| warning: false
#| error: false 
#| label: table-fishery-sens-discard
#| tbl-cap: "Fishery performance statistics in SENS. Average by-catch discard rate by weight observed (kg/trap haul; and standard deviation, SD)."
region="cfasouth"
o = observer.db( DS="bycatch_summary", p=p,  yrs=p$yrs, region=region )   
resS = o$eff_summ[ order(fishyr), ]
names(resS) = c("Year", "Discards", "SD")
resS$Discards = round( resS$Discards*100, 2)
resS$SD = round( resS$SD*100, 2)
gt::gt(resS) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
  summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
  footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
  row_group.padding = gt::px(1))

4X:

#| eval: true
#| output: true
#| warning: false
#| error: false 
#| label: table-fishery-4x-discard
#| tbl-cap: "Fishery performance statistics in 4X. Average by-catch discard rate by weight observed (kg/trap haul; and standard deviation, SD)."
region="cfa4x"
o = observer.db( DS="bycatch_summary", p=p,  yrs=p$yrs, region=region )   
resX = o$eff_summ[ order(fishyr), ]
names(resX) = c("Year", "Discards", "SD")
resX$Discards = round( resX$Discards*100, 2)
resX$SD = round( resX$SD*100, 2)
gt::gt(resX) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
  summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
  footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
  row_group.padding = gt::px(1))

Survey-based tables

Carapace condition from trawl data >= 95mm CW

#| eval: true
#| output: false
det = snowcrab.db( p=p, DS="det.georeferenced" )
setDT(det)
det$fishyr = det$yr  ## the counting routine expectes this variable
det = det[ cw >= 95 ,]  # commerical sized crab only
years = sort( unique( det$yr ) )
det$region = NA
for ( reg in regions) {
  r = polygon_inside(x = det, region = aegis.polygons::polygon_internal_code(reg), planar=FALSE)
  det$region[r] = reg
}

NENS:

#| eval: true
#| output: true
#| label: table-survey-nens-comm
#| tbl-cap: "Distribution of NENS survey: males less than 95 mm CW by year and shell condition."
resN = dcast( det[ region=="cfanorth" & !is.na(shell), .(N=.N), by=.(fishyr, shell) ], fishyr  ~ shell, value.var="N", fill=0, drop=FALSE, na.rm=TRUE )
names(resN) = c("Year", "CC1", "CC2", "CC3", "CC4", "CC5" )
resN$Total = rowSums( resN[, 2:6 ], na.rm=TRUE)
resN[, 2:6 ] = round(resN[, 2:6 ] / resN$Total * 100, digits=2)
gt::gt(resN) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
  summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
  footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
  row_group.padding = gt::px(1))

SENS:

#| eval: true
#| output: true
#| label: table-survey-sens-comm
#| tbl-cap: "Distribution of SENS survey: males less than 95 mm CW by year and shell condition."
resS = dcast( det[ region=="cfasouth" & !is.na(shell), .(N=.N), by=.(fishyr, shell) ], fishyr  ~ shell, value.var="N", fill=0, drop=FALSE, na.rm=TRUE )
names(resS) = c("Year", "CC1", "CC2", "CC3", "CC4", "CC5" )
resS$Total = rowSums( resS[, 2:6 ], na.rm=TRUE)
resS[, 2:6 ] = round(resS[, 2:6 ] / resS$Total * 100, digits=2)
gt::gt(resS) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
  summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
  footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
  row_group.padding = gt::px(1))

4X:

#| eval: true
#| output: true
#| label: table-survey-4X-comm
#| tbl-cap: "Distribution of 4X survey: males less than 95 mm CW by year and shell condition."
resX = dcast( det[ region=="cfa4x" & !is.na(shell), .(N=.N), by=.(fishyr, shell) ], fishyr  ~ shell, value.var="N", fill=0, drop=FALSE, na.rm=TRUE )
names(resX) = c("Year", "CC1", "CC2", "CC3", "CC4", "CC5" )
resX$Total = rowSums( resX[, 2:6 ], na.rm=TRUE)
resX[, 2:6 ] = round(resX[, 2:6 ] / resX$Total * 100, digits=2)
gt::gt(resX) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
  summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
  footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
  row_group.padding = gt::px(1))

Counts of stations in each area

#| eval: true
#| output: true
#| label: table-survey-station-count
#| tbl-cap: "Survey station counts"
set = snowcrab.db(p=p, DS="set.clean")
setDT(set)
# check towquality .. this should always == 1
if (length( unique( set$towquality) ) != 1 ) print("error -- not good tows")
set$region = NA
for (reg in c( "cfanorth", "cfasouth", "cfa4x"  ) ) {
  d = polygon_inside(set[,c("lon","lat")], reg)
  set$region[d] = reg 
}
out = dcast( set[, .(N=.N), by=.(region, yr)], yr~region, value.var="N", fill=0, drop=FALSE, na.rm=TRUE )
out[,Total:=sum(cfanorth,cfasouth,cfa4x, na.rm=TRUE)]
out = out[, .(yr, cfanorth, cfasouth, cfa4x)]
names(out) = c("Year", "NENS", "SENS", "4X")
gt::gt(out) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
  summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
  footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
  row_group.padding = gt::px(1))

References



jae0/bio.snowcrab documentation built on Nov. 6, 2024, 10:10 p.m.