is there a way to reorder those facets based on their Y value (aka count ) in decreasing order dynamically - without hardcoding the order (given a similar column to package with hundreds of levels?
library(cranlogs)
library(tidyverse)
tidyverse_downloads <- cran_downloads(
packages = pkgs,
from = "2017-01-01",
to = "2017-06-30") %>%
tibble::as_tibble() %>%
group_by(package)
tidyverse_downloads %>%
ggplot(aes(x = date, y = count)) +
#geom_hline(yintercept = 0, color = "grey40") +
geom_line() +
#geom_smooth(method = "loess") +
theme_minimal() +
facet_wrap(~ package, scale = "free_y",ncol = 2) + theme(axis.text.x = element_text(angle = 90, hjust = 1))
What I have tried was to use the package library(tidytext) and scale_y_reordered
tidyverse_downloads %>%
mutate(count = tidytext::reorder_within(count, date, package)) %>%
tidytext::scale_y_reordered() +
ggplot(aes(x = date, y = count)) +
geom_line() +
theme_minimal() +
facet_wrap(~ package, scale = "free_y",ncol = 2) + theme(axis.text.x = element_text(angle = 90, hjust = 1))
however, that doesn't produce any outcome. Im doing something wrong I guess. Appreciate any help

