I created a summary data frame with just a single row for each n. Without knowing how your actual data is structured, it's hard to say if this is the most straightforward way.
Once that was done, I just added a black semi-transparent geom_col.
suppressPackageStartupMessages(library(tidyverse))
x <- tribble(
~n, ~a, ~b, ~c, ~d, ~cut,
1, 5, 5, 5, 5, 12,
2, 10, 4, 1, 2, 12,
3, 11, 0, 0, 14, 12,
4, 5, 7, 5, 0, 12
)
x <- x %>% gather(a:d, key = label, value = val)
ggplot(x) +
geom_col(aes(n, val, fill=label)) +
geom_col(
data = . %>% group_by(n) %>% summarize(cut = mean(cut)),
mapping = aes(x = n, y = 12),
fill = "black",
alpha = .5) +
theme_bw()
