Using Geom_Bar in GGplot2

So I am trying to use geom_bar in ggplot2 and all the cases I see of people showing it on the internet are comparative frequencies of certain things. The chart I am trying to make is a bar graph like thisstacked bars

However, I want to do it from a vector of values. That is, let's say I have a vector

v=c(1,2,3,4)

      

Instead of the four even bars I understand, I would like to get a stack of 4 bars where the top is 1 unit and the next is 2 units (etc.). Is this possible in R?

Edit: Here is the code I used for my graph. This gives a normal histogram, not the tricky version I'm looking for:

ggplot(data = v, aes(x = factor(x), y = y)) + geom_bar(aes(fill = factor(y)),stat = 'identity')

      

+3


source to share


1 answer


I think you can start with this:



v=data.frame(x="My Stacked Bar", y=c(1,2,3,4))

ggplot(data = v, aes(x = factor(x), y = y))+
  geom_bar(aes(fill=factor(y)), stat="identity")

      

+4


source







All Articles