-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsumer_confidence.R
77 lines (60 loc) · 3.86 KB
/
Consumer_confidence.R
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
65
66
67
68
69
70
71
72
73
74
75
76
# Upload the packages -----------------------------------------------------
pacman::p_load(readxl,readr, lubridate, tidyverse, ggplot2, hrbrthemes, ggfittext, patchwork, scales, ggtext, ggpubr,ggbump,wesanderson,
grid, gridtext, biscale, cowplot,sysfonts,ggimage,extrafont,systemfonts, showtext, ggbeeswarm)
# Fonts -------------------------------------------------------------------
extrafont::loadfonts(device = "win", quiet = TRUE)
font_add_google("Lora")
font_labels <- "Lora"
showtext_auto()
# Graph -------------------------------------------------------------------
# I only include graph code
ggUSA<-ggplot("data_source", aes(TIME, Value)) + geom_line(size = 0.8, color="#808080") +
scale_y_continuous(limits = c(96, 103.5), breaks = c(96, 98, 100, 102)) +
geom_point(x= George_H_W_Bush, y = c(101.1445),size=4, shape=21, fill="#e13d3d") +
geom_point(x= BClinton, y = c(100.28380),size=4, shape=21, fill="#1a6aff") +
geom_point(x= BushDate, y = c(101.1343),size=4, shape=21, fill="#e13d3d")+
geom_point(x= ObamaDate, y = c(96.22121),size=4, shape=21, fill="#1a6aff")+
geom_point(x= TrumpDate, y = c(101.4472),size=4, shape=21, fill="#e13d3d") +
geom_point(x= BidenDate, y = c(98.89713),size=4, shape=21, fill="#1a6aff") +
annotate("text", x = George_H_W_Bush, y =101.5,fontface =2,
hjust = 0.5, color = "#e13d3d",family = font_labels,
size = 3.5, label = paste0("George H. W. Bush \nJanuary 1989")) +
annotate("text", x = BClinton, y =100.8,fontface =2,
hjust = 0.5, color = "#1a6aff",family = font_labels,
size = 3.5, label = paste0("Bill Clinton \nJanuary 1993")) +
annotate("text", x = BushDate_for_text, y =101,fontface =2,
hjust = 0.5, color = "#e13d3d",family = font_labels,
size = 3.5, label = paste0("George W. Bush \nJanuary 2001")) +
annotate("text", x = ObamaDate, y =96.1,fontface =2,
hjust = 0.5, color = "#1a6aff",family = font_labels,
size = 3.5, label = paste0("Obama - January 2009")) +
annotate("text", x = TrumpDate, y =101.85,fontface =2,
hjust = 0.5, color = "#e13d3d",family = font_labels,
size = 3.5, label = paste0("Trump - January 2017")) +
annotate("text", x = BidenDate, y =98.1,fontface =2,
hjust = 0.5, color = "#1a6aff",family = font_labels,
size = 3.5, label = paste0("Biden - January 2021")) +
labs(x = "",y = "",
title = "Consumer confidence index (CCI) - US",
subtitle = "Monthly analysis of Consumer confidence index in the US since January 1989 during each presidential term",
caption = "Source: OECD Data data.oecd.org\nVisualization: JuanmaMN (Twitter @Juanma_MN)")+
theme_ipsum(grid="Y") +
theme(legend.position = "none",
plot.title = element_text(margin = margin(b = 8),
color = "#22222b",face = "bold",size = 16,
hjust = 0.5,
family = font_labels),
plot.subtitle = element_text(margin = margin(t=10,b = 25),
color = "#22222b", size = 9, family = font_labels,
hjust = 0.5),
plot.caption = element_text(margin = margin(t = 20),
color = "#22222b", size = 10, family = font_labels,
hjust = 0.95),
axis.title.x = element_text(margin = margin(t = 10),color = "#22222b",family = font_labels),
axis.title.y = element_text(margin = margin(r = 15),color = "#22222b",family = font_labels),
axis.text.x = element_text(color = "#22222b"),
axis.text.y = element_text(color = "#22222b"),
plot.background = element_rect(fill = "#f7f7f7", color = NA), # color removes the border
plot.margin = unit(c(1, 1, 1, 1), "cm"),
axis.ticks = element_blank())
ggUSA