【发布时间】:2021-04-20 16:42:55
【问题描述】:
我需要弄清楚如何根据特定变量调整绘图的宽度,而无需更改 facet_wrap 函数的 scales = "free" 参数。我尝试使用基于变量调整条形宽度的case_when,但出现错误。
以下是可重现的示例,显示了我遇到的问题。
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")
【问题讨论】:
标签: r ggplot2 facet-wrap