ggplot2 – bar plot with both stack and dodge

Here’s an alternative take using faceting instead of dodging:

ggplot(df, aes(x = year, y = total, fill = type)) +
    geom_bar(position = "stack", stat = "identity") +
    facet_wrap( ~ treatment)

enter image description here

With Tyler’s suggested change: + theme(panel.margin = grid::unit(-1.25, "lines"))

enter image description here

Leave a Comment