| Title: | Retention Flow Tables and Sankey Diagrams |
|---|---|
| Description: | Creates transition tables, summaries, and interactive Sankey diagrams from longitudinal person-term-state data. Sankey diagrams visualize flows between states with link widths proportional to flow counts; see Kennedy and Sankey (1898) "The Thermal Efficiency of Steam Engines" <doi:10.1680/imotp.1898.19100> and Schmidt (2008) "The Sankey Diagram in Energy and Material Flow Management: Part I: History" <doi:10.1111/j.1530-9290.2008.00004.x>. The minimum input schema is one row per person per term with an identifier, term, and categorical state. |
| Authors: | Alexander Nanni [aut, cre] |
| Maintainer: | Alexander Nanni <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.25 |
| Built: | 2026-07-17 06:29:35 UTC |
| Source: | https://github.com/cran/retentionflow |
Converts longitudinal person-term-state data into one row per person per consecutive term pair.
make_transitions( data, id = "ID", term = "Term", state = "State", term_order = NULL, missing_label = "Not enrolled" )make_transitions( data, id = "ID", term = "Term", state = "State", term_order = NULL, missing_label = "Not enrolled" )
data |
A data frame with one row per person per term. |
id |
Name of the identifier column. |
term |
Name of the term/time-period column. |
state |
Name of the categorical state column. |
term_order |
Optional vector giving the intended order of terms. |
missing_label |
Label used when a person is absent from the next term. |
A data frame with ID, from_term, to_term, from_state, to_state, and status.
x <- retention_example(); make_transitions(x)x <- retention_example(); make_transitions(x)
Creates a Plotly Sankey diagram from longitudinal person-term-state data. The default formatting follows the project Sankey style: term labels across the top, wide HTML-oriented output, fixed node colors for target state, graduation states, not enrolled, and other states, and detailed hover text.
plot_sankey( data, id = "ID", term = "Term", state = "State", term_order = NULL, start_term = NULL, target_state = NULL, missing_label = "Not Enrolled", unknown_label = "Unknown", graduated_other_label = "Graduated (Other)", graduated_in_target_label = NULL, title = NULL, width = NULL, height = 700, font_size = 11, title_font_size = 22, title_y = 0.975, top_margin = 65, term_label_y = 1.02, sankey_domain_top = 0.96, node_pad = 12, node_thickness = 18, save_html = FALSE, html_file = NULL, save_png = FALSE, png_file = NULL )plot_sankey( data, id = "ID", term = "Term", state = "State", term_order = NULL, start_term = NULL, target_state = NULL, missing_label = "Not Enrolled", unknown_label = "Unknown", graduated_other_label = "Graduated (Other)", graduated_in_target_label = NULL, title = NULL, width = NULL, height = 700, font_size = 11, title_font_size = 22, title_y = 0.975, top_margin = 65, term_label_y = 1.02, sankey_domain_top = 0.96, node_pad = 12, node_thickness = 18, save_html = FALSE, html_file = NULL, save_png = FALSE, png_file = NULL )
data |
A data frame with one row per person per term. |
id |
Name of the identifier column. Default is |
term |
Name of the term/time-period column. Default is |
state |
Name of the categorical state column. Default is |
term_order |
Optional vector giving the intended order of terms. If omitted, terms are ordered by first appearance in |
start_term |
Optional term defining the starting cohort. If omitted, the first value in |
target_state |
Optional state to highlight. When supplied, the starting cohort is restricted to people whose state equals |
missing_label |
Label assigned when a person is not observed in a later term. Default is |
unknown_label |
Label assigned to missing/blank states. Default is |
graduated_other_label |
Label used for graduation outside the target state. Default is |
graduated_in_target_label |
Optional label used for graduation in the target state. If omitted and |
title |
Plot title. If omitted, a title is constructed from |
width |
Plot width. Use |
height |
Plot height in pixels. Default is |
font_size |
Base font size. Default is |
title_font_size |
Title font size. Default is |
title_y |
Vertical position of the plot title in paper coordinates. Default is |
top_margin |
Top margin in pixels. Default is |
term_label_y |
Vertical position of the term labels in paper coordinates. Default is |
sankey_domain_top |
Top of the Sankey drawing region in paper coordinates. Default is |
node_pad |
Node padding. Default is |
node_thickness |
Node thickness. Default is |
save_html |
Logical. If |
html_file |
File path for the HTML export. Default is |
save_png |
Logical. If |
png_file |
File path for PNG export. Default is |
A plotly htmlwidget.
if (requireNamespace("plotly", quietly = TRUE)) { x <- retention_example() plot_sankey(x, target_state = "Biology", save_html = FALSE) }if (requireNamespace("plotly", quietly = TRUE)) { x <- retention_example() plot_sankey(x, target_state = "Biology", save_html = FALSE) }
A small synthetic dataset with one row per student per term.
retention_example()retention_example()
A data frame with ID, Term, and State.
retention_example()retention_example()
A synthetic longitudinal dataset with 100 students across eight semesters in
a four-year STEM program and seven STEM majors: Biology, Chemistry, Computer
Science, Engineering, Mathematics, Physics, and Statistics. Some students
graduate in fewer than eight semesters, some graduate in the eighth semester,
some stop out as Not Enrolled, and some remain enrolled at the end of
the fourth year.
data(stem_retention)data(stem_retention)
A data frame with 800 rows and 3 variables:
Synthetic student identifier.
Academic term.
Student major or enrollment/completion state.
data(stem_retention) head(stem_retention) validate_flow_data(stem_retention)data(stem_retention) head(stem_retention) validate_flow_data(stem_retention)
Counts students by transition pair and status.
summarize_transitions(transitions)summarize_transitions(transitions)
transitions |
A transition data frame created by make_transitions(). |
A data frame with transition counts and percentages within each from-term/from-state group.
x <- retention_example(); tr <- make_transitions(x); summarize_transitions(tr)x <- retention_example(); tr <- make_transitions(x); summarize_transitions(tr)
Checks that a data frame has identifier, term, and state columns and no duplicate identifier-term rows.
validate_flow_data( data, id = "ID", term = "Term", state = "State", require_complete = TRUE )validate_flow_data( data, id = "ID", term = "Term", state = "State", require_complete = TRUE )
data |
A data frame with one row per person per term. |
id |
Name of the identifier column. |
term |
Name of the term/time-period column. |
state |
Name of the categorical state column. |
require_complete |
If TRUE, missing values in required columns are errors. |
Invisibly returns TRUE when validation passes.
x <- retention_example(); validate_flow_data(x)x <- retention_example(); validate_flow_data(x)