'Issue with preparing dataset for use with ggalluvial and creating alluvial diagram

I am new to using the ggalluvial package. I presently am working with a dataset of donations that I would like to represent using an alluvial diagram as a medium. Below is a sample of the dataset that I am working with:

   donor_ID recip_name donation_amt month_year    
   <chr>    <chr>             <dbl> <chr>         
 1 1        B, P                 25 September 2019
 2 2        S, B                 27 July 2019     
 3 3        K, A                 50 June 2019     
 4 1        H, K                100 April 2019    
 5 2        W, E                  3 December 2019 
 6 3        S, B                  9 August 2019   
 7 1       C, J                 25 September 2019
 8 2       B, J                 50 October 2019  
 9 3       W, E                400 August 2019   
10 1       S, B                 20 December 2019 

The output of dput() on this datset is as follows:

structure(list(donor_ID = c("1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1"), recip_name = c("B, P", "S, B", "K, A", "H, K", 
"W, E", "S, B", "C, J", "B, J", "W, E", "S, B"), donation_amt = c(25, 
27, 50, 100, 3, 9, 25, 50, 400, 20), month_year = c("September 2019", 
"July 2019", "June 2019", "April 2019", "December 2019", "August 2019", 
"September 2019", "October 2019", "August 2019", "December 2019"
)), class = "data.frame", row.names = c(NA, -10L))

I am looking to represent the choice made by individual donors of who receives (recip_name) their donation may change from month to month (donor preference), whereas donor_ID represents individual donors. The resulting alluvial diagram should show said changes between each month in a way that is also proportional to the total donation amounts (donation_amt) moving between recipient. Below is the script I have written to accomplish this:

df$recip_name <- as.factor(df$recip_name)
df %>% 
  filter(transaction_dt < as.Date("2020-01-01")) %>% 
  select(donor_ID, recip_name, donation_amt, month_year) %>% 
  ggplot(aes(x = month_year, y = donation_amt, stratum = recip_name,
             alluvium = donor_ID, fill = recip_name, label = recip_name)) +
  scale_fill_brewer(type = "qual", palette = "Set2") +
  geom_flow(stat = "alluvium", color = "darkgray") +
  geom_stratum() +
  theme_light() +
  theme(legend.position = "bottom") +
  ggtitle("Donor Preference")

Upon executing this R code, this is the resulting error I receive:

Error in f(...) : 
  Data is not in a recognized alluvial form (see `help('alluvial-data')` for details).

I have done research on what is already out there on issues with properly setting up data for use in ggalluvial, to no avail. How can I properly develop the desired alluvial diagram using this data?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source