fred_md: St. Louis FED Monthly Database

Description Usage Format Source Examples

Description

This is a database of over 100 economic indicators recorded on a monthly basis, as provided by the St. Louis FED. A few indicators with missing values have been removed.

Usage

1

Format

An object of class tbl_df (inherits from tbl, data.frame) with 696 rows and 125 columns.

Source

https://research.stlouisfed.org/econ/mccracken/fred-databases/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
library(lubridate)
library(dplyr)
library(ggplot2)
library(ggrepel)
fred_md %>%
  select(-date, -sasdate) %>%
  scale() %>%
  prcomp() -> pca

pca_data <- data.frame(date=fred_md$date, pca$x) %>%
  mutate(
    type = ifelse(
      (ymd("1990-07-01") <= date & date < ymd("1991-03-01")) |
      (ymd("2001-03-01") <= date & date < ymd("2001-11-01")) |
      (ymd("2007-12-01") <= date & date < ymd("2009-06-01")),
      "recession",
      "recovery"
    )
  )

pca_labels <-
  mutate(pca_data,
    label = ifelse(
      date %in% c(ymd("1990-01-01"), ymd("1991-03-01"), ymd("2001-11-01"),
                  ymd("2009-06-01"), ymd("2017-12-01")),
      format(date, "%b %Y"), ""
    )
  ) %>%
  filter(label != "") %>%
  mutate(
    nudge_x = c(.2, -.2, -.2, -.2, .2),
    nudge_y = c(.2, -.2, -.2, -.2, .2),
    hjust = c(0, 1, 1, 1, 0),
    vjust = c(0, 1, 1, 1, 0),
  )

ggplot(filter(pca_data, date >= ymd("1990-01-01"))) +
  aes(x=PC1, y=PC2, color=type, alpha = date, group = 1) +
  geom_path(size = 1, lineend = "butt") +
  geom_text_repel(
    data = pca_labels,
    aes(label = label),
    alpha = 1,
    point.padding = .2, color = "black",
    min.segment.length = 0, size = 10/.pt,
    nudge_x = pca_labels$nudge_x,
    nudge_y = pca_labels$nudge_y,
    hjust = pca_labels$hjust,
    vjust = pca_labels$vjust
  ) +
  scale_color_manual(
    values = c("#D55E00", "#009E73"),
    name = NULL
  ) +
  scale_alpha_date(range = c(0.5, 1), guide = "none") +
  scale_x_continuous(limits = c(-2, 15.5)) +
  scale_y_continuous(limits = c(-5, 5)) +
  theme_minimal_grid(12, rel_small = 1) +
  theme(
    legend.position = c(1, 1),
    legend.justification = c(1, 1),
    legend.direction = "horizontal",
    legend.background = element_rect(fill = "white")
  )

clauswilke/dviz.supp documentation built on Aug. 25, 2020, 2:12 a.m.