-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathggplot_flipbook_xaringan.html
10924 lines (9724 loc) · 336 KB
/
ggplot_flipbook_xaringan.html
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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<title>the ggplot flipbook</title>
<meta charset="utf-8" />
<meta name="author" content="Gina Reynolds" />
<link href="libs/remark-css-0.0.1/kunoichi.css" rel="stylesheet" />
<link href="libs/remark-css-0.0.1/ninjutsu.css" rel="stylesheet" />
</head>
<body>
<textarea id="source">
class: center, middle, inverse, title-slide
# the ggplot flipbook
## made with xaringan
### Gina Reynolds
### 2019/01/31
---
<!-- #Table of Contents -->
<!-- - [Visual Table of Contents](#visualtoc) -->
<!-- - [Introduction](#introduction) -->
<!-- - [What's the slow ggplot workflow?](#whatsslow) -->
<!-- - [Getting started with R and RStudio](#gettingstarted) -->
<!-- - [Acknowledgements](#acknowledgements) -->
<!-- - [The tidyverse](#thetidyverse) -->
# Introduction
The ggplot2 package in the programming language R implements the "layered grammar of graphics" --- a proposal of Leland Wilkinson and the product of the dissertation and ongoing work of Hadley Wickham. This data visualization system idea is at once powerful, novel, and intuitive. Wickham and collaborators have built a system where data visualization is dividable into parameters: data to visualize, aesthetics that represent variables, geometric objects, a coordinate system, specific scales, and statistical transformation.
In this book, I use a "slow ggplotting" method as well as a "flipbook" format to facilitate the introduction of this plotting method. "Slow ggplotting" makes modifications to plots as incrementally as possible so that it is clear to users what code triggers each new layer or modification. The aim is less to be concise, and more to be explicit about how new statements modify the plot; repetition should facilitating more interactions with ggplotting to help newcomers internalize the functions. The flipbook layout is designed to show what code is triggering each change in the plot output.
Readers of the book should easily be able to follow along with how plots are built up. While intuitive, using ggplotting effectively and efficiently nevertheless requires practice. My hope is that these examples will be a helpful reference point for those that endeavor to pick up data visualization with ggplot2.
---
name: whatsslow
# What's the slow ggplot workflow?
"Slow ggplot" just means working more incrementally than is typical. Elements of the approach are as follows:
- pulling out aes() from the ggplot() function:
- using fewer functions; example - using labs() to add a title instead of ggtitle()
- using functions multiple times; example aes(x = var1) + aes(y = var2) rather than aes(x = var1, y = var2)
- using base R functions and tidyverse functions. For other packages, the :: style to call them
- write out arguments (no shortcuts) aes(x = gdppercap) not aes(gdppercap)
- order ggplot commands so that reactivity is obvious; scale adjustments to aesthetics might also be near the aesthetic declaration.
---
Here, I contrast the usual plotting method to slow ggplotting:
Usual approach:
```r
ggplot(my_data, aes(var1, y = var2, col = var3)) +
geom_point() +
ggtitle("My Title") +
labs(x = "the x label", y = "the y label", col = "legend title")
```
Using slow ggplotting:
```r
ggplot(data = my_data) +
aes(x = var1) +
labs(x = "the x label") +
aes(y = var2) +
labs(y = "the y label") +
geom_point() +
aes(col = var3) +
labs(col = "legend title") +
labs(title = "My title")
```
---
name: gettingstarted
# Getting started with R and RStudio
- [Install Windows](https://www.youtube.com/watch?v=aCRMhAWmtpw)
- [Install Mac](https://www.youtube.com/watch?v=GLLZhc_5enQ)
---
name: acknowledgements
# Acknowledgements
I'm grateful to the ggplot team for their tireless work on developing and maintaining this fantastic resource. Additionally most of the visualizations here were produced for the Tableau-users-associated initiative #MakeoverMonday. I'm grateful to that community for feedback and encouragement and for welcoming work from outside of Tableau. Additional visualizations have been made with data curated by #TidyTuesday, a similar initiative from RStudio. Many thanks are due to Emi Tanaka (@statsgen) and Garrick Aden-Buie (@grrrck) helped by writing the "reveal" function to made the flipbook style possible. Also to Yihui Xie and others that work on the Xaringan package for creating slides from markdown and R code; I'm using Emi Tanaka's themes kunoichi and ninjutsu.
While I'm hopeful that this book serves as a reference, I think the best introductions and learning happens in person. My formal introduction to ggplot2 was at The Zurich Summer School for Women in Political Methodology in 2017 at the University of Zürich. I'm very grateful to the organizers and presenters of that workshop; Denise Traber gave an excellent presention on ggplot2. I'm grateful too to my students who motivate me to think about how to teach what I've been so lucky to learn. And thanks to David, who is supportive of plotting and of me.
---
name:visualtoc
#Visual Table of Contents
<a href="#christmastreesales"><img src="figures/christmas.png"width="150" height="150" title=figures/christmas.png alt=figures/christmas.png></a><a href="#baseball"><img src="figures/baseball.png"width="150" height="150" title=figures/baseball.png alt=figures/baseball.png></a><a href="#parentalleave"><img src="figures/parent_leave.png"width="150" height="150" title=figures/parent_leave.png alt=figures/parent_leave.png></a><a href="#traits"><img src="figures/traits.png"width="150" height="150" title=figures/traits.png alt=figures/traits.png></a><a href="#salaries"><img src="figures/white_house.png"width="150" height="150" title=figures/white_house.png alt=figures/white_house.png></a><a href="#wintergamemedals"><img src="figures/winter_games.png"width="150" height="150" title=figures/winter_games.png alt=figures/winter_games.png></a>
<a href="#brexit"><img src="figures/brexit_1.png"width="150" height="150" title=figures/brexit_1.png alt=figures/brexit_1.png></a><a href="#britishburgers"><img src="figures/map_curry.png"width="150" height="150" title=figures/map_curry.png alt=figures/map_curry.png></a><a href="#britishfood"><img src="figures/away_from_ben.png"width="150" height="150" title=figures/away_from_ben.png alt=figures/away_from_ben.png></a><a href="#lifeexpect"><img src="figures/life_expect.png"width="150" height="150" title=figures/life_expect.png alt=figures/life_expect.png></a><a href="#myersbriggs"><img src="figures/myers_briggs.png"width="150" height="150" title=figures/myers_briggs.png alt=figures/myers_briggs.png></a><a href="#womensrepresentation"><img src="figures/women.png"width="150" height="150" title=figures/women.png alt=figures/women.png></a>
<a href="#wine"><img src="figures/wine.png"width="150" height="150" title=figures/wine.png alt=figures/wine.png></a><a href="#ice"><img src="figures/ice.png"width="150" height="150" title=figures/ice.png alt=figures/ice.png></a><a href="#collegemajors01"><img src="figures/recent_grads_01.png"width="150" height="150" title=figures/recent_grads_01.png alt=figures/recent_grads_01.png></a><a href="#collegemajors02"><img src="figures/recent_grads_02.png"width="150" height="150" title=figures/recent_grads_02.png alt=figures/recent_grads_02.png></a><a href="#flippingseats"><img src="figures/flipping_seats.png"width="150" height="150" title=figures/flipping_seats.png alt=figures/flipping_seats.png></a><a href="#ratings"><img src="figures/company_ranks.png"width="150" height="150" title=figures/company_ranks.png alt=figures/company_ranks.png></a>
[More on next page](#visualtoc2)
---
name: visualtoc2
#Visual Table of Contents
<a href="#incarcerationbysex"><img src="figures/incarceration_01.png"width="150" height="150" title=figures/incarceration_01.png alt=figures/incarceration_01.png></a><a href="#incarcerationbygender"><img src="figures/incarceration_02.png"width="150" height="150" title=figures/incarceration_02.png alt=figures/incarceration_02.png></a><a href="#milkindustry"><img src="figures/milk.png"width="150" height="150" title=figures/milk.png alt=figures/milk.png></a><a href="#windturbinelocations01"><img src="figures/wind_01.png"width="150" height="150" title=figures/wind_01.png alt=figures/wind_01.png></a><a href="#windturbinelocations02"><img src="figures/wind_02.png"width="150" height="150" title=figures/wind_02.png alt=figures/wind_02.png></a><a href="#movies"><img src="figures/movies.png"width="150" height="150" title=figures/movies.png alt=figures/movies.png></a>
---
---
name: christmastreesales
# Christmas Trees
Here is a simple plot of Christmas Tree Sales in the U.S. The plot shows that artificial tree sales are on the rise, contrasting with declines in real trees. The title plays on the German Christmas Carol "O Tannenbaum", "Oh Christmas Tree" in English. "Wie echt sind deine Blätter?" means "how real are your leaves"; the original text from the carol is "Wie treu sind deine Blätter!" which means "How true your leaves are!"
I also plot the cumulative number of trees purchased of each type, artificial and real, from 2004 to 2014, comparing that to the 2016 U.S. population. Almost one real tree per person was bought over the course of 10 years!
```r
library(tidyverse)
```
A random sample from the data set:
<table>
<thead>
<tr>
<th style="text-align:right;"> Year </th>
<th style="text-align:right;"> Number of trees sold </th>
<th style="text-align:left;"> Type of tree </th>
<th style="text-align:right;"> Number of trees sold (millions) </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right;"> 2009 </td>
<td style="text-align:right;"> 11700000 </td>
<td style="text-align:left;"> Fake tree </td>
<td style="text-align:right;"> 11.7 </td>
</tr>
<tr>
<td style="text-align:right;"> 2005 </td>
<td style="text-align:right;"> 9300000 </td>
<td style="text-align:left;"> Fake tree </td>
<td style="text-align:right;"> 9.3 </td>
</tr>
<tr>
<td style="text-align:right;"> 2015 </td>
<td style="text-align:right;"> 12500000 </td>
<td style="text-align:left;"> Fake tree </td>
<td style="text-align:right;"> 12.5 </td>
</tr>
<tr>
<td style="text-align:right;"> 2008 </td>
<td style="text-align:right;"> 11700000 </td>
<td style="text-align:left;"> Fake tree </td>
<td style="text-align:right;"> 11.7 </td>
</tr>
<tr>
<td style="text-align:right;"> 2016 </td>
<td style="text-align:right;"> 27400000 </td>
<td style="text-align:left;"> Real tree </td>
<td style="text-align:right;"> 27.4 </td>
</tr>
</tbody>
</table>
---
class: split-40
count: false
.column[.content[
```r
*ggplot(data = dta)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_1-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(data = dta) +
* aes(x = Year)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_2-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(data = dta) +
aes(x = Year) +
* aes(y = `Number of trees sold (millions)`)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_3-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(data = dta) +
aes(x = Year) +
aes(y = `Number of trees sold (millions)`) +
* geom_point()
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_4-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(data = dta) +
aes(x = Year) +
aes(y = `Number of trees sold (millions)`) +
geom_point() +
* aes(col = fct_rev(`Type of tree`))
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_5-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(data = dta) +
aes(x = Year) +
aes(y = `Number of trees sold (millions)`) +
geom_point() +
aes(col = fct_rev(`Type of tree`)) +
* geom_smooth(method = "lm", se = F)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_6-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(data = dta) +
aes(x = Year) +
aes(y = `Number of trees sold (millions)`) +
geom_point() +
aes(col = fct_rev(`Type of tree`)) +
geom_smooth(method = "lm", se = F) +
* scale_color_manual(values =
* c("darkgreen", "green"))
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_8-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(data = dta) +
aes(x = Year) +
aes(y = `Number of trees sold (millions)`) +
geom_point() +
aes(col = fct_rev(`Type of tree`)) +
geom_smooth(method = "lm", se = F) +
scale_color_manual(values =
c("darkgreen", "green")) +
* ylim(c(0, 35))
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_9-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(data = dta) +
aes(x = Year) +
aes(y = `Number of trees sold (millions)`) +
geom_point() +
aes(col = fct_rev(`Type of tree`)) +
geom_smooth(method = "lm", se = F) +
scale_color_manual(values =
c("darkgreen", "green")) +
ylim(c(0, 35)) +
* labs(col = "")
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_10-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(data = dta) +
aes(x = Year) +
aes(y = `Number of trees sold (millions)`) +
geom_point() +
aes(col = fct_rev(`Type of tree`)) +
geom_smooth(method = "lm", se = F) +
scale_color_manual(values =
c("darkgreen", "green")) +
ylim(c(0, 35)) +
labs(col = "") +
* labs(title = "Wie echt sind deine Blätter?")
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_11-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(data = dta) +
aes(x = Year) +
aes(y = `Number of trees sold (millions)`) +
geom_point() +
aes(col = fct_rev(`Type of tree`)) +
geom_smooth(method = "lm", se = F) +
scale_color_manual(values =
c("darkgreen", "green")) +
ylim(c(0, 35)) +
labs(col = "") +
labs(title = "Wie echt sind deine Blätter?") +
* labs(subtitle = "Real and fake Christmas trees sold in the US | Data Source: Statista | @EvaMaeRey ")
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_12-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(data = dta) +
aes(x = Year) +
aes(y = `Number of trees sold (millions)`) +
geom_point() +
aes(col = fct_rev(`Type of tree`)) +
geom_smooth(method = "lm", se = F) +
scale_color_manual(values =
c("darkgreen", "green")) +
ylim(c(0, 35)) +
labs(col = "") +
labs(title = "Wie echt sind deine Blätter?") +
labs(subtitle = "Real and fake Christmas trees sold in the US | Data Source: Statista | @EvaMaeRey ") +
* theme_bw()
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_christmas_13-1.png" width="80%" />
]]
---
name: baseball
# Baseball, WAR, and Ethnicity
This data visualization uses the WAR measure in baseball, a calculation based on the contributions of players. The visualizations show that new ethnicities and races started to be included in Major League baseball, the minority players that joined tended to contribute more than the expected value for players overall. For example, from 1947, when Jackie Robinson joined Major League baseball, and onward, the percent of African American players was outpaced by the percent calculated contributions (WAR) of African American players.
A random sample from the data set:
<table>
<thead>
<tr>
<th style="text-align:right;"> Year </th>
<th style="text-align:left;"> Ethnicity </th>
<th style="text-align:left;"> type </th>
<th style="text-align:right;"> Percent </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right;"> 1948 </td>
<td style="text-align:left;"> Asian </td>
<td style="text-align:left;"> % of WAR </td>
<td style="text-align:right;"> 0.0 </td>
</tr>
<tr>
<td style="text-align:right;"> 1995 </td>
<td style="text-align:left;"> Latino </td>
<td style="text-align:left;"> % of Players </td>
<td style="text-align:right;"> 19.2 </td>
</tr>
<tr>
<td style="text-align:right;"> 1960 </td>
<td style="text-align:left;"> Asian </td>
<td style="text-align:left;"> % of WAR </td>
<td style="text-align:right;"> 0.0 </td>
</tr>
<tr>
<td style="text-align:right;"> 1952 </td>
<td style="text-align:left;"> African American </td>
<td style="text-align:left;"> % of Players </td>
<td style="text-align:right;"> 2.9 </td>
</tr>
<tr>
<td style="text-align:right;"> 1979 </td>
<td style="text-align:left;"> African American </td>
<td style="text-align:left;"> % of WAR </td>
<td style="text-align:right;"> 24.2 </td>
</tr>
<tr>
<td style="text-align:right;"> 2006 </td>
<td style="text-align:left;"> Latino </td>
<td style="text-align:left;"> % of Players </td>
<td style="text-align:right;"> 27.9 </td>
</tr>
<tr>
<td style="text-align:right;"> 1983 </td>
<td style="text-align:left;"> Asian </td>
<td style="text-align:left;"> % of Players </td>
<td style="text-align:right;"> 0.0 </td>
</tr>
<tr>
<td style="text-align:right;"> 1984 </td>
<td style="text-align:left;"> Asian </td>
<td style="text-align:left;"> % of WAR </td>
<td style="text-align:right;"> 0.0 </td>
</tr>
</tbody>
</table>
---
class: split-40
count: false
.column[.content[
```r
*ggplot(df_gather)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_baseball_1-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df_gather) +
* aes(x = Year, y = Percent)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_baseball_2-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df_gather) +
aes(x = Year, y = Percent) +
* facet_wrap(~ Ethnicity)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_baseball_3-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df_gather) +
aes(x = Year, y = Percent) +
facet_wrap(~ Ethnicity) +
* geom_area(alpha = .5,
* position = "dodge")
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_baseball_5-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df_gather) +
aes(x = Year, y = Percent) +
facet_wrap(~ Ethnicity) +
geom_area(alpha = .5,
position = "dodge") +
* aes(fill = type)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_baseball_6-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df_gather) +
aes(x = Year, y = Percent) +
facet_wrap(~ Ethnicity) +
geom_area(alpha = .5,
position = "dodge") +
aes(fill = type) +
* labs(fill = "")
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_baseball_7-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df_gather) +
aes(x = Year, y = Percent) +
facet_wrap(~ Ethnicity) +
geom_area(alpha = .5,
position = "dodge") +
aes(fill = type) +
labs(fill = "") +
* labs(x = "")
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_baseball_8-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df_gather) +
aes(x = Year, y = Percent) +
facet_wrap(~ Ethnicity) +
geom_area(alpha = .5,
position = "dodge") +
aes(fill = type) +
labs(fill = "") +
labs(x = "") +
* labs(title = "American Baseball Demographics 1947-2016")
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_baseball_9-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df_gather) +
aes(x = Year, y = Percent) +
facet_wrap(~ Ethnicity) +
geom_area(alpha = .5,
position = "dodge") +
aes(fill = type) +
labs(fill = "") +
labs(x = "") +
labs(title = "American Baseball Demographics 1947-2016") +
* labs(subtitle = "Percentage of players and WAR percentage (WAR is a calculation of value contributed)\nData: SABR.org | Vis: @EvaMaeRey for #MakeoverMonday")
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_baseball_10-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df_gather) +
aes(x = Year, y = Percent) +
facet_wrap(~ Ethnicity) +
geom_area(alpha = .5,
position = "dodge") +
aes(fill = type) +
labs(fill = "") +
labs(x = "") +
labs(title = "American Baseball Demographics 1947-2016") +
labs(subtitle = "Percentage of players and WAR percentage (WAR is a calculation of value contributed)\nData: SABR.org | Vis: @EvaMaeRey for #MakeoverMonday") +
* theme_light()
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_baseball_11-1.png" width="80%" />
]]
---
---
# Hic sunt dracones!
This book is not complete. The plots that follow aren't as carefully edited as what precedes. But feel free to have a look around. This "here be dragons" slide should move later and later on as weeks go by. Also I hope to add new work as time goes on.
---
name:parentalleave
# Maternal Leave
The OECD provides a comparative report on how much paid leave women are entitled to after childbirth. But leave takes different forms. In some places, the allowed leave is longer, but sometimes that means that the pay out compared to the regular salary is lower. To emphasize the different forms that law around paid leave take, I plotted the total payout available to mothers as areas of rectangles, where one side is the length of leave allowed, and the other side is the proportion of salary paid to the new mom.
A random sample from the data set:
<table>
<thead>
<tr>
<th style="text-align:left;"> Country </th>
<th style="text-align:right;"> Paid maternity leave avg payment rate (%) </th>
<th style="text-align:right;"> Paid maternity leave full rate equivalent in weeks </th>
<th style="text-align:right;"> Paid maternity leave in weeks </th>
<th style="text-align:right;"> Paid parental leave avg payment rate (%) </th>
<th style="text-align:right;"> Paid parental leave full rate equivalent in weeks </th>
<th style="text-align:right;"> Paid parental leave in weeks </th>
<th style="text-align:right;"> Total paid leave avg payment rate (%) </th>
<th style="text-align:right;"> Total paid leave full rate equivalent in weeks </th>
<th style="text-align:right;"> Total paid leave in weeks </th>
<th style="text-align:left;"> rank_name </th>
<th style="text-align:right;"> paid_leave_months </th>
<th style="text-align:right;"> total_paid_yearly_salaries </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> Belgium </td>
<td style="text-align:right;"> 64.1 </td>
<td style="text-align:right;"> 9.6 </td>
<td style="text-align:right;"> 15 </td>
<td style="text-align:right;"> 20.2 </td>
<td style="text-align:right;"> 3.5 </td>
<td style="text-align:right;"> 17.3 </td>
<td style="text-align:right;"> 40.6 </td>
<td style="text-align:right;"> 13.1 </td>
<td style="text-align:right;"> 32.3 </td>
<td style="text-align:left;"> #27: Belgium </td>
<td style="text-align:right;"> 7.433425 </td>
<td style="text-align:right;"> 0.2519231 </td>
</tr>
<tr>
<td style="text-align:left;"> Canada </td>
<td style="text-align:right;"> 48.4 </td>
<td style="text-align:right;"> 8.2 </td>
<td style="text-align:right;"> 17 </td>
<td style="text-align:right;"> 54.9 </td>
<td style="text-align:right;"> 19.2 </td>
<td style="text-align:right;"> 35.0 </td>
<td style="text-align:right;"> 52.8 </td>
<td style="text-align:right;"> 27.4 </td>
<td style="text-align:right;"> 52.0 </td>
<td style="text-align:left;"> #15: Canada </td>
<td style="text-align:right;"> 11.967123 </td>
<td style="text-align:right;"> 0.5269231 </td>
</tr>
<tr>
<td style="text-align:left;"> United States </td>
<td style="text-align:right;"> 0.0 </td>
<td style="text-align:right;"> 0.0 </td>
<td style="text-align:right;"> 0 </td>
<td style="text-align:right;"> 0.0 </td>
<td style="text-align:right;"> 0.0 </td>
<td style="text-align:right;"> 0.0 </td>
<td style="text-align:right;"> 0.0 </td>
<td style="text-align:right;"> 0.0 </td>
<td style="text-align:right;"> 0.0 </td>
<td style="text-align:left;"> #35: United States </td>
<td style="text-align:right;"> 0.000000 </td>
<td style="text-align:right;"> 0.0000000 </td>
</tr>
<tr>
<td style="text-align:left;"> Czech Republic </td>
<td style="text-align:right;"> 62.6 </td>
<td style="text-align:right;"> 17.5 </td>
<td style="text-align:right;"> 28 </td>
<td style="text-align:right;"> 43.4 </td>
<td style="text-align:right;"> 35.6 </td>
<td style="text-align:right;"> 82.0 </td>
<td style="text-align:right;"> 48.3 </td>
<td style="text-align:right;"> 53.1 </td>
<td style="text-align:right;"> 110.0 </td>
<td style="text-align:left;"> #5: Czech Republic </td>
<td style="text-align:right;"> 25.315068 </td>
<td style="text-align:right;"> 1.0211538 </td>
</tr>
<tr>
<td style="text-align:left;"> Iceland </td>
<td style="text-align:right;"> 59.7 </td>
<td style="text-align:right;"> 7.8 </td>
<td style="text-align:right;"> 13 </td>
<td style="text-align:right;"> 59.7 </td>
<td style="text-align:right;"> 7.8 </td>
<td style="text-align:right;"> 13.0 </td>
<td style="text-align:right;"> 59.7 </td>
<td style="text-align:right;"> 15.5 </td>
<td style="text-align:right;"> 26.0 </td>
<td style="text-align:left;"> #25: Iceland </td>
<td style="text-align:right;"> 5.983562 </td>
<td style="text-align:right;"> 0.2980769 </td>
</tr>
</tbody>
</table>
---
class: split-40
count: false
.column[.content[
```r
*ggplot(df)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_parent_leave_1-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df) +
* aes(x = paid_leave_months)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_parent_leave_2-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df) +
aes(x = paid_leave_months) +
* aes(y = `Total paid leave avg payment rate (%)`)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_parent_leave_3-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df) +
aes(x = paid_leave_months) +
aes(y = `Total paid leave avg payment rate (%)`) +
* aes(xmin = 0)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_parent_leave_4-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df) +
aes(x = paid_leave_months) +
aes(y = `Total paid leave avg payment rate (%)`) +
aes(xmin = 0) +
* aes(xmax = paid_leave_months)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_parent_leave_5-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df) +
aes(x = paid_leave_months) +
aes(y = `Total paid leave avg payment rate (%)`) +
aes(xmin = 0) +
aes(xmax = paid_leave_months) +
* aes(ymin = 0)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_parent_leave_6-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df) +
aes(x = paid_leave_months) +
aes(y = `Total paid leave avg payment rate (%)`) +
aes(xmin = 0) +
aes(xmax = paid_leave_months) +
aes(ymin = 0) +
* aes(ymax = `Total paid leave avg payment rate (%)`)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_parent_leave_7-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df) +
aes(x = paid_leave_months) +
aes(y = `Total paid leave avg payment rate (%)`) +
aes(xmin = 0) +
aes(xmax = paid_leave_months) +
aes(ymin = 0) +
aes(ymax = `Total paid leave avg payment rate (%)`) +
* facet_wrap(fct_inorder(rank_name) ~ .)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_parent_leave_8-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df) +
aes(x = paid_leave_months) +
aes(y = `Total paid leave avg payment rate (%)`) +
aes(xmin = 0) +
aes(xmax = paid_leave_months) +
aes(ymin = 0) +
aes(ymax = `Total paid leave avg payment rate (%)`) +
facet_wrap(fct_inorder(rank_name) ~ .) +
* geom_rect(fill = "blue", alpha = .2)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_parent_leave_9-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[
```r
ggplot(df) +
aes(x = paid_leave_months) +
aes(y = `Total paid leave avg payment rate (%)`) +
aes(xmin = 0) +
aes(xmax = paid_leave_months) +
aes(ymin = 0) +
aes(ymax = `Total paid leave avg payment rate (%)`) +
facet_wrap(fct_inorder(rank_name) ~ .) +
geom_rect(fill = "blue", alpha = .2) +
* aes(yend = 0)
```
]]
.column[.content.center[
<img src="ggplot_flipbook_xaringan_files/figure-html/output_parent_leave_10-1.png" width="80%" />
]]
---
class: split-40
count: false
.column[.content[