data %>%
group_by(area, brand) %>%
summarise(count = n(), .groups = "drop") %>%
mutate(brand_order = paste(brand, area, rank(-count), sep = "_")) %>%
ggplot(aes(reorder(brand_order, -count),
count, fill = brand)) +
geom_col()+
facet_wrap(~ area, scales = "free_x", ncol = 3) +
geom_text(aes(label = count), vjust = -0.5) +
scale_x_discrete(labels = function(x) gsub("_.+$", "", x)) + # 移除排序编号
scale_y_continuous(limits = c(0, 42)) +
labs(x = "品牌", y = "数量") +
theme(axis.text.x = element_text(angle = 42, hjust = 1),
legend.position = "none")