## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.align = "center")

## ----contribution-code, eval = FALSE------------------------------------------
# contribution <- climniche_dominant_contribution(
#   spatial_fit,
#   scope = "current"
# )
# 
# summary(contribution)
# head(contribution[["table"]])

## ----contribution-figure-code, eval = FALSE-----------------------------------
# variable_labels <- c(
#   temperature_mean = "Mean temperature",
#   temperature_range = "Temperature range",
#   salinity_range = "Salinity range",
#   ph_mean = "Mean pH",
#   sea_water_speed_mean = "Mean current speed",
#   sea_water_speed_range = "Current speed range"
# )
# 
# plot_climniche_dominant_contribution(
#   contribution,
#   type = "both",
#   variable_labels = variable_labels,
#   legend_variables = names(variable_labels),
#   study_region = mediterranean_boundary,
#   degree_labels = "hemisphere"
# )

## ----contribution-figure-output, echo = FALSE, out.width = "100%"-------------
knitr::include_graphics("figures/anchovy-climniche-contributions.png")

## ----contribution-summary, echo = FALSE---------------------------------------
library(climniche)

case_path <- system.file("extdata/mediterranean_anchovy", package = "climniche")
contribution_summary <- read.csv(
  file.path(case_path, "anchovy_climniche_dominant_contributions.csv")
)
contribution_summary <- contribution_summary[, c(
  "label", "mean_absolute_share", "dominant_weight_fraction"
)]
names(contribution_summary) <- c(
  "Climate variable", "Mean absolute share", "Weighted dominance frequency"
)
knitr::kable(contribution_summary, digits = 3, row.names = FALSE)

