Description Usage Arguments Examples
this function produces an alluvial diagram. This function is a copy of alluvial::alluvial but a 'rotate' option is added to rotate the labels.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
... |
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 |
numeric, scaling of fonts of category labels and axis labels respectively. See |
cex.axis |
cex value to be passed to the axis. See help(par) |
rotate |
angle to rotate the labels. This argument is passed as an |
las |
direction of the labels of the covariates. 1 is horizontal, 2 is vertical. |
bottom.mar |
bottom margin to be passed as a first argument to |
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 | library(dplyr)
# Alluvial plot
# Load the data to be used
data(prca)
dat <- prca
dat$trt = dat$rx
dat %>%
dplyr::select(trt, bm, hx, pf) %>%
dplyr::group_by(trt, bm, hx, pf) %>%
dplyr::summarise(Freq = n()) -> alldat
alldat %>%
ungroup() %>%
mutate(trt = ifelse(trt == 0 , "Control", "Treatment"),
bm = ifelse(bm == 0 , "No", "Yes"),
hx = ifelse(hx == 0 , "No", "Yes"),
pf = ifelse(pf == 0 , "No", "Yes"))-> alldat
plot_alluvial(alldat[,c(1,3,2,4)], freq = alldat$Freq,
xw=0.2,cw = 0.12,cex = 1,
alpha = 0.8,
col=ifelse(alldat$trt == "Treatment","#1f78b4", "#a6cee3"),
layer = alldat$trt == 1, rotate = 90)
# Alluvial plot using survival rate at 24 months
data(prca)
dat <- prca
dat %>%
mutate(survival = factor(ifelse(survtime > 24 , "Yes", "No"), levels = c("No", "Yes")),
trt = rx) -> dat
dat %>%
dplyr::select(trt, bm, hx, pf, survival) %>%
dplyr::group_by(trt, bm, hx, pf, survival) %>%
dplyr::summarise(Freq = n()) -> alldat
alldat %>%
ungroup() %>%
mutate(trt = ifelse(trt == 0 , "Control", "Treatment"),
bm = ifelse(bm == 0 , "No", "Yes"),
hx = ifelse(hx == 0 , "No", "Yes")) -> alldat
plot_alluvial(alldat[,c(5,1,3,2,4)], freq = alldat$Freq,
xw=0.2,cw = 0.12,cex = 1,
alpha = 0.8,
col=ifelse(alldat$survival == "Yes",
ifelse(alldat$trt == "Treatment","#80b1d3","#d5e2eb"),
ifelse(alldat$trt == "Treatment","#faa8d2","#fbe0ee")),
layer = alldat$trt == 1, rotate = 90, las = 2, bottom.mar = 5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.