R/detections/length_zone_run.R

source("R/detections//input_data.R")

#----------------------------------------------------------------------
#   Run hetmaps with length, zones and detections
#----------------------------------------------------------------------

legend_title <- "Detections"
mix_extra_data_detections <-
  merge_extra_data_with_detections(monthly_detections,
                                   fish_extra_data)

length_zone_data <-
  mix_extra_data_detections %>%
  group_by(Zone, Length) %>%
  summarise(detections = n(), .groups = "drop")

length_zone_data <- length_zone_data[order(length_zone_data$Zone),]

h_lz_matrix <- generate_heatmap_length_zones (
  length_zone_data,
  "Detections by fishing locations and individual lengths for the whole series",
  legend_title,
  'Length',
  'Zone',
  by_percentage = FALSE,
  by_col_rows_order = HEAT_MAP_ORDER,
  font_size = 10
)

length_stat_chart <- generate_bar_plot(
  length_zone_data,
  'Length',
  'detections',
  "Detections sorted by individual lengths for the whole series",
  "Detections",
  'Length',
  "Detection values",
  month_as_name = FALSE,
  show_bar_values = TRUE
)

zone_stat_chart <- generate_bar_plot(
  length_zone_data,
  'Zone',
  'detections',
  "Detections sorted by fishing zones for the whole series",
  "Detections",
  'Zone',
  "Detection values",
  month_as_name = FALSE,
  show_bar_values = TRUE
)

bar_plots <-
  ggarrange(length_stat_chart,
            zone_stat_chart,
            ncol = 1,
            nrow = 2)

individual_length_data <-
  mix_extra_data_detections %>%
  group_by(ind_name, Length) %>%
  summarise(detections = n(), .groups = "drop")


individual_length_data <-
  individual_length_data[order(individual_length_data$Length),]
h_li_matrix <- generate_heatmap_length_zones (
  individual_length_data,
  "Detections by individuals and their lengths for the whole series",
  legend_title,
  'ind_name',
  'Length',
  by_percentage = FALSE,
  by_col_rows_order = HEAT_MAP_ORDER,
  font_size = 5
)

individual_zone_data <-
  mix_extra_data_detections %>%
  group_by(ind_name, Zone) %>%
  summarise(detections = n(), .groups = "drop")


individual_zone_data <-
  individual_zone_data[order(individual_zone_data$Zone),]
h_iz_matrix <- generate_heatmap_length_zones (
  individual_zone_data,
  "Detections by fishing locations and individuals for the whole series",
  legend_title,
  'ind_name',
  'Zone',
  by_percentage = FALSE,
  by_col_rows_order = HEAT_MAP_ORDER,
  font_size = 10
)

to_path <-
  file.path(OUTPUT,
            paste("length_zones_individuals_detections", suffix, sep = ""))

plots_to_pdf(
  list(h_lz_matrix, bar_plots, h_li_matrix, h_iz_matrix),
  to_path,
  paper_type,
  paper_height,
  paper_width
)
d2gex/seabasstfm documentation built on July 29, 2022, 2:20 a.m.