簡體   English   中英

R,ggplot,堆積條形圖,時間序列

[英]R, ggplot, stacked bar chart, time series

我在以時間軸表示的堆疊條形圖上遇到麻煩。

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

但是,這不會產生期望的結果。 有人有主意嗎?

最好的祝願

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不是整數變量。整數是整數)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM