ggplot2:按年份组合直方图数据 [英] ggplot2: Group histogram data by year
问题描述
我有一堆数据,附有一个YYYY-MM-DD日期,我每年都无法获得一个单独的酒吧。换句话说,2014年的所有数据显示在2014年的酒吧之下。
I have a bunch of data with a YYYY-MM-DD date attached to it, and I'm having trouble getting a single bar for each year. In other words, all data from 2014 showing up under a bar for 2014.
使用
df1 $ Close.Date< - as.Date(df1 $ Close.Date,%m /%d /%Y)
这是我的直方图公式不正确分组
Here's my histogram formula that doesn't group correctly
ggplot(df1 ,aes(Close.Date,fill = Stage))+ geom_bar()
我试过用$ code > break 和 binwidth
没有成功
I've tried messing around with breaks
and binwidth
with no success
推荐答案
p>我修复它:添加这行 df1 $ yr< - strftime(df1 $ Close.Date,%Y)
然后用yr替换Close.Date在ggplot行。
I fixed it by: adding this line df1$yr <- strftime(df1$Close.Date, "%Y")
and then replacing Close.Date with yr in the ggplot line.
这篇关于ggplot2:按年份组合直方图数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!