### Run ggalluvial Shiny App Example Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/shiny.md Launches a ggalluvial Shiny app example from the installed package. This is useful for viewing the app locally if it does not display in the document. ```r shiny::shinyAppDir(system.file("examples/ex-shiny-long-data", package="ggalluvial")) ``` -------------------------------- ### Example Datasets Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/index.html Example datasets included in the package for demonstration and testing. ```APIDOC ## Example Datasets ### Datasets - `vaccinations`: Influenza vaccination survey responses. - `majors`: Students' declared majors across several semesters. ### Description These datasets serve as examples for users to understand and test the functionality of the ggalluvial package. ``` -------------------------------- ### Load ggalluvial and create example data Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/ggalluvial-shiny.html Loads the ggalluvial package and defines a sample data frame for use in the Shiny app example. Ensure ggalluvial and other necessary packages are installed. ```R library(ggalluvial) example_data <- data.frame( weight = rep(1, 12), ID = 1:12, cluster = rep(c(1, 2), c(4, 8)), grp1 = rep(c('1a', '1b', '1a', '1b'), c(3, 2, 3, 4)), grp2 = rep(c('2a', '2b', '2a', '2b', '2a'), c(2, 2, 2, 2, 4)), grp3 = rep(c('3a','3b', '3a', '3b'), c(3, 2, 2, 5)) ) ``` -------------------------------- ### Inspect ggfittext required aesthetics and data setup Source: https://github.com/corybrunson/ggalluvial/blob/main/vignettes/labels.rmd Displays the required aesthetics and data setup function for `ggfittext::GeomFitText`, indicating how it determines text bounding boxes. ```r print(ggfittext:::GeomFitText$required_aes) print(ggfittext:::GeomFitText$setup_data) ``` -------------------------------- ### Basic geom_alluvium example Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/geom_alluvium.md A basic example demonstrating the usage of geom_alluvium with discrete axes and fill aesthetic. ```r ggplot(as.data.frame(Titanic), aes(y = Freq, axis1 = Class, axis2 = Sex, axis3 = Age, fill = Survived)) + geom_alluvium() + scale_x_discrete(limits = c("Class", "Sex", "Age")) ``` -------------------------------- ### Lode Ordering Examples with stat_alluvium Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/stat_alluvium.html These examples showcase different ways to control lode ordering and aesthetic binding when using stat_alluvium. They demonstrate options like 'forward' lode guidance, binding alluvia, and using custom lode orders or guidance functions. ```r gg <- ggplot(as.data.frame(Titanic), aes(y = Freq, axis1 = Class, axis2 = Sex, axis3 = Age)) + geom_stratum() + geom_text(stat = "stratum", aes(label = after_stat(stratum))) + scale_x_discrete(limits = c("Class", "Sex", "Age")) # use of lode controls gg + geom_flow(aes(fill = Survived, alpha = Sex), stat = "alluvium", lode.guidance = "forward") #> Warning: Using alpha for a discrete variable is not advised. ``` ```r # prioritize aesthetic binding gg + geom_flow(aes(fill = Survived, alpha = Sex), stat = "alluvium", aes.bind = "alluvia", lode.guidance = "forward") #> Warning: Using alpha for a discrete variable is not advised. ``` ```r # use of custom lode order gg + geom_flow(aes(fill = Survived, alpha = Sex, order = sample(x = 32)), stat = "alluvium") #> Warning: Ignoring unknown aesthetics: order #> Warning: Using alpha for a discrete variable is not advised. ``` ```r # use of custom luide guidance function lode_custom <- function(n, i) { stopifnot(n == 3) switch( i, `1` = 1:3, `2` = c(2, 3, 1), `3` = 3:1 ) } gg + geom_flow(aes(fill = Survived, alpha = Sex), stat = "alluvium", aes.bind = "flow", lode.guidance = lode_custom) #> Warning: Using alpha for a discrete variable is not advised. ``` -------------------------------- ### 'backfront' Lode Guidance Example Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/lode-ordering.html Illustrates the 'backfront' lode guidance function, which extends outward in one direction before the other. This example applies it to an alluvial plot. ```R for (i in 1:4) print(lode_backfront(4, i)) ``` ```R ggplot(toy, aes(x = collection, stratum = category, alluvium = subject)) + stat_alluvium(aes(fill = class), lode.guidance = "backfront") + stat_stratum() + stat_stratum(geom = "text", aes(label = category)) ``` -------------------------------- ### Install ggalluvial Development Version from GitHub Source: https://github.com/corybrunson/ggalluvial/blob/main/README.rmd Installs the development version of ggalluvial from the main branch on GitHub. Set build_vignettes to TRUE to also build the package vignettes. ```r remotes::install_github("corybrunson/ggalluvial@main", build_vignettes = TRUE) ``` -------------------------------- ### 'backward' Lode Guidance Example Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/lode-ordering.html Shows the 'backward' lode guidance function, which prioritizes tidiness on the right side of the diagram. This example applies it to an alluvial plot. ```R for (i in 1:4) print(lode_backward(4, i)) ``` ```R ggplot(toy, aes(x = collection, stratum = category, alluvium = subject)) + stat_alluvium(aes(fill = class), lode.guidance = "backward") + stat_stratum() + stat_stratum(geom = "text", aes(label = category)) ``` -------------------------------- ### Alluvium Cementation Examples with stat_alluvium Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/stat_alluvium.html This example illustrates alluvium cementation using stat_alluvium. It sets up a ggplot object with strata and then applies geom_stratum, preparing for further alluvium-related geoms. ```r gg <- ggplot(ggalluvial::majors, aes(x = semester, stratum = curriculum, alluvium = student, fill = curriculum)) + geom_stratum() ``` -------------------------------- ### Install ggalluvial from CRAN Source: https://github.com/corybrunson/ggalluvial/blob/main/README.rmd Installs the latest stable release of the ggalluvial package from CRAN. This is the recommended method for most users. ```r install.packages("ggalluvial") ``` -------------------------------- ### Install ggalluvial Optimization Branch from GitHub Source: https://github.com/corybrunson/ggalluvial/blob/main/README.rmd Installs a development version from the 'optimization' branch on GitHub, which contains experimental functions for reducing alluvial overlaps. Note that this branch may not be as up-to-date as the main branch. ```r remotes::install_github("corybrunson/ggalluvial", ref = "optimization") ``` -------------------------------- ### ggfittext Setup Data Logic Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/labels.md Shows the setup_data method for ggfittext::geom_fit_text, illustrating how it handles data for text placement, including checks for required aesthetics and calculations for width/height if not provided. ```r print(ggfittext:::GeomFitText$setup_data) ``` -------------------------------- ### Setup ggalluvial and ggplot2 Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/lode-ordering.html Loads the ggalluvial package and sets default chunk options for knitr. Ensure ggplot2 is also loaded as it's a dependency. ```r knitr::opts_chunk$set(fig.width = 6, fig.height = 3, fig.align = "center") library(ggalluvial) ``` -------------------------------- ### Backward Lode Guidance Example Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/order-rectangles.md Shows the 'backward' lode guidance function. This function prioritizes keeping the right part of the plot tidy, allowing the left part to be more complex. ```r for (i in 1:4) print(lode_backward(4, i)) ``` -------------------------------- ### Lode Ordering Examples with stat_alluvium Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/stat_alluvium.md This example showcases lode ordering in alluvial plots using stat_alluvium. It builds upon a base ggplot object and demonstrates how to control lode guidance with the 'forward' option. ```R gg <- ggplot(as.data.frame(Titanic),\ aes(y = Freq,\ axis1 = Class, axis2 = Sex, axis3 = Age)) +\ geom_stratum() +\ geom_text(stat = "stratum", aes(label = after_stat(stratum))) +\ scale_x_discrete(limits = c("Class", "Sex", "Age")) # use of lode controls gg + geom_flow(aes(fill = Survived, alpha = Sex), stat = "alluvium",\ lode.guidance = "forward") #> Warning: Using alpha for a discrete variable is not advised. ``` -------------------------------- ### Setup ggalluvial and load data Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/labels.html Initializes ggalluvial and ggplot2, and loads the 'vaccinations' dataset. The response factor levels are reversed for intuitive ordering. Required for subsequent plotting. ```r knitr::opts_chunk$set(fig.width = 6, fig.height = 4, fig.align = "center") library(ggalluvial) ## Loading required package: ggplot2 data(vaccinations) vaccinations <- transform(vaccinations, response = factor(response, rev(levels(response)))) ``` -------------------------------- ### ggplot with Backfront Lode Guidance Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/order-rectangles.md Generates a ggplot visualization using the 'backfront' lode guidance for alluvia and strata. This example shows how to apply the guidance to a plot for visual analysis. ```r ggplot(toy, aes(x = collection, stratum = category, alluvium = subject)) + stat_alluvium(aes(fill = class), lode.guidance = "backfront") + stat_stratum() + stat_alluvium(geom = "text", aes(label = subject), lode.guidance = "backfront") ``` -------------------------------- ### Prioritize Aesthetic Binding in Alluvial Plots Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/stat_alluvium.md This example shows how to prioritize aesthetic binding using 'alluvia' and a forward lode guidance. Note the warning about using alpha for a discrete variable. ```R gg + geom_flow(aes(fill = Survived, alpha = Sex), stat = "alluvium", aes.bind = "alluvia", lode.guidance = "forward") ``` -------------------------------- ### Size Filter Examples for geom_flow (min.y) Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/stat_flow.html Demonstrates omitting small flows from the visualization using the 'min.y' aesthetic in geom_flow with the 'vaccinations' dataset. ```r gg <- ggplot(vaccinations, aes(y = freq, x = survey, stratum = response, alluvium = subject, fill = response, label = response)) + stat_stratum(alpha = .5) + geom_text(stat = "stratum") # omit small flows gg + geom_flow(min.y = 50) ``` -------------------------------- ### Geom Stratum Example: Use of Facets Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/geom_stratum.md Illustrates how to use geom_stratum in conjunction with geom_flow and facet_wrap to visualize data across different categories. ```r ggplot(as.data.frame(Titanic), aes(y = Freq, axis1 = Class, axis2 = Sex)) + geom_flow(aes(fill = Survived)) + geom_stratum() + geom_text(stat = "stratum", aes(label = after_stat(stratum))) + scale_x_discrete(limits = c("Class", "Sex")) + facet_wrap(~ Age, scales = "free_y") ``` -------------------------------- ### Varying Aesthetics with Interaction and Binding Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/stat_flow.md Shows how to set aesthetics that vary both between and within strata using an interaction term for fill and binding aesthetics to flows. This example uses the 'vaccinations' dataset. ```R ggplot(vaccinations, aes(x = survey, stratum = response, alluvium = subject, y = freq, label = response)) + geom_flow(aes(fill = interaction(response, subgroup)), aes.bind = "flows") + scale_alpha_discrete(range = c(1/3, 2/3)) + geom_stratum(alpha = .5) + geom_text(stat = "stratum") ``` -------------------------------- ### Manually Order Lodes with a Matrix Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/lode-ordering.html Pass an integer matrix to `lode.ordering` to specify the order of cases within each stratum at the axes. This example uses a shortcut with a single vector to order cases by their IDs. ```R lode_ord <- matrix(1:5, nrow = 5, ncol = 4) ggplot(toy, aes(x = collection, stratum = category, alluvium = subject)) + stat_alluvium(aes(fill = class), lode.ordering = lode_ord) + stat_stratum() + stat_stratum(geom = "text", aes(label = category)) ``` -------------------------------- ### Self-Adjoin Vaccinations Data (Keep X and Y) - R Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/self-adjoin.html Extends the previous example by also keeping 'start_date' and 'end_date' from the second copy of the dataset, providing more context for each step in the vaccination process. ```r vaccination_steps <- self_adjoin(vaccinations, key = survey, by = "subject", link = c("survey", "response"), keep.x = c("freq"), keep.y = c("start_date", "end_date")) head(vaccination_steps) ``` -------------------------------- ### Setup ggalluvial Plotting Environment Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/labels.md Sets up the plotting environment for ggalluvial, including chunk options and loading necessary libraries. It also transforms the 'vaccinations' dataset to reverse the order of response levels for better intuitiveness. ```r knitr::opts_chunk$set(fig.width = 6, fig.height = 4, fig.align = "center") library(ggalluvial) ``` ```r data(vaccinations) vaccinations <- transform(vaccinations, response = factor(response, rev(levels(response)))) ``` -------------------------------- ### Convert Alluvia to Lodes Format Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/lode-ordering.html Use Stat*$setup_data() to convert data from alluvia format to lodes format for ggalluvial transformations. This can also be done manually using exported conversion functions. ```R data <- setNames(toy[, 2:3], c("x", "stratum")) # required fields for stat transformations data$y <- 1 data$PANEL <- 1 # stratum transformation StatStratum$compute_panel(data) ``` -------------------------------- ### Control Lode Ordering with Forward Guidance Source: https://context7.com/corybrunson/ggalluvial/llms.txt Controls lode ordering using 'forward' guidance and aesthetic binding. This example uses geom_flow with stat = "alluvium" and aes.bind = "alluvia". ```r ggplot(as.data.frame(Titanic), \ aes(y = Freq, axis1 = Class, axis2 = Sex, axis3 = Age)) + \ geom_stratum() + \ geom_text(stat = "stratum", aes(label = after_stat(stratum))) + \ geom_flow(aes(fill = Survived, alpha = Sex), \ stat = "alluvium", \ lode.guidance = "forward", \ aes.bind = "alluvia") + \ scale_x_discrete(limits = c("Class", "Sex", "Age")) ``` -------------------------------- ### Rightward flow aesthetics with cubic flows (vaccine data) Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/geom_flow.md Example using rightward flow aesthetics for vaccine survey data, with cubic flows. Note: This example is within a \ donttest{} block. ```r # \donttest{ # rightward flow aesthetics for vaccine survey data, with cubic flows data(vaccinations) vaccinations$response <- factor(vaccinations$response, rev(levels(vaccinations$response))) ``` -------------------------------- ### Prepare Data for Alluvia Source: https://github.com/corybrunson/ggalluvial/blob/main/vignettes/order-rectangles.rmd Prepares data for calculating alluvia and flows by including 'alluvium', 'x', and 'stratum' variables. Requires 'y' and 'PANEL' fields for stat transformations. ```r # collection point, category, and subject variables data <- structure(toy[, 1:3], names = c("alluvium", "x", "stratum")) # required fields for stat transformations data$y <- 1 data$PANEL <- 1 ``` -------------------------------- ### Example: Full axis width Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/geom_stratum.html This example demonstrates how to use geom_stratum with the Titanic dataset to visualize strata across different axes. It maps 'Class', 'Sex', 'Age', and 'Survived' to different axes. ```R ggplot(as.data.frame(Titanic), aes(y = Freq, axis1 = Class, axis2 = Sex, axis3 = Age, axis4 = Survived)) + ``` -------------------------------- ### Alluvia Ordering by Aesthetics Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/order-rectangles.md Use `aes.bind = "alluvia"` to prioritize aesthetics for ordering alluvia before strata. This sorts alluvia within each stratum by aesthetic properties. ```r ggplot(toy, aes(x = collection, stratum = category, alluvium = subject)) + stat_alluvium(aes(fill = class, label = subject), aes.bind = "alluvia") + stat_stratum() + stat_alluvium(geom = "text", aes(fill = class, label = subject), aes.bind = "alluvia") ``` -------------------------------- ### lode_zagzig Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/lode-guidance-functions.html Orders lodes by zigzagging inward from a starting index `i`. ```APIDOC ## lode_zagzig ### Description Orders the numbers 1 through `n`, starting at index `i` and zigzagging inward. ### Usage lode_zagzig(n, i) ### Arguments * **n** (numeric) - A positive integer. * **i** (numeric) - A positive integer at most `n`. ``` -------------------------------- ### Aesthetics Varying Both Ways with aes.bind='flows' Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/stat_flow.html Demonstrates setting aesthetics that vary both between and within strata using interaction and aes.bind='flows' for the 'vaccinations' dataset. ```r # can even set aesthetics that vary both ways ggplot(vaccinations, aes(x = survey, stratum = response, alluvium = subject, y = freq, label = response)) + geom_flow(aes(fill = interaction(response, subgroup)), aes.bind = "flows") + scale_alpha_discrete(range = c(1/3, 2/3)) + geom_stratum(alpha = .5) + geom_text(stat = "stratum") #> Warning: Using alpha for a discrete variable is not advised. # } ``` -------------------------------- ### lode_zigzag Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/lode-guidance-functions.html Orders lodes by zigzagging outward from a starting index `i`. ```APIDOC ## lode_zigzag ### Description Orders the numbers 1 through `n`, starting at index `i` and zigzagging outward. ### Usage lode_zigzag(n, i) ### Arguments * **n** (numeric) - A positive integer. * **i** (numeric) - A positive integer at most `n`. ``` -------------------------------- ### Load Vaccinations Data Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/vaccinations.md This R code snippet loads the 'vaccinations' dataset. Ensure the package providing this dataset is installed and loaded. ```r vaccinations ``` -------------------------------- ### Size Filter Examples for geom_flow (max.y) Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/stat_flow.html Demonstrates omitting large flows from the visualization using the 'max.y' aesthetic in geom_flow with the 'vaccinations' dataset. ```r # omit large flows gg + geom_flow(max.y = 100) ``` -------------------------------- ### StatStratum Compute Panel Logic Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/labels.md Illustrates the compute_panel method for StatStratum, detailing its parameters and how it infers labels if needed. ```r print(StatStratum$compute_panel) ``` -------------------------------- ### Plotting Lodes with a Single Axis Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/geom_lode.md Example of using geom_lode to plot lodes with a single axis, demonstrating aesthetic mappings for fill and alpha. ```r ggplot(as.data.frame(Titanic), aes(y = Freq, axis = Class)) + geom_lode(aes(fill = Class, alpha = Survived)) + scale_x_discrete(limits = c("Class")) + scale_alpha_manual(values = c(.25, .75)) ``` -------------------------------- ### Basic Alluvial Diagram Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/geom_alluvium.html A basic alluvial diagram using the Titanic dataset. This example demonstrates the fundamental mapping of axes and fill aesthetics. ```r ggplot(as.data.frame(Titanic), \ aes(y = Freq, \ axis1 = Class, axis2 = Sex, axis3 = Age, \ fill = Survived)) + \ geom_alluvium() + \ scale_x_discrete(limits = c("Class", "Sex", "Age")) ``` -------------------------------- ### Flows Ordering by Aesthetics Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/order-rectangles.md Use `aes.bind = "flows"` to prioritize aesthetics for ordering flows after strata. This sorts flows at each axis by aesthetic properties. ```r ggplot(toy, aes(x = collection, stratum = category, alluvium = subject)) + stat_alluvium(aes(fill = class, label = subject), aes.bind = "flows") + stat_stratum() + stat_alluvium(geom = "text", aes(fill = class, label = subject), aes.bind = "flows") ``` -------------------------------- ### Get Stratum Label and Width Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/shiny.html Retrieves the name and count (width) of a stratum from the processed plot data using the determined row index. ```R node_label <- pbuilt$data[[2]]$stratum[node_row] node_n <- pbuilt$data[[2]]$count[node_row] ``` -------------------------------- ### Negate Missing Entries in Alluvial Plot Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/stat_flow.md This example demonstrates how to negate specific strata, such as 'Missing', from being displayed in the plot. It applies to stat_stratum, geom_flow, and geom_text. ```R ggplot(vaccinations, aes(y = freq, x = survey, stratum = response, alluvium = subject, fill = response, label = response, alpha = response != "Missing")) + stat_stratum(negate.strata = "Missing") + geom_flow(negate.strata = "Missing") + geom_text(stat = "stratum", alpha = 1, negate.strata = "Missing") + scale_alpha_discrete(range = c(.2, .6)) + guides(alpha = "none") ``` -------------------------------- ### Prepare Data for Alluvial Transformation Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/order-rectangles.md Prepares the data by adding required fields 'y' and 'PANEL' before applying the `StatAlluvium$compute_panel` transformation. This is necessary for subsequent statistical transformations in ggalluvial. ```r data <- structure(toy[, 1:3], names = c("alluvium", "x", "stratum")) data$y <- 1 data$PANEL <- 1 StatAlluvium$compute_panel(data) ``` -------------------------------- ### Get Alluvium Label and Count (R) Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/shiny.md Extracts the connecting node labels and the count for the hovered alluvium. This information is used to populate the tooltip for alluvia. ```r coord_id <- rev(which(hover_within_flow == 1))[1] flow_label <- paste(groups_to_draw[[coord_id]]$stratum, collapse = ' -> ') flow_n <- groups_to_draw[[coord_id]]$count[1] ``` -------------------------------- ### Backfront Lode Guidance Example Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/order-rectangles.md Illustrates the 'backfront' lode guidance function. This function extends completely in one outward direction from the index axis before the other, prioritizing minimizing crossings with the immediately preceding axis. ```r for (i in 1:4) print(lode_backfront(4, i)) ``` -------------------------------- ### Illustrate Positioning with Titanic Data Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/reference/stat_flow.md This example demonstrates positioning in an alluvial plot using the Titanic dataset. It utilizes stat_stratum, geom_line with stat='flow', stat_flow, and geom_text with stat='stratum'. ```R ggplot(as.data.frame(Titanic), aes(y = Freq, axis1 = Class, axis2 = Sex, axis3 = Age, color = Survived)) + stat_stratum(geom = "errorbar") + geom_line(stat = "flow") + stat_flow(geom = "pointrange") + geom_text(stat = "stratum", aes(label = after_stat(stratum))) + scale_x_discrete(limits = c("Class", "Sex", "Age")) ``` -------------------------------- ### Aesthetic Binding with 'stat_flow' Source: https://github.com/corybrunson/ggalluvial/blob/main/docs/articles/lode-ordering.html Illustrates `aes.bind = TRUE` with `stat_flow`, which prioritizes flow aesthetics after the present axis and before the adjacent axis for ordering flows. ```R ggplot(toy, aes(x = collection, stratum = category, alluvium = subject)) + stat_flow(aes(fill = class), aes.bind = TRUE) + stat_stratum() + stat_stratum(geom = "text", aes(label = category)) ```