【问题标题】:R, ggplot, stacked bar chart, time seriesR、ggplot、堆积条形图、时间序列
【发布时间】:2016-06-08 16:55:48
【问题描述】:

我在使用堆积条形图时遇到问题,它要在时间轴上表示。

我的 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()

但是,这不会产生预期的结果。有人有想法吗?

最好的祝福

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:
    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 不是整数变量。整数是整数)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多