Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用zoo中的as.yearmon修改ggplot2中的绘图_R_Date_Plot_Ggplot2_Zoo - Fatal编程技术网

使用zoo中的as.yearmon修改ggplot2中的绘图

使用zoo中的as.yearmon修改ggplot2中的绘图,r,date,plot,ggplot2,zoo,R,Date,Plot,Ggplot2,Zoo,我在ggplot2中创建了一个图形,使用zoo创建了月份箱子。但是,我希望能够修改该图,使其看起来像一个标准的ggplot图。这意味着未使用的垃圾箱将被丢弃,并填充整个垃圾箱空间。这是我的密码: library(data.table) library(ggplot2) library(scales) library(zoo) testset <- data.table(Date=as.Date(c("2013-07-02","2013-08-03","2013-09-04","2013-

我在ggplot2中创建了一个图形,使用zoo创建了月份箱子。但是,我希望能够修改该图,使其看起来像一个标准的ggplot图。这意味着未使用的垃圾箱将被丢弃,并填充整个垃圾箱空间。这是我的密码:

library(data.table)
library(ggplot2)
library(scales)
library(zoo)

testset <- data.table(Date=as.Date(c("2013-07-02","2013-08-03","2013-09-04","2013-10-05","2013-11-06","2013-07-03","2013-08-04","2013-09-05","2013-10-06","2013-11-07")), 
           Action = c("A","B","C","D","E","B","A","B","C","A","B","E","E","C","A"), 
           rating = runif(30))
我不确定我错过了什么,但我想知道!提前谢谢

要获得“标准外观”图,请将数据转换为“标准”数据类型,这是一个因素:

ggplot(testset, aes(as.factor(as.yearmon(Date)), fill=Action)) + 
    geom_bar(position='dodge') 

ggplot(testset, aes(as.factor(as.yearmon(Date)), fill=Action)) + 
    geom_bar(position='dodge')