9  Summarise results

The assessment results from Ferrer-Paris et al. (2019) are available in a dataset in figshare (Ferrer-Paris 2018). See Chapter 3 for instructions for data download.

Here we will use R and mermaid.js to read the data and generate summary tables.

9.1 Load libraries

library(dplyr)
library(knitr)
library(tidyr)
library(stringr)
opts <- options(knitr.kable.NA = "")

9.2 Load the data

here::here("overview-2019/assessment-results.qmd")
[1] "/Users/z3529065/proyectos/Forests-Americas/RLE-example-dry-forest-guajira/overview-2019/assessment-results.qmd"
(load(here::here("downloaded-data/20181123_MacrogroupsCountry.rda")))
[1] "Macrogroups.Global"         "Macrogroups.Country"       
[3] "SpatialCriteria.Global"     "SpatialCriteria.Country"   
[5] "FunctionalCriteria.Global"  "FunctionalCriteria.Country"

9.3 Create useful functions

First we create a couple of helper function to summarise best estimate and bounds of the risk categories.

label_risk_cats <- function(best,bounds) {
    if (is.na(bounds)) {
        out <- best
    } else {
        out <- sprintf("%s (%s)", best, bounds)
    }
}

Now we apply a series of steps to filter, reshape and transform the data in the original table into a more useful format.1

assessment_results <- function(x, mg_key, country_name) {
    x |> 
    filter(
        IVC.macrogroup_key %in% mg_key,
        Country %in% country_name) |> 
    pivot_longer(cols = A1:D3) |>
    select(IVC.macrogroup_key, name, value) |>
    mutate(
        subcriterion = str_replace(name, "bounds.", ""),
        type = if_else(grepl("bounds",name), "bounds", "best")) |>
    pivot_wider(
        id_cols = c(IVC.macrogroup_key,subcriterion), 
        names_from = "type", 
        values_from = value) |>
    rowwise() |>
    mutate(label = label_risk_cats(best,bounds)) |>
    ungroup()
}

Finally, this function takes a table template for mermaid.js and adds the information for each subcriterion:

create_RLE_table <- function (results, outfile) {
    results_table <- paste(readLines(here::here("fig/table-template.mmd")) ,collapse="\n")
    for (j in 1:nrow(results)) {
        qry <- slice(results,j) 
        results_table <-
        results_table |> 
            str_replace(
                sprintf("%s\\(\"NE\"\\)", qry$subcriterion),
                sprintf("%s(\"%s\")",qry$subcriterion, qry$label)
            ) |>
            str_replace(
                sprintf("class %s NE",qry$subcriterion),
                sprintf("class %s %s",qry$subcriterion, qry$best)   
            )
    }
    cat(results_table, file = outfile)

}

9.4 Global results

Now, for the continental/global assessment, we can display the results for this target macrogroup nicely using two lines of code:

rslts <- assessment_results(Macrogroups.Global, "M563", "global")
kable(t(rslts))
IVC.macrogroup_key M563 M563 M563 M563 M563 M563 M563 M563 M563 M563 M563
subcriterion A1 A2b A3 B1 B2 B3 C2a C2b D1 D2b D3
best VU LC EN LC LC LC NT NE LC VU LC
bounds VU – EN LC–NT
label VU (VU – EN) LC EN LC LC LC NT (LC–NT) NE LC VU LC

And we can generate an even nicer table using this function:

create_RLE_table(rslts,here::here("fig","overview-2019.mmd"))

