Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.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
R ggplot中的stat_bin(边界)问题_R_Ggplot2 - Fatal编程技术网

R ggplot中的stat_bin(边界)问题

R ggplot中的stat_bin(边界)问题,r,ggplot2,R,Ggplot2,我正在使用带有stat_bin的geom_bar创建一个柱状图,显示不同日期的事件数(binwidth可由用户通过Shining进行调整)。在我将边界变量插入stat_bin之前,图形看起来就像它应该的那样,但是最后一个bin通常会超过当前日期,这看起来有点混乱。因此,我使用边界变量使最后一个箱子在当前日期结束,此时图形开始生成许多灰色条。为什么会这样?我已经包括了我的代码,以及一张带有灰色条的图形图片 我使用以下代码生成以下绘图: ggplot(df, aes(x = df$date) +

我正在使用带有stat_bin的
geom_bar
创建一个柱状图,显示不同日期的事件数(binwidth可由用户通过Shining进行调整)。在我将边界变量插入stat_bin之前,图形看起来就像它应该的那样,但是最后一个bin通常会超过当前日期,这看起来有点混乱。因此,我使用边界变量使最后一个箱子在当前日期结束,此时图形开始生成许多灰色条。为什么会这样?我已经包括了我的代码,以及一张带有灰色条的图形图片

我使用以下代码生成以下绘图:

ggplot(df, aes(x = df$date) +
  geom_bar() + stat_bin(color = "white", boundary = (Sys.Date() - bin_width), binwidth = bin_width, aes(fill = df$groups)) +
  coord_cartesian(xlim = c(start_date, Sys.Date())) +
  theme_bw() +
  labs(x="Date", y="", fill="Groups")

没有数据很难确定,但请尝试取出
geom_bar()
stat_bin()
将自动生成几何图形。我认为您正在绘制两组条形图-一组来自
geom\u bar()
,另一组来自
stat\u bin()
。当您从
stat\u bin()
移动条形图时,第二组可见。

这完全正确。我觉得很傻。。。谢谢!