It's my first time using the ggalluvial
package and I have problems to adapt the design for my purposes.
Consider this example data I came up with:
data <- data.frame(person = c(rep("x",5), rep("y",2), rep("z",4), rep("w",2), rep("v",7)), # Create new data frame
disease = c("ADHD", "Depression", "Phobia", "Schizophrenia", "Bipolar"),
marker1 = c(sample(paste("cz",1:15, sep="")), "cz4", "cz5", "cz10", "cz1", "cz3"),
marker2 = rep(paste("ab",1:10,sep=""), 2),
domain = c("Development", "Mood", "Anxiety", "Psychiatric", "Psychiatric"),
freq = 1)
This is the plot I have so far:
ggplot(data = data,
aes(axis1 = disease,
axis2 = person,
axis3 = marker1,
axis4 = marker2,
y = freq)) +
geom_alluvium(aes(fill = domain), curve_type = "linear", width=0.8) +
geom_stratum(alpha = .5, width=0.8) +
geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
theme_void()
Note that I added 'freq' just to have more common heights of the bars and that the actual data is a lot larger and names are often longer.
With the plot I want to show relationships because the axes. My first problem is:
I would like to sort the first axis ('disease' here) according to 'domain'. So I would like to have first all 'Phobia' because 'Anxiety' is the first domain, then 'ADHD' for 'Development' etc... (in the real data there would be more diseases per domain). They should correspond with the order in the legend.
Then, I would like to have smaller lines. Is this possible?
Finally, I wonder if I could set a minimum and maximum height for every box/strata (in the more complex data set they differ, e.g. 'ADHD' could be very small (nearly not readable) and 'Schizophrenia' very large)?
Thank you for any help!