This is related to Plotting cumulative counts in ggplot2, but that question was dealing with a continuous variable (rather than discrete).
Here, I have a bar chart
set.seed(2021)
dat <- data.frame(x = c(rpois(100, 1), 7, 10))
ggplot(dat) + geom_bar(aes(x, ..count..))
I'm trying to plot a cumulative count with
ggplot(dat) + geom_bar(aes(x, cumsum(..count..)))
There are gaps when there are 'missing values' (i.e. when x
is 5, 6, 7, 9).
Is there a quick and easy way to have a bar chart with gaps filled with bars, i.e. I will have 11 bars? I could have manually created a data frame with the cumulative counts and plot it as usual, but I'm curious if there's a more elegant way.