I would like to add a stacked bar to a dodged bar chart, showing the total. I don't want the column for the total to be a solid bar, but to consist of the stacked components. I can add both geom_bars to the plot, but I haven't been able to move the total bar. I could add a dummy category with zero in the middle, but of course I'd prefer the total to be to the right of the components.
df=data.frame(
treatment=rep(c("Impact","Control")),
type=rep(c("Phylum1","Phylum2"),each=2),
total=c(2,3,4,5))
ggplot(df,aes(y=total,x=treatment,fill=type)) +
geom_bar(position= position_dodge(),stat="identity", alpha = 0.9, width = 0.25) +
geom_bar(position = position_stack(), stat = 'identity', alpha = 0.3, width = 0.125)
This is not the same question they want to stack/dodge by two variables. I just want to summarise the same info twice, but differently.
I can of course add a bar for the solid total and put in the stacked bar by hand, but I get so close with basic ggplot that I thought maybe a little hack (e.g. modifying the return object of position_stack) might be possible.