A graph to help visualize what factors are influencing the index. Produces a plotly graphic where the bars are the total score for the factor after modifying it based on exposure. Hover to see the name of the factor and value of the exposure multiplier. Facets are produced if there are multiple scenarios

plot_q_score(vuln_df)

Arguments

vuln_df

the vuln_df element of the result from calc_vulnerability with an added column for the scenario_name. See examples.

Value

plotly graph

Examples


# load dplyr for dealing with nested lists in table
library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union

base_pth <- system.file("extdata", package = "ccviR")

# scenario names
scn_nms <- c("RCP 4.5", "RCP 8.5")

clim_vars <- get_clim_vars(file.path(base_pth, "clim_files/processed"), scn_nms)

spat_res <- analyze_spatial(
  range_poly = sf::read_sf(file.path(base_pth, "rng_poly.shp"), agr = "constant"),
  scale_poly = sf::read_sf(file.path(base_pth, "assess_poly.shp"), agr = "constant"),
  clim_vars_lst = clim_vars,
  hs_rast = terra::rast(c(file.path(base_pth, "rng_chg_45.tif"),
                          file.path(base_pth, "rng_chg_85.tif"))),
  hs_rcl = matrix(c(-1, 0, 1, 1, 2, 3), ncol = 2),
  scenario_names = scn_nms
)
#> performing spatial analysis
#> Warning: More than 10% of the range change raster does not match the expected values.
#> Is the classification table correct?

# vulnerability factor table with score 1 (somewhat increase vulnerability)
# for all factors
vuln <- make_vuln_df("test_species", val1 = 1, mig = 1)

index_vuln <- calc_vulnerability(spat_res$spat_table, vuln, "Bird")
#> calculating vulnerability index RCP 4.5
#> finished vulnerability
#> calculating vulnerability index RCP 8.5
#> finished vulnerability

bind_rows(index_vuln$vuln_df %>% `names<-`(index_vuln$scenario_name),
          .id = "scenario_name") %>%
  plot_q_score()