I have a dataset that looks something like this:
results <- as.data.frame(cbind(c("Violence", "Violence", "Violence", "Violence", "Economic", "Economic","Economic","Economic","Institutional","Institutional","Institutional","Institutional"),
c("No", "No", "Yes", "Yes","No", "No", "Yes", "Yes", "No", "No", "Yes", "Yes"),
c("Yes", "No", "Yes", "No","Yes", "No", "Yes", "No", "Yes", "No", "Yes", "No"),
c(3,3,1,3,4,5,8,7,6,5,4,3)))
colnames(results) <- c("Type", "Test1", "Test2", "Freq")
Then I create an alluvial plot with ggalluvial
library(ggplot2)
library(tidyverse)
library(ggalluvial)
ggplot(data = results,
aes(axis1 = Type, axis2 = Test1, axis3 = Test2,
y = Freq)) +
scale_x_discrete(limits = c("Article", "False 0s Removed", "New Flow Measure"), expand = c(.2, .05)) +
xlab("Results") +
geom_flow(aes(fill = Type)) +
geom_stratum() +
geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
theme_minimal() +
ggtitle("Replication Summary")
This looks fine except for each stratum I want the vertical order to be organized by the color (Type), so that each stratum is a bar chart of sorts where I can see what percentage of each Type are No and Yes for each test. How would I change so the vertical ordering is grouped by color ($type) at each stratum (Test1 and Test2). At current the second stratum (Test 1) looks good but the the third does not (test 2)