I have been trying to plot clustered columns with running totals in. I have two types of columns and just need R to calculate the running total of each them separately. For some reason it's adding running totals of different types together.
library(ggplot2)
df = data.frame(date = c(1, 1, 2, 2, 3, 3),
val = c(5, 2, 5, 2, 5, 2),
type = c("honey","bread","honey","bread","honey","bread"))
ggplot(df, aes(x=date, y=cumsum(val), group = type, fill=type)) +
geom_bar(position = position_dodge(preserve = 'total'), stat="identity") + theme_classic()
I am getting:
What I am looking is to have a running total in, showing honey with values of 5,10 and 15, and bread with values of 2, 4 and 6.
What am I doing wrong? Any idea?