【问题标题】:Time series of inflation rate通货膨胀率的时间序列
【发布时间】:2020-01-16 19:12:58
【问题描述】:

您好,我有一个 20 年 CPI 的数据集 我计算了通货膨胀率:

"/" <- function(x,y) ifelse(y==0,0,base:::"/"(x,y))

n <- length(CPI.germany$CPI)

infl <- CPI.germany$CPI[13:n]/CPI.germany$CPI[1:(n-12)]

# adjust the date column
date <- CPI.germany1$Date
datenew<- date[13:252]

#control
length(datenew)
length(infl)

 infl    datenew
1    1.08182862 1991-01-15
2    1.08195654 1991-02-15
3    1.08191389 1991-03-15
4    1.22093054 1991-04-15
5    1.28206524 1991-05-15
6    1.56516705 1991-06-15
7    2.01404189 1991-07-15
8    1.58665134 1991-08-15

我怎么知道创建一个像我附加的那样的时间序列图。 哪个包是最简单的? ggplot2?

【问题讨论】:

  • See here 提出一个人们可以帮助解决的 R 问题。这包括数据样本和所有必要的代码。现在这是非常广泛的,我们不能在一张数据表的图片上运行代码。目前还不清楚您想要什么类型的图表以及您想要如何处理它(什么包等),删除 12 行似乎是一个与实际绘图无关的预处理步骤
  • 试试ggplot(your_dataset, aes(datenew, infl)) + geom_line()。您所附图表中的主题来自hrbrthemes 包。
  • “最简单”是主观的,取决于很多事情:你的经验、你的听众、你的背景等等。
  • 我的经验不是那么高;我是初学者。这是一个学校演示文稿。所以它应该只将日期与适当的增长率联系起来

标签: r time-series


【解决方案1】:

假设DF在最后的注释中可重现地转换为动物园系列z,然后使用显示的方法之一。

library(zoo)
z <- read.zoo(DF, index = "datenew")

# classic graphics
plot(z)

# ggplot2
library(ggplot2)
autoplot(z)

# lattice
library(lattice)
xyplot(z)

注意

Lines <- " infl    datenew
1    1.08182862 1991-01-15
2    1.08195654 1991-02-15
3    1.08191389 1991-03-15
4    1.22093054 1991-04-15
5    1.28206524 1991-05-15
6    1.56516705 1991-06-15
7    2.01404189 1991-07-15
8    1.58665134 1991-08-15"
DF <- read.table(text = Lines)

【讨论】:

    猜你喜欢
    • 2020-04-27
    • 2023-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 2019-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多