我在理解为什么日期,标签和中断的处理没有像我在R中尝试使用ggplot2进行直方图时所预期的那样有问题.
我在找:
%Y-b格式的日期标签我已将数据上传到pastebin以使其可重现.我创建了几个列,因为我不确定这样做的最佳方法:
> dates <- read.csv("http://pastebin.com/raw.php?i=sDzXKFxJ", sep=",", header=T)
> head(dates)
YM Date Year Month
1 2008-Apr 2008-04-01 2008 4
2 2009-Apr 2009-04-01 2009 4
3 2009-Apr 2009-04-01 2009 4
4 2009-Apr 2009-04-01 2009 4
5 2009-Apr 2009-04-01 2009 4
6 2009-Apr 2009-04-01 2009 4
Run Code Online (Sandbox Code Playgroud)
这是我试过的:
library(ggplot2)
library(scales)
dates$converted <- as.Date(dates$Date, format="%Y-%m-%d")
ggplot(dates, aes(x=converted)) + geom_histogram()
+ opts(axis.text.x = theme_text(angle=90))
Run Code Online (Sandbox Code Playgroud)
这会产生这个图表.我想要%Y-%b格式化,所以我在周围搜索并尝试以下内容,基于此SO:
ggplot(dates, aes(x=converted)) + geom_histogram() …Run Code Online (Sandbox Code Playgroud)