Sankey Diagram of Stroke Risk Factors

Introduction

The Assignment2 package provides a function, plot_sankey_diagram(), for creating Excel‑style Sankey diagrams using ggplot2.
This vignette demonstrates how to recreate the provided Excel Sankey chart visualizing stroke risk factors over time.

Key features of the function:

Basic Usage

The package includes an example dataset, stroke_data, which matches the structure of the Excel file.

data("stroke_data")

Basic Sankey diagram with no gaps

plot_sankey_diagram(stroke_data)

Adding Vertical and Horizontal Gaps

You can toggle gaps by setting vertical_gap or horizontal_gap to TRUE.

Horizontal White Space

plot_sankey_diagram(stroke_data, vertical_gap = FALSE, horizontal_gap = TRUE)

Vertical White Space

plot_sankey_diagram(stroke_data, vertical_gap = TRUE, horizontal_gap = FALSE)

Both Horizontal and Vertical White Space

plot_sankey_diagram(stroke_data, vertical_gap = TRUE, horizontal_gap = TRUE)

Adjusting Minimum Ribbon Size

For very small proportions, set a minimum ribbon size so that labels are easier to read.
(Default minimum ribbon size is set to 0.06.)

plot_sankey_diagram(stroke_data, min_ribbon_size = 0.06)

Conclusion

This vignette demonstrates how the plot_sankey_diagram() function replicates the Excel Sankey chart style in R.
You can customize:

- **Colors** (by editing the function’s color scale)  
- **White space** (with `vertical_gap` and `horizontal_gap`)  
- **Ribbon visibility** (with `min_ribbon_size`)  

For further styling, you can apply additional ggplot2 themes or save your plots with ggsave().