小编Ala*_*zin的帖子

在ggplot中,histgramming日期与不等的区间

我试图让ggplot产生一个带有3个月宽的箱子的直方图.不是90天而是3个月.就天来说,这是一个不等宽度的分组.请注意,每隔3个月的刻度线工作正常.这是我有问题的bin宽度.这里有很多讨论,但我找不到解决方案.

了解日期并使用R中的ggplot2绘制直方图

这是对问题的陈述.请注意,我显然可以在ggplot之外聚合结果然后绘制它们,可能作为ggplot中的因子.但我正在寻找一个全ggplot解决方案.

set.seed(seed=1)
dts<-as.Date('2012-01-01') + round(365*rnorm(500))
dts<-data.frame(d=dts)
g<-ggplot(dts,aes(x=d, y=..count..))

#this isnt what I want.  It is 90 days, not 3 months.
#Setting binwidth=' 3 months' also doesnt work
g + geom_histogram(fill='blue',binwidth=90) +
    scale_x_date(breaks = date_breaks('3 months'),  #seq(as.Date('2008-1-1'), as.Date('2012-3-1'), '3 month'),
                 labels = date_format("%Y-%m"),
                 limits = c(as.Date('2010-1-1'), as.Date('2014-1-1'))) +
    opts(axis.text.x = theme_text(angle=90))

#this doesnt work either.
#get:   stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
#        Error in `+.Date`(left, right) : binary + is not defined …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

5
推荐指数
1
解决办法
2056
查看次数

无法使用par(new = T)创建新的绘图窗口(设备?)

我想为R中的每个附加图创建一个新窗口.我试过了

plot(rnorm(20), new=TRUE)
Run Code Online (Sandbox Code Playgroud)

并且

par(new=T)
plot(rnorm(20), new=TRUE)
Run Code Online (Sandbox Code Playgroud)

都没给我一个新窗口.我真的需要创建一个新设备吗?

plot r

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

r ×2

ggplot2 ×1

plot ×1