for those playing along with the home game, what I'm doing here is trying to reverse the sort order in a waterfall chart. Line 276 of this: https://github.com/CerebralMastication/waterfalls/blob/master/R/waterfall.R
In practice it looks like this:
devtools::install_github("CerebralMastication/waterfalls")
library(waterfalls)
library(tidyverse)
waterfall(
tibble(category = letters[1:5],
value = c(200, -20, 4, 20, -150)),
calc_total = TRUE,
fill_by_sign = FALSE,
put_rect_text_outside_when_value_below = 50,
coord_flip = FALSE
) -> p
p

layer_data(p)
#> x y PANEL group
#> 1 1 0 1 1
#> 2 2 200 1 2
#> 3 3 180 1 3
#> 4 4 184 1 4
#> 5 5 204 1 5
#> 6 6 200 1 6
#> 7 1 180 1 1
#> 8 2 184 1 2
#> 9 3 204 1 3
#> 10 4 54 1 4
#> 11 5 204 1 5
#> 12 6 54 1 6
So in our input tibble we only had 5 categories, but in our output we have 6 because a total was added. That's an example of the logic that keeps me from knowing ex ante what data frame will be in the plot.
The reason I want to molest the sort order is this happens when I flip my coord:
waterfall(
tibble(category = letters[1:5],
value = c(200, -20, 4, 20, -150)),
calc_total = TRUE,
fill_by_sign = FALSE,
put_rect_text_outside_when_value_below = 50,
coord_flip = TRUE
) -> p
p

And I want those reversed so it reads top to bottom.
I can't just call scale_x_reverse() because a scale is already set in the code elsewhere.