I am trying to recreate this solution using ggplot2
in R: Combining two stacked bar plots for a grouped stacked bar plot
diamonds %>%
filter(color=="D"|color=="E"|color=="F") %>%
mutate(dummy=rep(c("a","b"),each=13057)) %>%
ggplot(aes(x=color,y=price))+
geom_bar(aes(fill=clarity),stat="identity",width=.25)+
facet_wrap(~cut)
I added a new variable to the diamonds
dataset called dummy
. dummy
has two values: a
and b
. Let's say I want to compare these two values by creating a bar graph that has two stacked bars right next to each other (one for each value of dummy
) for each value of color
. How can I manipulate this such that there are two stacked bars for each value of color
?
I think it would involve position dodge
and/or a separate legend
, but I've been unsuccessful so far. I do not want to add another facet - I want these both on the x-axis within each facet.