Stacked bar chart with continuous Y variables

*Updated with an example
Hello,
I am trying to make a stacked bar chart where the x-axis is categorical, by the y-axis is continuous. As it is, my code produces a bar chart where instead of a stacked chart, the bars are colored to designate the value for the second y-value. I want to produce a typical stacked chart where the color changes where the first y-variable ends. Here is my current code:

library(ggplot2)
Bar <- ggplot(iris,aes(Species,Sepal.Width,fill=Sepal.Length))+
  geom_col()
Bar

Created on 2019-02-05 by the reprex package (v0.2.1)
Thanks!

We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

1 Like

I think I accomplished that. Thanks!

A stacked bar chart is intended usually with color variables that are factor variables rather than continuous. Your code is mapping the fill aesthetic to a continuous variable, Sepal.Length, which is why ggplot2 is using colors in this way. If you want a continuous y-axis and want a stacked bar chart, the variable you map onto the fill aesthetic needs to be a factor variable. You can see some example plots/code here:
https://www.r-graph-gallery.com/stacked-barplot/

2 Likes

You were very close on your reprex, the idea was to use a small sample of your own data, but if you want to use the iris data set, there is no need for the df_paste() call, since iris comes with R by default.

I don't understand what you're going for. Could you share a drawing of your goal?

Nice, art by accident!
:slight_smile:

How do you expect this to work? I honestly don't even know what it means to "stack a continuous variable"

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.