I want to keep the second axis of an alluvial plot in the same order as the first axis. Namely as the first axis is a higher-level taxonomy of the second, its main purpose is to show an overview and grouping of the organisms to enhance readability of the graph. For this, I tried to manually order the strata. All that I achieved, however, was reshuffling the lodes instead of the strata (e.g. from this tutorial or playing with the lode.guidance
).
Does someone have an idea how to solve this? In the end, all the lodes between the first and the second axis should flow horizontally and sort then from the second into the third as it is.
A short version of the data (still quite extensive, sorry):
taxa <- structure(list(Order = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L,
32L, 32L, 32L, 32L, 32L, 32L, 32L,
32L, 32L, 32L, 32L, 32L, 32L),
.Label = c("Adinetida", "Cercomonadidae_or",
"Cercozoa_unclassified",
"Chaetopeltidales",
"Chlorophyta_ph_unclassified",
"Chromulinales",
"Chrysophyceae_unclassified",
"Chytridiomycetes_unclassified",
"Conthreep", "Craspedida_or",
"Cryomonadida", "Cryptomonadales",
"Cystobasidiales",
"Cystobasidiomycetes_unclassified",
"Cystofilobasidiales",
"Dinophyceae_unclassified",
"Diplogasterida",
"Glissomonadida_or",
"Helotiales", "Imbricatea_unclassified",
"Incertae_Sedis",
"Intramacronucleata_unclassified",
"Leotiomycetes_unclassified", "LG08-10_or",
"Litostomatea", "Monhysterida",
"Ochromonadales",
"Ochrophyta_ph_unclassified",
"Parachela",
"Peronosporomycetes_or",
"Phragmoplastophyta_unclassified",
"Saccharomycetales",
"Spirotrichea", "Spongomonadida",
"Thecofilosea_unclassified",
"Tremellales", "Tremellomycetes_or",
"Tremellomycetes_unclassified",
"Trichosporonales"),
class = "factor"),
Genus = c(paste(rep("Poterioochromonas", 19)),
paste(rep("Colpoda", 9)),
paste(rep("Colpodea_unclassified", 24)),
paste(rep("Colpodida_ge", 28)),
paste(rep("Conthreep_unclassified", 4)),
"Cryptocaryon", "Cyclidium",
paste(rep("Nassophorea_unclassified", 2)),
"Platyophrya", paste(rep("Tetrahymena", 5)),
paste(rep("uncultured", 3)),
paste(rep("uncultured_ge", 4)), "Glarea",
paste(rep("Helotiales_unclassified_ge", 13)),
paste(rep("Chrysolepidomonas", 12)), "Ochromonas",
paste(rep("Debaryomycetaceae_unclassified", 3)),
"Pichiaceae_unclassified_ge",
paste(rep("Saccharomycetaceae_unclassified", 5)),
paste(rep("Yarrowia", 4))),
Freq = rep(1, 141),
Habitat = c("B", "B", "B", "B", "B", "B", "B","B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "A", "A", "A",
"B", "A", "A", "B", "B", "B", "B", "A", "A", "A", "A",
"B", "A", "A", "A", "A", "B", "A", "B", "B", "A", "B",
"B", "B", "A", "A", "A", "B", "B", "B", "A", "A", "A",
"A", "A", "A", "A", "A", "B", "A", "B", "A", "B", "B",
"A", "A", "B", "B", "A", "B", "A", "B", "B", "A", "A",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "A", "A",
"B", "A", "A", "B", "B", "B", "A", "B", "B", "A", "B",
"B", "B", "A", "A", "A", "A", "A", "A", "A", "A", "B",
"A", "B", "A", "B", "A", "A", "A", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"A", "A", "B", "A", "B", "A", "B", "B", "B")),
class = "data.frame", row.names = seq(1:141))
And here the alluvial diagram that comes out with the three axes sorted alphabetically:
library("ggalluvial")
ggplot(data = taxa,
aes(axis1 = Order, axis2 = Genus, axis3 = Habitat, y = Freq)) +
stat_alluvium(aes(fill = Habitat)) +
geom_stratum(linetype = 1, lwd = 0.01) +
geom_text(stat = "stratum", infer.label = TRUE, size = 3) +
theme_void() +
theme(legend.position = "none")