1
votes

I'm having trouble with a stacked bar chart, that is to be represented on a time axis.

My DF looks as follows:

date (class: Date) | action (class: character) | share (class: integer) 

2016-01-17 | ABC | 0.26

2016-01-17 | DEF | 0.16

...

2016-01-18 | ABC | 0.22

2016-01-18 | GHI | 0.19

What I would now like is a stacked bar chart on a daily basis. I have tried

ggplot(my_df, aes(date,fill=action))+ geom_bar()+ scale_x_date()

However, this does not produce the desired result. Does someone have an idea?

Best Wishes

1

1 Answers

3
votes
myDF <-
  data.frame(date = as.Date(c('2016-01-17','2016-01-17','2016-01-18','2016-01-18')),
             action = c('ABC','DEF','ABC','GHI'),
             share = c(0.26, 0.16, 0.22, 0.19)) 
ggplot(data = myDF, 
       aes(x = date, y = share, fill = action)) + 
  geom_bar(stat = 'identity')

(By the way, your variable share is not an integer variable. Integers are whole numbers)