Which will create the following code and subsequent output using `mermaid.js

%% Generic table
block-beta
    columns 5
    space
    SC["Subcriteria"]:4
    space S1["1"] 
    block:S2:2
    columns 2 
    S2a["2a"] S2b["2b"] end 
    S3["3"]
    A
    A1("VU (VU -- EN)")
    A2a("NE")
    A2b("LC")
    A3("EN")
    B
    B1("LC") B2("LC"):2 B3("LC")
    C C1("NE") C2a("NT (LC--NT)") C2b("NE") C3("NE")
    D D1("LC") D2a("NE") D2b("VU") D3("LC")
    E E1("NE"):4

    class A crits
    class B crits
    class C crits
    class D crits
    class E crits
    class SC subcrits
    class S2a crits
    class S2b crits
    class S3 crits
    class S1 crits
    class S2 crits
    class A1 VU
    class A2a NE
    class A2b LC
    class A3 EN
    class B1 LC
    class B2 LC 
    class B3 LC
    class C1 NE
    class C2a NT
    class C2b NE
    class C3 NE
    class E1 NE 
    class D1 LC 
    class D2a NE 
    class D2b VU 
    class D3 LC
    
    classDef VU fill:#FFFF00, stroke: white, color:black;
    classDef LC fill:#00AA00, stroke: white, color:black;
    classDef EN fill:#FFC800, stroke: white, color:black;
    classDef CR fill:#FF0000, stroke: white, color:white;
    classDef DD fill:#bbb, stroke: #eee, color: #eee;
    classDef NE fill:#FFFFFF, stroke: #bbb, color:#bbb;
    classDef subcrits fill:white,stroke:#333,stroke-width:1px;
    classDef crits fill:white,stroke:#333,stroke-width:1px;
%% Generic table
block-beta
    columns 5
    space
    SC["Subcriteria"]:4
    space S1["1"] 
    block:S2:2
    columns 2 
    S2a["2a"] S2b["2b"] end 
    S3["3"]
    A
    A1("VU (VU -- EN)")
    A2a("NE")
    A2b("LC")
    A3("EN")
    B
    B1("LC") B2("LC"):2 B3("LC")
    C C1("NE") C2a("NT (LC--NT)") C2b("NE") C3("NE")
    D D1("LC") D2a("NE") D2b("VU") D3("LC")
    E E1("NE"):4

    class A crits
    class B crits
    class C crits
    class D crits
    class E crits
    class SC subcrits
    class S2a crits
    class S2b crits
    class S3 crits
    class S1 crits
    class S2 crits
    class A1 VU
    class A2a NE
    class A2b LC
    class A3 EN
    class B1 LC
    class B2 LC 
    class B3 LC
    class C1 NE
    class C2a NT
    class C2b NE
    class C3 NE
    class E1 NE 
    class D1 LC 
    class D2a NE 
    class D2b VU 
    class D3 LC
    
    classDef VU fill:#FFFF00, stroke: white, color:black;
    classDef LC fill:#00AA00, stroke: white, color:black;
    classDef EN fill:#FFC800, stroke: white, color:black;
    classDef CR fill:#FF0000, stroke: white, color:white;
    classDef DD fill:#bbb, stroke: #eee, color: #eee;
    classDef NE fill:#FFFFFF, stroke: #bbb, color:#bbb;
    classDef subcrits fill:white,stroke:#333,stroke-width:1px;
    classDef crits fill:white,stroke:#333,stroke-width:1px;
Figure 9.1: Results from the RLE assessment (2019)

9.5 Country results

For the national assessment, we can create similar tables using these lines of code:

rslts <- assessment_results(Macrogroups.Country, "M563", "Venezuela")
kable(t(rslts))
IVC.macrogroup_key M563 M563 M563 M563 M563 M563 M563 M563 M563 M563 M563
subcriterion A1 A2b A3 B1 B2 B3 C2a C2b D1 D2b D3
best VU LC VU LC LC LC LC NE LC VU LC
bounds LC – EN VU – EN LC–NT
label VU (LC – EN) LC VU (VU – EN) LC LC LC LC (LC–NT) NE LC VU LC
create_RLE_table(rslts,here::here("fig","Venezuela-2019.mmd"))
rslts <- assessment_results(Macrogroups.Country, "M563", "Colombia")
kable(t(rslts))
IVC.macrogroup_key M563 M563 M563 M563 M563 M563 M563 M563 M563 M563 M563
subcriterion A1 A2b A3 B1 B2 B3 C2a C2b D1 D2b D3
best EN LC CR LC LC LC VU NE VU EN LC
bounds VU – LC NT–VU
label EN LC (VU – LC) CR LC LC LC VU (NT–VU) NE VU EN LC
create_RLE_table(rslts,here::here("fig","Colombia-2019.mmd"))
rslts <- assessment_results(Macrogroups.Country, "M563", "Trinidad and Tobago")
kable(t(rslts))
IVC.macrogroup_key M563 M563 M563 M563 M563 M563 M563 M563 M563 M563 M563
subcriterion A1 A2b A3 B1 B2 B3 C2a C2b D1 D2b D3
best LC LC NT LC LC LC LC NE LC DD CR
bounds LC – VU VU – LC LC – VU LC–NT
label LC (LC – VU) LC (VU – LC) NT (LC – VU) LC LC LC LC (LC–NT) NE LC DD CR
create_RLE_table(rslts,here::here("fig","TT-2019.mmd"))

See all tables in Section 1.2.


  1. If you can’t read this, trust me, I know what I am doing…↩︎