You no longer need to calculate the position variable. Starting in ggplot2_2.2.0, text can be stacked and centered via position_stack
.
The relevant line of geom_text
code is below. Notice I don't need to use the "pos" variable at all for text placement.
geom_text(aes(label=paste0(value,"%")),
position = position_stack(vjust = .5), size = 2, color = "black")
The code for the plot and the resulting graph:
ggplot(dre, aes(factor(sex), value, fill = variable)) +
geom_col() +
facet_wrap(factor(year)~area) +
geom_text(aes(label = paste0(value,"%")),
position = position_stack(vjust = .5), size = 2, color = "black") +
coord_flip() +
theme_bw() +
scale_fill_brewer()