'Function for generating river plots (alluvial diagrams) to visualize flows and transitions over time or between categories. Supports alluvial diagrams, Sankey diagrams, and stream graphs with customizable aesthetics.'
Usage
riverplot(
data,
id = NULL,
time,
strata,
weight = NULL,
plotType = "alluvial",
fillType = "first",
sortStreams = TRUE,
labelNodes = TRUE,
curveType = "cardinal",
showCounts = FALSE,
showLegend = TRUE,
mytitle = "",
xtitle = "",
ytitle = "",
originaltheme = FALSE
)
Arguments
- data
The data as a data frame.
- id
Optional identifier for individual entities in the data.
- time
Variable representing time points or sequential stages.
- strata
Variables containing the categories that change over time.
- weight
Optional numerical variable to determine stream width.
- plotType
Type of river plot to generate.
- fillType
Determines how colors are assigned to flows.
- sortStreams
Sort alluvial streams by frequency.
- labelNodes
Add labels to nodes.
- curveType
Type of curve to use for stream paths.
- showCounts
Display counts on the diagram.
- showLegend
Display color legend.
- mytitle
Title for the plot.
- xtitle
Label for the x-axis.
- ytitle
Label for the y-axis.
- originaltheme
Use the ggStatsPlot theme instead of the default theme.
Examples
# \donttest{
# Load example data
data(riverplot_example_data)
data(riverplot_wide_example_data)
# Basic alluvial plot (longitudinal data)
riverplot(
data = riverplot_example_data,
time = "timepoint",
strata = "treatment_response",
plotType = "alluvial"
)
#> Error: object 'riverplot_example_data' not found
# Weighted river plot with patient tracking
riverplot(
data = riverplot_example_data,
id = "patient_id",
time = "timepoint",
strata = "treatment_response",
weight = "treatment_cost",
plotType = "alluvial",
labelNodes = TRUE,
fillType = "first"
)
#> Error: object 'riverplot_example_data' not found
# Multi-stage flow (wide format data)
riverplot(
data = riverplot_wide_example_data,
strata = c("screening", "enrollment", "treatment", "outcome"),
plotType = "alluvial",
fillType = "last",
showCounts = TRUE
)
#> Error in riverplot(data = riverplot_wide_example_data, strata = c("screening", "enrollment", "treatment", "outcome"), plotType = "alluvial", fillType = "last", showCounts = TRUE): argument "time" is missing, with no default
# Sankey diagram
riverplot(
data = riverplot_wide_example_data,
strata = c("screening", "enrollment", "treatment"),
weight = "total_cost",
plotType = "sankey",
curveType = "cardinal"
)
#> Error in riverplot(data = riverplot_wide_example_data, strata = c("screening", "enrollment", "treatment"), weight = "total_cost", plotType = "sankey", curveType = "cardinal"): argument "time" is missing, with no default
# Stream plot
riverplot(
data = riverplot_example_data,
time = "timepoint",
strata = "treatment_response",
weight = "treatment_cost",
plotType = "stream"
)
#> Error: object 'riverplot_example_data' not found
# }