【问题标题】:Editing the time series- decomposed plots编辑时间序列分解图
【发布时间】:2021-10-25 22:37:21
【问题描述】:

是否可以删除分解图(附加)右侧出现的空灰色框(红色圆圈内突出显示)?

另外,是否可以将个人的标题字体(在绿色圆圈内突出显示)更改为 Times New Roman 或任何其他喜欢的选择?

用于创建绘图的r代码如下

autoplot(decompose(x, type = "additive"))+labs(y=expression(Chl[a]~(µg/L)), x="Year") + ggtitle(expression(Decomposed~Chl[a]~Time~Series~BB1)) + theme(plot.title=element_text(hjust=0.5))

时间序列-分解图

【问题讨论】:

  • 请提供一个可重现的例子。没有对象x,我无法轻易提供解决方案的示例。

标签: r time-series stl-decomposition autoplot


【解决方案1】:

在预测包中,无法将比例尺放置在左侧。您必须手动移除比例尺并将它们添加到左侧。这可以通过设置autoplot(x, range.bars = FALSE)来完成。

您可以通过将适当的theme() 文本字段设置为element_text(family = ***) 来指定ggplot2 中的字体系列。

我在这里使用USAccDeaths 作为示例数据集:

library(fpp2)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
#> ── Attaching packages ────────────────────────────────────────────── fpp2 2.4 ──
#> ✓ ggplot2   3.3.5.9000     ✓ fma       2.4       
#> ✓ forecast  8.15           ✓ expsmooth 2.3
#> 
autoplot(decompose(USAccDeaths, type = "additive"))+
  labs(y=expression(Chl[a]~(µg/L)), x="Year") + 
  ggtitle(expression(Decomposed~Chl[a]~Time~Series~BB1)) +
  theme(
    plot.title=element_text(hjust=0.5),
    text = element_text(family = "Times New Roman", size = 15)
  )

reprex package (v2.0.0) 于 2021 年 8 月 26 日创建

【讨论】:

  • 谢谢!当我执行您修改后的代码时,一切正常。但是,当我合并范围时。 bar = FALSE 进入相同的代码我最终得到如下错误 autoplot(decompose(x, range.bars = FALSE, type = "additive"))+ labs(y=expression(Chl[a]~(µg/L )), x="Year") + ggtitle(表达式(Decomposed~Chl[a]~Time~Series~BB1)) + 主题( plot.title=element_text(hjust=0.5), text = element_text(family = "Times New Roman", size = 15) ) 分解错误(x, range.bars = FALSE, type = "additive") : 未使用的参数 (range.bars = FALSE)
  • range.barsautoplot() 而不是 decompose() 的参数。所以你的第一条绘图线应该是:autoplot(decompose(x, type = "additive"), range.bars = FALSE)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-26
  • 2020-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多