corybrunson / ggalluvial

ggplot2 extension for alluvial plots
http://corybrunson.github.io/ggalluvial/
GNU General Public License v3.0
499 stars 34 forks source link

Reversal of factor levels in vignette example changes data #66

Closed jtr13 closed 4 years ago

jtr13 commented 4 years ago

Thank you for a great package.

I'd like to point out that the line levels(vaccinations$response) <- rev(levels(vaccinations$response)) in the package vignette erroneously relabels the factor levels:

library(ggalluvial)
#> Loading required package: ggplot2
    data(vaccinations)
    summary(vaccinations$response)
#>   Missing     Never Sometimes    Always 
#>        26        25        37        29
    levels(vaccinations$response) <- rev(levels(vaccinations$response))
    summary(vaccinations$response)
#>    Always Sometimes     Never   Missing 
#>        26        25        37        29

Created on 2020-10-14 by the reprex package (v0.3.0)

In order to keep the levels as they are and only change their order, it should be:

library(ggalluvial)
#> Loading required package: ggplot2
    data(vaccinations)
    summary(vaccinations$response)
#>   Missing     Never Sometimes    Always 
#>        26        25        37        29
    vaccinations$response <- factor(vaccinations$response, levels = rev(levels(vaccinations$response)))
    summary(vaccinations$response)
#>    Always Sometimes     Never   Missing 
#>        29        37        25        26

Created on 2020-10-14 by the reprex package (v0.3.0)

(Or: vaccinations$response <- forcats::fct_rev(vaccinations$response))

corybrunson commented 4 years ago

Thank you so much @jtr13 for pointing this out! That code traces way back and i guess i never carefully vetted it once i better understood how factors work. I'll get to work on a patch ASAP—there are several other places, including examples, where the error has metastasized.

jtr13 commented 4 years ago

Sure, thanks again for this awesome package.

corybrunson commented 4 years ago

The issue is resolved in commit 99ff7b4023e217321c89c1599269e1c19543f85a, and the website in particular is updated accordingly. Because the exported code has not been changed, and to avoid overburdening the maintainers, i will wait until the next code patch or feature upgrade to resubmit to CRAN. : )