-1

I have been using code that is verbatim to that in: https://www.r-bloggers.com/2022/10/how-to-create-a-ggalluvial-plot-in-r/ in order to produce an alluvial plot. While I can get the plot to appear:

My Code:

    #install.packages("ggalluvial")
    library(ggalluvial)

    ggplot(data = Sankey_Table, aes(axis1 = source, axis2 = target, y = value)) +
      geom_alluvium(aes(fill = source)) +
      ggalluvial::geom_stratum(alpha = 0.5, na.rm = TRUE) +
      geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
      scale_x_discrete(limits = c("Source", "Target"),
                       expand = c(0.15, 0.05)) +
      theme_void() 

My Data:

> head(Sankey_Table)
# A tibble: 6 × 5
  source              target               value
  <chr>               <chr>                <dbl>
1 pre :: H0         post :: H0              31
2 pre :: H0         post :: Hlow            11
3 pre :: H0         post :: pCR             12
4 pre :: H0         post :: NA               1
5 pre :: Hlow       post :: H0              28
6 pre :: Hlow       post :: Hlow            29

When I run the above code, I get this error message and the following image:

Warning messages:
1: Computation failed in `stat_stratum()`:
unused argument (na_rm = na_rm) 
2: Computation failed in `stat_stratum()`:
unused argument (na_rm = na_rm) 

The output figure

I have no idea why the labels are not appearing as they do on the reference website, using essentially the same code and a dataframe formatted the exact same way. I have been having some difficulty getting labels to appear with ggsankey as well using the geom_text function and have been at a loss as to what to do. I've tried re-installing the ggplot2 and alluvial packages, and changing around the argument order to just about every combination I can think of.

Any help would be enormously appreciated.

I am expecting something to the effect of: enter image description here

The above plot was generated using the exact same code (link is above).

stefan
  • 90,330
  • 6
  • 25
  • 51
  • Welcome to SO! Would you mind sharing your data via `dput()` instead of the output of `print()`? Doing so makes your data reproducible and makes it much much easier for others to copy your data and run your code. Simply type `dput(head(Sankey_Table))` in the console and copy the output into your post. – stefan Feb 09 '23 at 19:30
  • 1
    Hi! The code you provided is working fine for me using R version 4.2.2 and ggalluvial 0.12.3 – Susan Switzer Feb 09 '23 at 21:00

1 Answers1

0

Somebody says above that all it's working with ggalluvial 0.12.3, so I checked, I was having the same problem but with 0.12.4, so I used

require(devtools)
install_version("ggalluvial", version = "0.12.3", repos = "http://cran.us.r-project.org")

to install the old version, and it worked.

Marco
  • 2,368
  • 6
  • 22
  • 48