ggalluvial icon indicating copy to clipboard operation
ggalluvial copied to clipboard

add comment about different widths to main vignette

Open mw55309 opened this issue 2 years ago • 3 comments

Description of the issue

I'm sorry if this has been mentioned before, but the flows overlap the boundaries of the columns and I am not sure why, even in thee Titanic example

Reproducible example (preferably using reprex::reprex())

ggplot(as.data.frame(Titanic),
       aes(y = Freq,
           axis1 = Survived, axis2 = Sex, axis3 = Class)) +
  geom_alluvium(aes(fill = Class),
                width = 0, knot.pos = 0, reverse = FALSE) +
  guides(fill = FALSE) +
  geom_stratum(width = 1/8, reverse = FALSE) +
  geom_text(stat = "stratum", aes(label = after_stat(stratum)),
            reverse = FALSE) +
  scale_x_continuous(breaks = 1:3, labels = c("Survived", "Sex", "Class")) +
  coord_flip() +
  ggtitle("Titanic survival by class and sex")

ggaluvial

If you look at the purple (far right) flow between "Crew" and "Male", it clearly overlaps the boundary between "3rd" and "Crew", then also between "Male" and "Female".

The flows overlap the boundaries in multiple locations.

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_1.0.8       alluvial_0.1-2    readxl_1.3.1      ggalluvial_0.12.3 ggplot2_3.3.5    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7       magrittr_2.0.1   tidyselect_1.1.1 munsell_0.5.0    colorspace_2.0-2 R6_2.5.0         rlang_1.0.2     
 [8] fansi_0.5.0      tools_4.0.2      grid_4.0.2       gtable_0.3.0     utf8_1.2.1       cli_3.0.1        DBI_1.1.1       
[15] withr_2.4.2      ellipsis_0.3.2   digest_0.6.27    assertthat_0.2.1 tibble_3.1.2     lifecycle_1.0.1  crayon_1.4.1    
[22] farver_2.1.0     tidyr_1.1.3      purrr_0.3.4      vctrs_0.3.8      glue_1.4.2       labeling_0.4.2   cellranger_1.1.0
[29] compiler_4.0.2   pillar_1.6.1     generics_0.1.0   scales_1.1.1     pkgconfig_2.0.3 

mw55309 avatar Apr 11 '22 09:04 mw55309

Hi @mw55309 and thanks for checking! I don't remember if this is explicitly documented anywhere, and maybe it should be mentioned in the vignette with this example. I believe it's due to the difference between the choices of width for the alluvia versus for the strata. If you set them to the same value, do they match?

corybrunson avatar Apr 11 '22 10:04 corybrunson

Yes, that fixes it, thank you!

ggplot(as.data.frame(Titanic),
       aes(y = Freq,
           axis1 = Survived, axis2 = Sex, axis3 = Class)) +
  geom_alluvium(aes(fill = Class),
                width = 1/8, knot.pos = 0, reverse = FALSE) +
  guides(fill = FALSE) +
  geom_stratum(width = 1/8, reverse = FALSE) +
  geom_text(stat = "stratum", aes(label = after_stat(stratum)),
            reverse = FALSE) +
  scale_x_continuous(breaks = 1:3, labels = c("Survived", "Sex", "Class")) +
  coord_flip() +
  ggtitle("Titanic survival by class and sex")

It may be worthwhile updating the vignette?

mw55309 avatar Apr 11 '22 11:04 mw55309

Sure, i'll leave this issue open as a reminder for the next time i revise the package.

Good to know that it worked, thanks!

corybrunson avatar Apr 11 '22 13:04 corybrunson

Resolved in 0b71a4d3e5de93a9db2a9c7491424c43d21f3449, i think!

corybrunson avatar Jul 09 '23 19:07 corybrunson