Skip to contents

Welcome

The currentsee package simulates transitions between malaria intervention packages and renders them as richly annotated Sankey diagrams. This vignette takes you from simulation to interactive exploration so you can explore the full workflow in just a few lines of code.

For package users the usual library call works:

1. Simulate transitions

We begin by simulating our data and adding a mock grouping variable “seasonality”

set.seed(1)
df <- simulate(100) |>
  mutate(
    season = sample(c("perennial", "seasonal"), 1),
    .by = "id"
  )

dplyr::glimpse(df)
#> Rows: 500
#> Columns: 5
#> $ step    <dbl> -1, 0, 1, 2, 3, -1, 0, 1, 2, 3, -1, 0, 1, 2, 3, -1, 0, 1, 2, 3…
#> $ package <chr> "cm", "cm, itn", "cm, itn, irs", "cm, itn, smc, irs", "cm, itn…
#> $ changed <chr> "itn", NA, "irs", "smc", "vx", "itn", NA, "vx", "smc", "irs", 
#> $ id      <int> 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5,
#> $ season  <chr> "perennial", "perennial", "perennial", "perennial", "perennial…

The required columns include:

  • step An integer vector. The current package is 0, steps down are negative and up are positive.
  • package A character string indicating the name of the package specified as a comma separated concatenation of the interventions in the package. When rendering the sankey labels, individual interventions are stacked vertically.
  • changed A character string indication which intervention is added or removed at each step.
  • id A unqiue, interger identifier for each pathway

Additional columns are grouping variables. At a minimum, you will likely want to include the current package as a grouping variable.

The resulting data.frame records every step in each trajectory, including the package string and which intervention changed.

2. Build Sankey inputs

Next we convert the raw simulation into the node and link structures required by networkD3::sankeyNetwork().

nodes <- make_nodes(df)
links <- make_links(df, nodes)
colours <- make_colours(nodes$id)

glimpse(nodes)
#> Rows: 9
#> Columns: 4
#> $ name      <chr> "cm", "cm, itn", "cm, itn, irs", "cm, itn, smc", "cm, itn, s…
#> $ node_name <chr> "cm", "cm\nitn", "cm\nitn\nirs", "cm\nitn\nsmc", "cm\nitn\ns…
#> $ id        <chr> "0", "1", "2", "3", "4", "5", "6", "7", "8"
#> $ p         <chr> "100%", "100%", "54%", "29%", "62%", "15%", "100%", "17%", "…
glimpse(links)
#> Rows: 14
#> Columns: 11
#> $ package      <chr> "cm", "cm, itn", "cm, itn, irs", "cm, itn, smc, irs", "cm…
#> $ next_package <chr> "cm, itn", "cm, itn, irs", "cm, itn, smc, irs", "cm, itn,…
#> $ step         <dbl> -1, 0, 1, 2, 3, 0, 1, 2, 1, 2, 1, 0, 1, 1
#> $ value        <int> 100, 54, 41, 62, 100, 17, 7, 15, 13, 23, 10, 29, 8, 21
#> $ source       <int> 0, 1, 2, 4, 6, 1, 7, 5, 2, 8, 7, 1, 3, 3
#> $ target       <int> 1, 2, 4, 6, NA, 7, 5, 6, 8, 6, 8, 3, 5, 4
#> $ label        <chr> "cm", "cm\nitn", "cm\nitn\nirs", "cm\nitn\nsmc\nirs", "cm…
#> $ id           <chr> "0", "1", "2", "4", "6", "1", "7", "5", "2", "8", "7", "1…
#> $ change       <chr> "itn", "irs", "smc", "vx", NA, "vx", "smc", "irs", "vx", 
#> $ tooltip      <chr> "→: add itn\n←: remove itn", "→: add irs\n←: remove irs",
#> $ p            <chr> "100%", "54%", "41%", "62%", "100%", "17%", "7%", "15%", 

Nodes represent unique package combinations, while links count how often we move from one combination to the next. Tooltips are automatically generated to summarise which interventions were added or removed.

3. Create a static Sankey diagram

With the inputs prepared we can render an interactive Sankey diagram directly in the RStudio viewer or an HTML document.

make_sankey(nodes, links, colours)

The widget honours the colour palette produced by make_colours() and includes rich tooltips describing each transition.

4. Launch the exploration Shiny app

To explore the same data with filtering controls, launch the bundled Shiny app. This opens in your default browser and allows you to subset the trajectories by any grouping columns you provide.

launch_step_app(df, group_cols = "season")

The app keeps the same Sankey rendering but adds dropdown selectors for the season column, letting you compare perennial and seasonal pathways side by side.