Stacked bar chart with continuous Y variables

ggplot2

#1

*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!


#2

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.


#3

I think I accomplished that. Thanks!


#4

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/


#5

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.


#6

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


#7

Nice, art by accident!
:slight_smile:


#8

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