Don't think this is a duplicate of others, but happy to delete if it is.
Dataset contains 3 columns: 'Recipient' (x-axis), 'Amount' (y-axis), and 'Department'(grid-column/fill).
How can I re-order facet grids more intuitively in descending order by total 'Amount' spent for each 'Department'? (Blue first, since it has spent the most 'Amount' & has the highest # of 'Recipients', probably followed by turquoise, then green, etc.)
R script:
library("tidyverse")
library("ggthemes")
library("gganimate")
library("readxl")
library("httr")
library("rvest")
library("scales")
library("tidytext")
source_file <- "Houston City Council 2020-06-16.xlsx"
agenda_prime <- read_xlsx(source_file, sheet = 6, col_names = TRUE)
agenda_reordered <- agenda_prime %>%
# mutate(Recipient = fct_reorder(Recipient, desc(Amount)))
mutate(
Recipient = reorder_within(Recipient, desc(Amount), Department))
plot <- agenda_reordered %>%
ggplot(aes(Recipient, Amount, fill = Department, label = dollar(Amount))) +
geom_col(show.legend = FALSE) +
labs(title = "$ spent during this week's City Council meeting",
subtitle = "Wednesday, June 17, 2020",
caption = "Sources: City of Houston, City Council Agenda, June 16 & 17, 2020 & HTV broadcast of 6/17 agenda session",
x = "",
y = "") +
theme_solarized_2(light = FALSE) +
theme(legend.position = "top", legend.direction = "horizontal", legend.title = element_blank()) +
scale_y_continuous(labels = dollar_format(prefix = "$")) +
# geom_text(aes(Vote, Number+3), size = 3, color = "gray")
facet_grid(cols = vars(Department), scales = "free_x", space = "free_x") +
theme(strip.text.x = element_blank(), strip.background = element_blank(), axis.text.x = element_text(angle=0, size=2))
plot
Source dataset:
THANKS!!!