I have a follow-up question on this one geom_flow since the question within the link did not cover the real problem.
In my dataset there are cases where individuals within the first time period fit into more than one category:
set.seed(123)
individual <- as.character(rep(1:3, each = 5))
timeperiod <- paste0(rep(c(1,2,3), 5), "_month")
sport <- factor(sample(c("soccer", "tabletennis", "mma"), prob = c(0.4, 0.4, 0.2), 15, replace = T))
d <- data.frame(individual, timeperiod, sport)
d %>%
count(individual, timeperiod, sport) %>%
ggplot(aes(x = timeperiod,
y = n,
stratum = sport,
alluvium = individual,
fill = sport,
label = sport)) +
geom_flow() +
geom_stratum()
When i try to plot this dataset with geom_flow an error message is thrown out that my data is not in alluvial form:
Error in
geom_flow()
: ! Problem while computing stat. ℹ Error occurred in the 1st layer. Caused by error insetup_data()
: ! Data is not in a recognized alluvial form (seehelp('alluvial-data')
for details). Runrlang::last_error()
to see where the error occurred.
How can i circumvent this issue?
One approach could be to map every possible path and assign a new ID to the column individual for the respective rows.