想做一个年-月的时间直方统计如下:
> test<-as.Date("2008-12-19")
> test
[1] "2008-12-19"
> str(test)
Date[1:1], format: "2008-12-19"
> test1<-strftime(test,format = "%Y-%m")
> test1
[1] "2008-12"
> str(test1)
chr "2008-12"
> test2<-as.Date(test1)
Error in charToDate(x) : 字符串的格式不够标准明确
> test3<-strftime(test,format="%Y")
> test3
[1] "2008"
> str(test3)
chr "2008"
年-月-日转换成年-月或年后格式就不是Date型而是变成了chr型,原来年-月-日Date型时可以用geom_histogram直接对时间做直方统计,转换成后年-月或年chr型后就不行了,报错如下:
Error: StatBin requires a continuous x variable the x variable is discrete. Perhaps you want stat="count"?
该如何解决?
另外我用年-月-日做直方统计时提示信息如下:
stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
这个binwidth是指的30日吗?
谢谢大家