I have a simple data.frame, made into a simple alluvial map using the alluvial package. How can I edit the plot? My questions, in order of importance, are:
- Change the color scheme so that flows coming from the same "Admitted To" unit are the same color.
- Add a title
- Save this plot so I can later plot it into a grid with a few ggplots
Caveat: ggalluvial might be easier but unfortunately I can't install it at work, so the solution needs to use base r, ggplot, or the alluvial package.
library(alluvial)
df <- structure(list(Admitted.To =
c("UnitC", "UnitC", "UnitC", "UnitC", "UnitD", "UnitD",
"UnitD", "UnitD", "UnitE", "UnitE", "UnitE", "UnitF",
"UnitB", "UnitB", "UnitB", "UnitB", "UnitB", "UnitG",
"UnitH", "UnitA", "UnitA", "UnitA", "UnitA", "UnitA"),
Discharged.From = c("UnitC", "UnitD", "UnitE", "UnitA",
"UnitC", "UnitD", "UnitE", "UnitA",
"UnitD", "UnitE", "UnitA", "UnitF",
"UnitD", "UnitI", "UnitE", "UnitB",
"UnitA", "UnitG", "UnitH", "UnitC",
"UnitD", "UnitI", "UnitE", "UnitA"),
n = c(136, 2, 1, 2, 1, 162, 2, 3, 1, 213, 1, 3, 5, 1, 7,
22, 23, 1, 32, 10, 9, 39, 9, 607)),
.Names = c("Admitted.To", "Discharged.From", "n"),
row.names = c(NA, -24L),
class = c("tbl_df", "tbl", "data.frame"))
I've been using the color code below until I figure out how to map the colors to the "Admitted To" group
set.seed(8) # for nice colors
cols <- hsv(h = sample(1:8/10), s = sample(3:8)/8, v = sample(3:8)/8)
And my alluvial plot code:
alluvial(df[,1:2],
freq = 8,
blocks = T,
col = cols)
I've tried adding title = "SampleTitleHere"
into my code but it just plots another column. I haven't found much documentation on this package.