I need to figure out how to adjust the width of a plot for based on a a specific variable without having the change the scales = "free" parameter of facet_wrap function. I tried using the a case_when that adjusts the width of the bar based on the variable, but I get an error.
below is reproducible example that shows the issue I'm having.
library(tidyverse)
set.seed(1)
data.frame(date = rep(seq.Date(Sys.Date()
, by = "day", length.out = 10), 3)
,Time = rep(c("AM","PM"), each = 30)
,office = rep(LETTERS[1:3], 2)
,n = sample(c(50:100),60, replace = TRUE)) %>%
add_row(date = Sys.Date(), Time = "AM", office = "Z", n = 80) %>%
ggplot(aes(x = date, y = n, group = office)) +
geom_bar(stat = 'identity', position = 'stack'
,width = .7, show.legend = FALSE, alpha =.75) +
facet_wrap(vars(office, Time), ncol = 2, labeller = "label_both",
scales = "free")
