Description Usage Arguments Value Note Examples
Drawing alluvial diagrams, also known as parallel set plots.
1 2 3 4 |
... |
vectors or data frames, all for the same number of observations |
freq |
numeric, vector of frequencies of the same length as the number of observations |
col |
vector of colors of the stripes |
border |
vector of border colors for the stripes |
layer |
numeric, order of drawing of the stripes |
hide |
logical, should particular stripe be plotted |
alpha |
numeric, vector of transparency of the stripes |
gap.width |
numeric, relative width of inter-category gaps |
xw |
numeric, the distance from the set axis to the control points of the xspline |
cw |
numeric, width of the category axis |
blocks |
logical, whether to use blocks to tie the flows together at each category, versus contiguous ribbons (also admits character value "bookends") |
ordering |
list of numeric vectors allowing to reorder the alluvia on each axis separately, see Examples |
axis_labels |
character, labels of the axes, defaults to variable names in the data |
cex, cex.axis |
numeric, scaling of fonts of category labels and axis labels respectively. See |
Invisibly a list with elements:
endpoints |
A list of matrices of y-coordinates of endpoints of the alluvia. x-coordinates are consecutive natural numbers. |
Please mind that the API is planned to change to be more compatible with dplyr verbs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | # Titanic data
tit <- as.data.frame(Titanic)
# 2d
tit2d <- aggregate( Freq ~ Class + Survived, data=tit, sum)
alluvial( tit2d[,1:2], freq=tit2d$Freq, xw=0.0, alpha=0.8,
gap.width=0.1, col= "steelblue", border="white",
layer = tit2d$Survived != "Yes" )
alluvial( tit2d[,1:2], freq=tit2d$Freq,
hide=tit2d$Freq < 150,
xw=0.0, alpha=0.8,
gap.width=0.1, col= "steelblue", border="white",
layer = tit2d$Survived != "Yes" )
# 3d
tit3d <- aggregate( Freq ~ Class + Sex + Survived, data=tit, sum)
alluvial(tit3d[,1:3], freq=tit3d$Freq, alpha=1, xw=0.2,
col=ifelse( tit3d$Survived == "No", "red", "gray"),
layer = tit3d$Sex != "Female",
border="white")
# 4d
alluvial( tit[,1:4], freq=tit$Freq, border=NA,
hide = tit$Freq < quantile(tit$Freq, .50),
col=ifelse( tit$Class == "3rd" & tit$Sex == "Male", "red", "gray") )
# 3d example with custom ordering
# Reorder "Sex" axis according to survival status
ord <- list(NULL, with(tit3d, order(Sex, Survived)), NULL)
alluvial(tit3d[,1:3], freq=tit3d$Freq, alpha=1, xw=0.2,
col=ifelse( tit3d$Survived == "No", "red", "gray"),
layer = tit3d$Sex != "Female",
border="white", ordering=ord)
# Possible blocks options
for (blocks in c(TRUE, FALSE, "bookends")) {
# Elaborate alluvial diagram from main examples file
alluvial( tit[, 1:4], freq = tit$Freq, border = NA,
hide = tit$Freq < quantile(tit$Freq, .50),
col = ifelse( tit$Class == "3rd" & tit$Sex == "Male",
"red", "gray" ),
blocks = blocks )
}
# Data returned
x <- alluvial( tit2d[,1:2], freq=tit2d$Freq, xw=0.0, alpha=0.8,
gap.width=0.1, col= "steelblue", border="white",
layer = tit2d$Survived != "Yes" )
points( rep(1, 16), x$endpoints[[1]], col="green")
points( rep(2, 16), x$endpoints[[2]], col="blue")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.