p1 <- ggplot(school, aes(연도, 학교수, fill = fct_rev(학교급))) +
geom_col() +
geom_text(
aes(y = 추가, label = ifelse(
학교수 <= 999, 학교수, format(학교수, big.mark = ",")
)),
size = 3
) +
geom_text(
aes(y = 추가, label = ifelse(학교급 == "기타", format(누계, big.mark = ","), "")),
size = 3, vjust = -2
) +
scale_x_discrete(expand = c(0.08, 0.08)) +
scale_y_continuous(labels = function(x) {
ifelse(x <= 999, x, format(x, big.mark = ","))
}, expand = c(0.01, 0.1), limits = c(0, 25000)) +
scale_fill_brewer(palette = "Set2", labels = c("유", "초", "중", "고", "기타")) +
theme_bw() +
theme(
plot.background = element_blank(),
panel.background = element_blank(),
panel.border = element_blank(),
axis.line.y.left = element_line(size = 0.3),
axis.line.x.bottom = element_line(size = 0.3),
axis.title.x = element_blank(),
legend.title = element_blank(),
legend.position = "bottom",
legend.background = element_blank(),
legend.margin = margin(0, 0, 0, 0)
) +
guides(
fill = guide_legend(keywidth = 0.3, keyheight = 0.3, default.unit = "cm")
)