Adding label in the center of the bar in geom_bar

Working with the sample data provided by FJCC, your code could work if you define the fill aesthetic globally (or if you define the group aesthetic on geom_text()), see this example.

library(ggplot2)

DF <- data.frame(Name = c("A", "A", "B", "B", "C", "C"),
                 TotalDemand = c(27,23,16,9, 32, 40),
                 Pop = c("TEST", "CONTROL", "TEST", "CONTROL", "TEST", "CONTROL"))

ggplot(DF, aes(x = Name, y = TotalDemand, fill = Pop)) + 
    geom_bar(stat = "identity", position = position_dodge()) +
    geom_text(aes(label = TotalDemand, y = TotalDemand - 3),
              position = position_dodge(width = 0.9)) + 
    coord_flip()

1 Like