Staggered and stacked geom_bar in the same figure?
Base graphics?!? NEVERRRR
Here's what I've come up with. I admit I had a hard time understanding all your aggregation and prep, so I just aggregated to counts and may have gotten that all wrong - but it seems like you're in a position where it might be easier to start from a functioning plot and then get the inputs right. Does this do the trick?
# Aggregate
dat.agg <- ddply(dat, .var = c("category1", "outcome"), .fun = summarise,
cat1.n = length(outcome),
yes = sum(category2 %in% "yes"),
not = sum(category2 %in% "not")
)
# Plot - outcome will be x for both layers
ggplot(dat.agg, aes(x = outcome)) +
# First layer of bars - for category1 totals by outcome
geom_bar(aes(weight = cat1.n, fill = category1), position = "dodge") +
# Second layer of bars - number of "yes" by outcome and category1
geom_bar(aes(weight = yes, fill = category1), position = "dodge") +
# Transparency to make total lighter than "yes" - I am bad at colors
scale_fill_manual(value = c(alpha("#1F78B4", 0.5), alpha("#33A02C", 0.5))) +
# Title
opts(title = "A pretty plot <3")