I have got a question about creating a stacked barplot in R with ggplot2. What I want to create is a stacked bar plot in which every bar is placed "on top" of the other.
x = c(100,200,400,600,800,1000,1250,1500)
y1 = c(1,2,3,4,5,6,7,8)
y2 = c(8,7,6,5,4,3,2,1)
data <- data.frame(x,y1,y2)
ggplot(data, aes(x, y1,label=x)) +
geom_bar(stat="identity", fill="blue", position="stack") +
geom_bar(stat="identity",aes(x, y2), fill="orange", position="stack")
What I get now are stacked bars. But for x = 100 I get one bar from 0 - 1 and a second from 0 - 8. But what I want to get is one from 0 - 1 and a second from 1 - 9.
Have you an idea how I can solve this problem (without summing up the inputs manually)?
Thanks for your help!