-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboardC21C.Rmd
708 lines (396 loc) · 18.6 KB
/
dashboardC21C.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
---
title: "Capital in Twenty First Century by Thomas Piketty."
output:
flexdashboard::flex_dashboard:
#storyboard: true
social: menu
#source: embed
---
```{r setup, include=FALSE}
#Clear the workspace - remove all variables
rm(list = ls())
library(Quandl)
library(plotly)
library(flexdashboard)
```
```{r}
titleVar <- list(
#family = "Ariel",
size = 18
#color = "#7f7f7f"
)
```
Introduction {.storyboard}
=========================================
### <b>Income inequality in the United States, 1910-2010</b>
```{r}
i1 <- Quandl("PIKETTY/TSI_1", api_key="yg2rjFAWcN1FgzoJ1naL")
plot_ly(i1, x=i1$Date, y=i1$Value, mode = 'lines+markers', type = "scatter") %>%
layout(title = '<b>Income inequality in the United States, 1910-2010</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>Share of top decile in national income</b>'))
```
***
Introduction
- FIGURE I.1
- page 36
- Context
### <b>The capital/income ratio in Europe, 1870-2010</b>
```{r}
i2 <- Quandl("PIKETTY/TSI_2", api_key="yg2rjFAWcN1FgzoJ1naL")
plot_ly(i2, x=i2$Date, y = i2$Germany, name = "<b>Germany</b>", mode = 'lines+markers', type='scatter') %>%
add_trace(x=i2$Date, y = i2$France, name = "<b>France</b>", connectgaps = TRUE) %>%
add_trace(x=i2$Date, y = i2$Britain, name = "<b>Britain</b>", connectgaps = TRUE) %>%
layout(title = '<b>The capital/income ratio in Europe, 1870-2010</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>Market value of private capital (% national income)</b>'))
```
***
Introduction
- FIGURE I.2
- Page 38
- Context
Part One {.storyboard}
=========================================
### <b>The distribution of world output, 1700-2012</b>
```{r}
c1_1 <- Quandl("PIKETTY/TS1_1A", api_key="yg2rjFAWcN1FgzoJ1naL")
#GP: taking first 8 rows only, data since 1700 AD
c1_1 <- c1_1[1:8,]
#NOTE: code below gave none stacked graph, we need to stack one on top of another
# plot_ly(data=c1_1, x=Date, y=`World output`, fill="tonexty", mode="lines") %>%
# add_trace(x=Date, y = Europe, fill="tonexty") %>%
# add_trace(x=Date, y = America, fill="tonexty") %>%
# add_trace(x=Date, y = Africa, fill="tonexty") %>%
# add_trace(x=Date, y = Asia, fill="tonexty")
Years <- c1_1$Date
y1_real<- c1_1$Europe
y2_real<- c1_1$America
y3_real<- c1_1$Africa
y4_real<- c1_1$Asia
df= data.frame(Years, y1_real, y2_real, y3_real, y4_real)
df$y4_stck<- df$y4_real + df$y3_real + df$y2_real + df$y1_real
df$y3_stck<- df$y3_real + df$y2_real + df$y1_real
df$y2_stck<- df$y2_real + df$y1_real
df$y1_stck<- df$y1_real
p1<- plot_ly(df, x=df$Years, y=df$y1_stck, text=df$y1_real, hoverinfo='x+text+name', name="Europe", fill="tonexty", type = 'scatter', mode = "markers") %>%
layout(title = '<b>The distribution of world output, 1700-2012</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>Percentage of Total World Output</b>'))
p2<- add_trace(p1, x=df$Years, y=df$y2_stck, text=df$y2_real, type = 'scatter', mode = "markers", hoverinfo='x+text+name', name="America", fill="tonexty")
p3<- add_trace(p2, x=df$Years, y=df$y3_stck, text=df$y3_real, type = 'scatter', mode = "markers", hoverinfo='x+text+name', name="Africa", fill="tonexty")
p4<- add_trace(p3, x=df$Years, y=df$y4_stck, text=df$y4_real, type = 'scatter', mode = "markers", hoverinfo='x+text+name', name="Asia", fill="tonexty")
p4
rm(df, p1, p2, p3, p4, y1_real, y2_real, y3_real, y4_real, Years)
```
***
Part One: Income and Capital
- Income and Output
- FIGURE 1.1
- Page 75
- Context
### <b>The distribution of world population, 1700-2012</b>
```{r}
c1_2 <- Quandl("PIKETTY/TS1_2A", api_key="yg2rjFAWcN1FgzoJ1naL")
#GP: taking first 8 rows only, data since 1700 AD
c1_2 <- c1_2[1:8,]
Years <- c1_2$Date
y1_real<- c1_2$Europe
y2_real<- c1_2$America
y3_real<- c1_2$Africa
y4_real<- c1_2$Asia
df= data.frame(Years, y1_real, y2_real, y3_real, y4_real)
df$y4_stck<- df$y4_real + df$y3_real + df$y2_real + df$y1_real
df$y3_stck<- df$y3_real + df$y2_real + df$y1_real
df$y2_stck<- df$y2_real + df$y1_real
df$y1_stck<- df$y1_real
p1<- plot_ly(df, x=df$Years, y=df$y1_stck, text=df$y1_real, type = 'scatter', mode = "markers", hoverinfo='x+text+name', name="Europe", fill="tonexty") %>%
layout(title = '<b>The distribution of world population, 1700-2012</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>Percentage of Total World Population</b>'))
p2<- add_trace(p1, x=df$Years, y=df$y2_stck, type = 'scatter', mode = "markers", text=df$y2_real, hoverinfo='x+text+name', name="America", fill="tonexty")
p3<- add_trace(p2, x=df$Years, y=df$y3_stck, type = 'scatter', mode = "markers", text=df$y3_real, hoverinfo='x+text+name', name="Africa", fill="tonexty")
p4<- add_trace(p3, x=df$Years, y=df$y4_stck, type = 'scatter', mode = "markers", text=df$y4_real, hoverinfo='x+text+name', name="Asia", fill="tonexty")
p4
rm(df, p1, p2, p3, p4, y1_real, y2_real, y3_real, y4_real, Years)
```
***
Part One: Income and Capital
- Income and Output
- FIGURE 1.2
- Page 76
- Context
### <b>Global inequality, 1700-2012: divergence then convergence ?</b>
```{r}
c1_3 <- Quandl("PIKETTY/TS1_3A", api_key="yg2rjFAWcN1FgzoJ1naL")
c1_3 <- c1_3[1:8,]
plot_ly(c1_3, x=c1_3$Date, y=c1_3$`Europe + America`, name = "<b>Europe + America</b>", mode = 'lines+markers', type = 'scatter') %>%
add_trace(x=c1_3$Date, y = c1_3$`Asia + Africa`, name = "<b>Asia + Africa</b>", connectgaps = TRUE) %>%
add_trace(x=c1_3$Date, y = c1_3$`Per capita output`, name = "<b>World</b>", connectgaps = TRUE) %>%
layout(title = '<b>Global inequality, 1700-2012: divergence then convergence?</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>Per capita GDP(% of World Average)</b>'))
```
***
Part One: Income and Capital
- Income and Output
- FIGURE 1.3
- Page 77
- Context
### <b>Exchange rate and purchasing power parity: euro/dollar</b>
```{r}
c1_4 <- Quandl("PIKETTY/TS1_7", api_key="Kv-CaGGQMdMbP2q7nER2")
plot_ly(c1_4, x=c1_4$Date, y=c1_4$`exchange rate euro/dollar`, name = "<b>Exchange rate euro/dollar</b>",
mode = 'lines+markers',
type = 'scatter',
marker = list(symbol = 'square')) %>%
add_trace(x=c1_4$Date, y = c1_4$`purchasing power parity euro/dollar`, name = "<b>Purchasing power parity euro/dollar</b>",
mode = 'lines+markers',
type = 'scatter',
marker = list(symbol = "triangle-up-open"),
connectgaps = TRUE) %>%
layout(title = '<b>Exchange rate and purchasing power parity: euro/dollar</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b></b>'))
```
***
Part One: Income and Capital
- Income and Output
- FIGURE 1.4
- Page 82
- Context
### <b>Exchange rate and purchasing power parity: euro/yuan</b>
```{r}
#c1_4 <- Quandl("PIKETTY/TS1_7", api_key="Kv-CaGGQMdMbP2q7nER2")
plot_ly(c1_4, x=c1_4$Date, y= c1_4$`exchange rate euro/yuan`, name = "<b>Exchange rate euro/yuan</b>",
mode = 'lines+markers',
type = 'scatter',
marker = list(symbol = 'square')) %>%
add_trace(x=c1_4$Date, y = c1_4$`purchasing power parity euro/yuan`, name = "<b>Purchasing power parity euro/yuan</b>",
mode = 'lines+markers',
type = 'scatter',
marker = list(symbol = "triangle-up-open"),
connectgaps = TRUE) %>%
layout(title = '<b>Exchange rate and purchasing power parity: euro/yuan</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b></b>'))
```
***
Part One: Income and Capital
- Income and Output
- FIGURE 1.5
- Page 85
- Context
### <b>The growth of world population, 1700-2012</b>
```{r}
c2_1 <- Quandl("PIKETTY/TS2_2C", api_key="Kv-CaGGQMdMbP2q7nER2", start_date="1700-01-01")
c2_1 <- c2_1[5:11,]
Years <- c2_1$Year
y1_real<- c2_1$Europe
y2_real<- c2_1$Amrica
y3_real<- c2_1$Africa
y4_real<- c2_1$Asia
df= data.frame(Years, y1_real, y2_real, y3_real, y4_real)
df$y4_stck<- df$y4_real + df$y3_real + df$y2_real + df$y1_real
df$y3_stck<- df$y3_real + df$y2_real + df$y1_real
df$y2_stck<- df$y2_real + df$y1_real
df$y1_stck<- df$y1_real
p1<- plot_ly(df, x=df$Years, y=df$y1_stck, text=df$y1_real, hoverinfo='x+text+name',
name="Europe",
mode = 'lines+markers',
type = 'scatter',
fill="tonexty") %>%
layout(title = '<b>The growth of world population, 1700-2012</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>World population (million inhabitants)</b>'))
p2<- add_trace(p1, x=df$Years, y=df$y2_stck, text=df$y2_real, hoverinfo='x+text+name', name="America", fill="tonexty")
p3<- add_trace(p2, x=df$Years, y=df$y3_stck, text=df$y3_real, hoverinfo='x+text+name', name="Africa", fill="tonexty")
p4<- add_trace(p3, x=df$Years, y=df$y4_stck, text=df$y4_real, hoverinfo='x+text+name', name="Asia", fill="tonexty")
p4
rm(df, p1, p2, p3, p4, y1_real, y2_real, y3_real, y4_real, Years)
```
***
Part One: Income and Capital
- Growth: Illusions and Realities
- FIGURE 2.1
- Page 95
- Context
### <b>The growth rate of world population from Antiquity to 2100</b>
```{r}
c2_2 <- Quandl("PIKETTY/TS2_2A", api_key="Kv-CaGGQMdMbP2q7nER2")
plot_ly(c2_2, x=c2_2$`Year Ending`, y=c2_2$World, mode = 'lines+markers', marker = list(symbol = 'square'), type='scatter') %>%
layout(title = '<b>The growth rate of world population from Antiquity to 2100</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>World Population growth rate</b>'))
```
***
Part One: Income and Capital
- Growth: Illusions and Realities
- FIGURE 2.2
- Page 101
- Context
### <b>The growth rate of per capita output since the Industrial Revolution</b>
```{r}
c2_3 <- Quandl("PIKETTY/S2_3", api_key="Kv-CaGGQMdMbP2q7nER2")
c2_3 <- c2_3[5:11,]
plot_ly(c2_3, x=c2_3$`Year Ending`, y=c2_3$`Western Europe`, name = "<b>Western Europe</b>",
mode = 'lines+markers',
type = 'scatter',
marker = list(symbol = 'square')) %>%
add_trace(x=c2_3$`Year Ending`, y = c2_3$`North America`, name = "<b>North America</b>",
mode = 'lines+markers',
type = 'scatter',
marker = list(symbol = 'square'),
connectgaps = TRUE) %>%
layout(title = '<b>The growth rate of per capita output since the Industrial Revolution</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>Growth rate of per capita GDP</b>'))
```
***
Part One: Income and Capital
- Growth: Illusions and Realities
- FIGURE 2.3
- Page 122
- Context
### <b>The growth rate of world per capita output from Antiquity to 2100</b>
```{r}
c2_4 <- read.csv("./c2_4.csv", header = TRUE)
plot_ly(c2_4, x=c2_4$Years, y=c2_4$Per.capita.world.output, mode = 'lines+markers',
type = 'scatter',
marker = list(symbol = 'square')) %>%
layout(title = '<b>The growth rate of world per capita output from Antiquity to 2100</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>Growth rate of per capita GDP</b>'))
```
***
Part One: Income and Capital
- Growth: Illusions and Realities
- FIGURE 2.4
- Page 125
- Context
### <b>The growth rate of world output from Antiquity to 2100</b>
```{r}
plot_ly(c2_4, x=c2_4$Years, y=c2_4$World.output, mode = 'lines+markers',
type = 'scatter',
marker = list(symbol = 'square')) %>%
layout(title = '<b>The growth rate of world output from Antiquity to 2100</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>Growth rate World GDP</b>'))
```
***
Part One: Income and Capital
- Growth: Illusions and Realities
- FIGURE 2.5
- Page 127
- Context
### <b>Inflation since the Industrial Revolution</b>
```{r}
c2_5 <- Quandl("PIKETTY/S2_5", api_key="Kv-CaGGQMdMbP2q7nER2")
plot_ly(c2_5, x=c2_5$`Year Ending`, y=c2_5$France, name="<b>France</b>", mode = 'lines+markers', type = 'scatter') %>%
add_trace(x=c2_5$`Year Ending`, y=c2_5$Germany, name="<b>Germany</b>", mode = 'lines+markers',
marker = list(symbol = 'triangle-up')) %>%
add_trace(x=c2_5$`Year Ending`, y=c2_5$`United States`, name="<b>United States</b>", mode = 'lines+markers',
marker = list(symbol = 'triangle-up-open')) %>%
add_trace(x=c2_5$`Year Ending`, y=c2_5$Britain, name="<b>Britian</b>", mode = 'lines+markers',
marker = list(symbol = 'square-open')) %>%
layout(title = '<b>Inflation since the Industrial Revolution</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>Inflation rate(consumer price index)</b>'))
```
***
Part One: Income and Capital
- Growth: Illusions and Realities
- FIGURE 2.6
- Page 135
- Context
Part Two {.storyboard}
=========================================
### <b>Capital in Britain, 1700-2010</b>
```{r}
c3_1 <- Quandl("PIKETTY/T3_1", api_key="Kv-CaGGQMdMbP2q7nER2")
#GP: taking first 8 rows only, data since 1700 AD
c3_1 <- c3_1[,1:6]
Years <- c3_1$Year
y1_real<- c3_1$`incl. Land`
y2_real<- c3_1$`incl. Housing`
y3_real<- c3_1$`incl. Other domestic capital assets`
y4_real<- c3_1$`incl. Net foreign capital`
df= data.frame(Years, y1_real, y2_real, y3_real, y4_real)
df$y4_stck<- df$y4_real + df$y3_real + df$y2_real + df$y1_real
df$y3_stck<- df$y3_real + df$y2_real + df$y1_real
df$y2_stck<- df$y2_real + df$y1_real
df$y1_stck<- df$y1_real
p1<- plot_ly(df, x=df$Years, y=df$y1_stck, text=df$y1_real, mode = 'lines+markers',
type = 'scatter',
hoverinfo='x+text+name',
name="Agricultural land",
fill="tonexty") %>%
layout(title = '<b>Capital in Britain, 1700-2010</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>Value of national capital(% of national income)</b>'))
p2<- add_trace(p1, x=df$Years, y=df$y2_stck, text=df$y2_real, hoverinfo='x+text+name', name="Housing", fill="tonexty")
p3<- add_trace(p2, x=df$Years, y=df$y3_stck, text=df$y3_real, hoverinfo='x+text+name', name="Other domestic capital", fill="tonexty")
p4<- add_trace(p3, x=df$Years, y=df$y4_stck, text=df$y4_real, hoverinfo='x+text+name', name="Net foreign capital", fill="tonexty")
p4
# p5<- layout(yaxis=list(showgrid=FALSE, showline=FALSE))
# p5
rm(df, p1, p2, p3, p4, p5, y1_real, y2_real, y3_real, y4_real, Years)
```
***
Part Two: THE DYNAMICS OF THE CAPITAL/INCOME RATIO
- The Metamorphoses of Capital
- FIGURE 3.1
- Page 142
- Context
### <b>Capital in France, 1700-2010</b>
```{r}
c3_2 <- Quandl("PIKETTY/T3_2", api_key="Kv-CaGGQMdMbP2q7nER2")
#GP: taking first 8 rows only, data since 1700 AD
c3_2 <- c3_2[,1:6]
Years <- c3_2$Year
y1_real<- c3_2$`incl. Land`
y2_real<- c3_2$`incl. Housing`
y3_real<- c3_2$`incl. Other domestic capital assets`
y4_real<- c3_2$`incl. Net foreign capital`
df= data.frame(Years, y1_real, y2_real, y3_real, y4_real)
df$y4_stck<- df$y4_real + df$y3_real + df$y2_real + df$y1_real
df$y3_stck<- df$y3_real + df$y2_real + df$y1_real
df$y2_stck<- df$y2_real + df$y1_real
df$y1_stck<- df$y1_real
p1<- plot_ly(df, x=df$Years, y=df$y1_stck, text=df$y1_real, mode = 'lines+markers',
type = 'scatter',
hoverinfo='x+text+name',
name="Agricultural land",
fill="tonexty") %>%
layout(title = '<b>Capital in France, 1700-2010</b>',
titlefont = titleVar,
xaxis = list(title = '<b>Years</b>'),
yaxis = list (title = '<b>Value of national capital(% of national income)</b>'))
p2<- add_trace(p1, x=df$Years, y=df$y2_stck, text=df$y2_real, hoverinfo='x+text+name', name="Housing", fill="tonexty")
p3<- add_trace(p2, x=df$Years, y=df$y3_stck, text=df$y3_real, hoverinfo='x+text+name', name="Other domestic capital", fill="tonexty")
p4<- add_trace(p3, x=df$Years, y=df$y4_stck, text=df$y4_real, hoverinfo='x+text+name', name="Net foreign capital", fill="tonexty")
p4
# p5<- layout(yaxis=list(showgrid=FALSE, showline=FALSE))
# p5
rm(df, p1, p2, p3, p4, y1_real, y2_real, y3_real, y4_real, Years)
```
***
Part Two: THE DYNAMICS OF THE CAPITAL/INCOME RATIO
- The Metamorphoses of Capital
- FIGURE 3.2
- Page 143
- Context