1
我知道這已被問了很多次之前。但是,我無法找到解決問題的方案。barplot兩組使用ggplot2
我延長mtcars
數據由虛設設定表示轎廂是否被出售或由車賣方購買(購買= 0 - >產品信息,購買= 1 - >買)和交易日期:
data(mtcars)
mtcars$buy <- c(0,0,1,0,0,1,1,0,0,1,0,1,0,0,0,1,1,0,0,0,1,0,1,0,1,1,0,0,0,1,0,1)
mtcars$date <- as.Date(c('2011-01-01','2011-01-06','2011-01-10','2011-01-20','2011-01-23',
'2011-01-25','2011-01-31','2011-02-01','2011-02-06','2011-02-15',
'2011-02-22','2011-02-26','2011-03-05','2011-03-15','2011-03-20',
'2011-03-22','2011-03-27','2011-04-10','2011-04-25','2011-04-28',
'2011-05-05','2011-05-15','2011-06-05','2011-06-06','2011-06-17',
'2011-06-25','2011-07-05','2011-07-11','2011-07-25','2011-07-31',
'2011-08-23','2011-08-25'))
現在我想用ggplot
來獲得一個每月賣出和作爲單獨條形圖購買的barplot。但是,我只能創建的所有事務的總括圖:
mtcars$month <- as.Date(cut(mtcars$date, breaks="month"))
mtcars$counter <- 1
ggplot(mtcars, aes(month,counter)) + stat_summary(fun.y=sum, geom="Bar")
如何創建相同的圖形,但兩間酒吧每個月(一個購買的數量和其他與賣出數量)?
感謝您的幫助!