Alluvial diagrams consist of multiple horizontally-distributed columns (axes) representing factor variables, vertical divisions (strata) of these axes representing these variables' values; and splines (alluvial flows) connecting vertical subdivisions (lodes) within strata of adjacent axes representing subsets or amounts of observations that take the corresponding values of the corresponding variables. This function checks a data frame for either of two types of alluvial structure:
One row per lode, wherein each row encodes a subset or
amount of observations having a specific profile of axis values, a
key
field encodes the axis, a value
field encodes the
value within each axis, and a id
column identifies multiple
lodes corresponding to the same subset or amount of observations.
One row per alluvium, wherein each row encodes a subset or
amount of observations having a specific profile of axis values and a
set axes
of fields encodes its values at each axis variable.
If no arguments are assigned to any of these parameters, then
is_alluvial
will default to is_alluvial_alluvia
and assume that
all fields in data
(other than weight
, if given) are to be
treated as axes.
is_alluvial(data, ..., logical = TRUE, silent = FALSE) is_alluvial_lodes(data, key, value, id, weight = NULL, logical = TRUE, silent = FALSE) is_alluvial_alluvia(data, axes, weight = NULL, logical = TRUE, silent = FALSE)
data | A data frame. |
---|---|
... | Additional parameters used to determine method and passed
thereto. All or none of |
logical | Whether to return a logical value (TRUE, the default) or a character string indicating the type of alluvial structure ("none", "lodes", or "alluvia") |
silent | Whether to print warning messages. |
key, value, id | Numeric or character; the fields of |
weight | Optional numeric or character; the fields of |
axes | Numeric or character vector; the field(s) of |
# Titanic data in alluvium form titanic_alluvia <- as.data.frame(Titanic) is_alluvial(titanic_alluvia, weight = "Freq")#> [1] TRUE# Titanic data in lode form titanic_lodes <- suppressWarnings(tidyr::gather( dplyr::mutate(titanic_alluvia, Index = 1:nrow(titanic_alluvia)), "Variable", "Value", axes = 1:4, factor_key = TRUE )) titanic_lodes$Value <- factor(titanic_lodes$Value, levels = do.call(c, lapply(titanic_alluvia[, 1:4], levels))) is_alluvial(titanic_lodes, key = "Variable", value = "Value", id = "Index", weight = "Freq", logical = FALSE)#> [1] "lodes"