-
Notifications
You must be signed in to change notification settings - Fork 0
/
US-China-trade.Rmd
187 lines (178 loc) · 11.9 KB
/
US-China-trade.Rmd
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
## First graph
gg1<-ggplot(data, aes(year, trade)) + geom_line(aes(colour = column),size = 1.5,linetype = "solid") +
# scale_x_continuous(breaks=c(1990,1995,2000,2005,2010,2015,2019))+
scale_x_continuous(expand = c(0, 0), limits = c(1983, 2021),breaks = 1983:2021,
labels = c(" "," "," ", " ",1987, " ", " ", " ",1991, " "," "," ",1995," "," "," ",
1999," "," "," ",2003," "," "," ",2007," ",
" "," ",2011," "," "," ",2015," "," ",
" ",2019," "," ")) +
scale_y_continuous(labels = dollar_format(prefix="$", suffix = "bn", scale = 1e-3),
limits = c(0, 600000),
breaks = seq(0, 600000, by = 100000)) +
scale_color_manual(values=c("#72bcd4", "#CC6666")) + # set the colour of the lines
#geom_point(size=4, shape=21, fill="#f5f5f2") +
geom_point(x= 1997, y = c(62557.70),size=4, shape=21, fill="#ac3939")+
geom_point(x= 1997, y = c(12862.20),size=4, shape=21, fill="#3a9fbf")+
geom_point(x= 2001, y = c(19182.30),size=4, shape=21, fill="#3a9fbf")+
geom_point(x= 2001, y = c(102278.40),size=4, shape=21, fill="#ac3939")+
geom_point(x= 2007, y = c(62936.89),size=4, shape=21, fill="#3a9fbf")+
geom_point(x= 2007, y = c(321442.87),size=4, shape=21, fill="#ac3939")+
geom_point(x= 2019, y = c(106448.37),size=4, shape=21, fill="#3a9fbf")+
geom_point(x= 2019, y = c(450760.38),size=4, shape=21, fill="#ac3939")+
labs(x = "",y = "",
title = "U.S. trade in goods with China - 1985 to 2019",
subtitle = "All figures are in billions of U.S. dollars on a nominal basis, not seasonally adjusted unless otherwise specified.",
caption = "Source: US Census Bureau www.census.gov\nVisualization: JuanmaMN (Twitter @Juanma_MN)")+
#guides(fill = NULL) +
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_blank(),
axis.title.y = element_blank(),
axis.text.x = element_text(color = "#22222b",family = font_labels),
axis.text.y = element_blank(),
plot.background = element_rect(fill = "#fbfaf6", color = NA),
panel.grid.major = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
plot.margin = unit(c(2, 2, 2, 2), "cm"),
axis.ticks = element_blank())+
annotate("segment", x = 1997, xend = 1997, y = 0, yend = 130000,
linetype = "longdash", color = "#000000") +
annotate("segment", x = 2001, xend = 2001, y = 0, yend = 210000,
linetype = "longdash", color = "#000000") +
annotate("segment", x = 2007, xend = 2007, y = 0, yend = 420000,
linetype = "longdash", color = "#000000") +
annotate("segment", x = 2019, xend = 2019, y = 300000, yend =452243.44,
linetype = "longdash", color = "#000000") +
annotate("segment", x = 2019, xend = 2019, y =110000, yend = 235000,
linetype = "longdash", color = "#000000") +
annotate("text", x = 1997, y =160000,fontface =0,family = font_labels,
hjust = 0.5, color = "#000000",
size = 3.5, label = paste0("1997\n Asian financial crisis")) +
annotate("text", x = 2001, y =250000,fontface =0,family = font_labels,
hjust = 0.5, color = "#000000",
size = 3.5, label = paste0("2001 (December)\nChina joins the \n World Trade Organization ")) +
annotate("text", x = 2007, y =450000,family = font_labels,
hjust = 0.5, color = "#000000", fontface =0,
size = 3.5, label = paste0("2007\n Global financial crisis starts")) +
annotate("text", x = 2019, y =270000,fontface =2,family = font_labels,
hjust = 0.5, color = "#ffc04d",
size = 3.5, label = paste0("Trade deficit 2019\n$344.31bn")) +
annotate("text", x = 2013, y =151746.19,fontface =2,family = font_labels,
hjust = 0, color = "#3a9fbf",
size = 3.5, label = paste0("U.S. exports to China")) +
annotate("text", x = 2013, y =410430.02,fontface =2, family = font_labels,
hjust = 0, color = "#e13d3d",
size = 3.5, label = paste0("U.S. imports from China")) +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=0,yend=0),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=100000,yend=100000),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=200000,yend=200000),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=300000,yend=300000),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=400000,yend=400000),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=500000,yend=500000),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=600000,yend=600000),linetype="dotted",colour = "#000000") +
annotate("text",x =1984, y = 0, label = "$0bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 100000, label = "$100bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 200000, label = "$200bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 300000, label = "$300bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 400000, label = "$400bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 500000, label = "$500bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 600000, label = "$600bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain")
gg1
## Second graph
p2datadeficit <- datadeficit%>%
ggplot(aes(x=year, y=-Deficit)) +
scale_x_continuous(expand = c(0, 0), limits = c(1983, 2021),breaks = 1983:2021,
labels = c(" "," "," ", " ",1987, " ", " ", " ",1991, " "," "," ",1995," "," "," ",
1999," "," "," ",2003," "," "," ",2007," ",
" "," ",2011," "," "," ",2015," "," ",
" ",2019," "," ")) +
scale_y_continuous(labels = dollar_format(prefix="$", suffix = "bn", scale = 1e-3),
limits = c(0, 450000),
breaks = seq(0, 450000, by = 100000)) +
geom_area(fill= "#e86969") +
labs(x = "",y = "",
title = "U.S. trade deficit in goods with China - 1985 to 2019",
subtitle = "All figures are in billions of U.S. dollars on a nominal basis, not seasonally adjusted unless otherwise specified.",
caption = "Source: US Census Bureau www.census.gov\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_blank(),
axis.title.y = element_blank(),
axis.text.x = element_text(color = "#22222b",family = font_labels),
axis.text.y = element_blank(),
plot.background = element_rect(fill = "#fbfaf6", color = NA),
panel.grid.major = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
plot.margin = unit(c(2, 2, 2, 2), "cm"),
axis.ticks = element_blank()) +
annotate("segment", x = 1997, xend = 1997, y = 0, yend = 130000,
linetype = "longdash", color = "#000000") +
annotate("segment", x = 2001, xend = 2001, y = 0, yend = 210000,
linetype = "longdash", color = "#000000") +
annotate("segment", x = 2007, xend = 2007, y = 0, yend = 330000,
linetype = "longdash", color = "#000000") +
annotate("text", x = 1997, y =160000,fontface =0,
hjust = 0.5, color = "#000000",family = font_labels,
size = 3.5, label = paste0("1997\n Asian financial crisis")) +
annotate("text", x = 2001, y =250000,fontface =0,
hjust = 0.5, color = "#000000",family = font_labels,
size = 3.5, label = paste0("2001 (December) \nChina joins the \n World Trade Organization ")) +
annotate("text", x = 2007, y =350000,family = font_labels,
hjust = 0.5, color = "#000000", fontface =0,
size = 3.5, label = paste0("2007 \n Global financial crisis starts")) +
annotate("text", x = 2013, y = 131746,fontface =2,family = font_labels,
hjust = 0.5, color = "#ffc04d",
size = 4.5, label = paste0("Trade deficit with China\n in 2019 - $344.31bn"))+
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=0,yend=0),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=100000,yend=100000),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=200000,yend=200000),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=300000,yend=300000),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=400000,yend=400000),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=500000,yend=500000),linetype="dotted",colour = "#000000") +
geom_segment(data= data, mapping=aes(x=1985,xend=2019,y=600000,yend=600000),linetype="dotted",colour = "#000000") +
annotate("text",x =1984, y = 0, label = "$0bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 100000, label = "$100bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 200000, label = "$200bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 300000, label = "$300bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 400000, label = "$400bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 500000, label = "$500bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain") +
annotate("text",x =1984, y = 600000, label = "$600bn",colour = "#000000",
vjust = 0.5, size = 3.5, family = font_labels, fontface = "plain")
p2datadeficit