【问题标题】:ggplot change grid to fit monthly dataggplot 更改网格以适应月度数据
【发布时间】:2021-02-26 11:17:33
【问题描述】:

我有一个名为 afs20 的 1 年数据集,其结构如下:

  • datum 包含数据点的日期
  • maand 包含数据点的月份
  • delta 包含目标变量
o = ggplot(afs20)      
o + 
  geom_point(aes(x = datum, y = delta),stat="identity") +
  theme_bw()

My current plot

现在我的问题是:如何将网格的垂直线与新月份的开始对齐?也就是说,我希望每个月的第一天出现的数据点与绘图的网格对齐。

【问题讨论】:

  • 我不确定你到底想要什么?网格线不是已经在每个月初了吗?如果你想玩弄网格,这里有一篇博文,解释了一些功能:statworx.com/de/blog/…

标签: r ggplot2


【解决方案1】:

您可以在 x-scale 中设置 date_minor_breaks 参数。 下面是内置数据集的示例。

library(ggplot2)

ggplot(head(economics, 50), aes(date, unemploy)) +
  geom_point() +
  scale_x_date(date_minor_breaks = "1 month")

【讨论】:

    猜你喜欢
    • 2012-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-08
    相关资源
    最近更新 更多