这里有点重写。关键是转换数据
into long form
:
library(tidyverse)
df <- read_table("region total primary secondary post16
East 21 4 8 9
Mid 28 3 15 10
North 7 2 4 1
South 13 3 5 5")
df %>%
dplyr::select(-total) %>%
pivot_longer(-region) %>%
mutate(name = fct_relevel(name, "primary", "secondary", "post16")) %>%
ggplot(aes(x = region, y = value, fill = name)) +
geom_col() +
coord_flip()