我在堆积条形图时遇到问题,即在时间轴上表示。
我的DF看起来如下:
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
我现在想要的是每天堆叠的条形图。我试过了
ggplot(my_df, aes(date,fill=action))+
geom_bar()+
scale_x_date()
但是,这不会产生预期的结果。有人有想法吗?
祝福
答案 0 :(得分:2)
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')
(顺便说一下,你的变量share
不是整数变量。整数是整数)