Stacked and grouped barplot in r

barplotI have a stacked and grouped bar plot in ggplot2 but stack appears as lines. Is there a way to fix it?
p1 and summed_spendings are continuous variables.Fill variable is discrete with values 0,1,2.

ggplot(x, aes(x = p1, y = summed_spendings,fill=Kidhome)) +
  geom_bar(stat = "identity")+
  facet_grid(~Teenhome)

  • 1

    Can you share your data. try dput(x) and share the result into your question

    – 

  • 1

    Please see: How to make a great R reproducible example?

    – 

  • So could you clarify something, you are using grid facet, such that it is creating a separate graph for Kidhome. Did you want one chart with a bar for each value of kidhome with p1 as the colored layer in each bar, and summed spending as the height of the bar?

    – 

  • I just need the bars to be stacked as a block not as lines. The block of stack needs to represent kidhome

    – 

Leave a Comment