-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-Olympic-history.html
1028 lines (1002 loc) · 118 KB
/
2-Olympic-history.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="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-0.9.464">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>kaggle - 2 Olympic history</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script id="quarto-search-options" type="application/json">{
"location": "sidebar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "start",
"type": "textbox",
"limit": 20,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit"
}
}</script>
<script src="site_libs\quarto-nav\quarto-nav.js"></script><script src="site_libs\quarto-nav\headroom.min.js"></script><script src="site_libs\clipboard\clipboard.min.js"></script><script src="site_libs\quarto-search\autocomplete.umd.js"></script><script src="site_libs\quarto-search\fuse.min.js"></script><script src="site_libs\quarto-search\quarto-search.js"></script><meta name="quarto:offset" content="./"><link href="/3-HR-comma-sep.html" rel="next"><link href="/1-vgsales.html" rel="prev"><script src="site_libs\quarto-html\quarto.js"></script><script src="site_libs\quarto-html\popper.min.js"></script><script src="site_libs\quarto-html\tippy.umd.min.js"></script><script src="site_libs\quarto-html\anchor.min.js"></script><link href="site_libs\quarto-html\tippy.css" rel="stylesheet"><link href="site_libs\quarto-html\quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles"><script src="site_libs\bootstrap\bootstrap.min.js"></script><link href="site_libs\bootstrap\bootstrap-icons.css" rel="stylesheet"><link href="site_libs\bootstrap\bootstrap.min.css" rel="stylesheet"></head>
<body class="nav-sidebar floating">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="quarto-secondary-nav" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<div class="container-fluid d-flex justify-content-between">
<h1 class="quarto-secondary-nav-title"><span class="chapter-number">2</span> <span class="chapter-title">Olympic history</span></h1>
<button type="button" class="quarto-btn-toggle btn" aria-label="Show secondary navigation">
<i class="bi bi-chevron-right"></i>
</button>
</div>
</nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse sidebar-navigation floating overflow-auto">
<div class="pt-lg-2 mt-2 text-left sidebar-header">
<div class="sidebar-title mb-0 py-0">
<a href="./">kaggle</a>
</div>
</div>
<div class="mt-2 flex-shrink-0 align-items-center">
<div class="sidebar-search">
<div id="quarto-search" class="" title="Search"></div>
</div>
</div>
<div class="sidebar-menu-container">
<ul class="list-unstyled mt-1">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./index.html" class="sidebar-item-text sidebar-link">简介</a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./1-vgsales.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">1</span> <span class="chapter-title">Video Games Sales</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./2-Olympic-history.html" class="sidebar-item-text sidebar-link active"><span class="chapter-number">2</span> <span class="chapter-title">Olympic history</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./3-HR-comma-sep.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">3</span> <span class="chapter-title">员工离职分析</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./4-creditcard.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">4</span> <span class="chapter-title">信用卡欺诈识别</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./5-Student-performance-level.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">5</span> <span class="chapter-title">学生成绩水平分类</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./6-mass-shoot.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">6</span> <span class="chapter-title">美国大规模枪击案</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./7-hotel-demond.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">7</span> <span class="chapter-title">酒店房间预定预测</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./9990-references.html" class="sidebar-item-text sidebar-link">参考文献</a>
</div>
</li>
</ul>
</div>
</nav>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#olympic-intro" id="toc-olympic-intro" class="nav-link active" data-scroll-target="#olympic-intro"> <span class="header-section-number">2.1</span> 介绍</a></li>
<li><a href="#运动员国家和时间" id="toc-运动员国家和时间" class="nav-link" data-scroll-target="#运动员国家和时间"> <span class="header-section-number">2.2</span> 运动员、国家和时间</a>
<ul class="collapse">
<li><a href="#随着时间的推移运动员国家和赛事的数量是否发生了变化" id="toc-随着时间的推移运动员国家和赛事的数量是否发生了变化" class="nav-link" data-scroll-target="#随着时间的推移运动员国家和赛事的数量是否发生了变化"> <span class="header-section-number">2.2.1</span> 随着时间的推移,运动员、国家和赛事的数量是否发生了变化?</a></li>
</ul></li>
<li><a href="#sec:art-com" id="toc-sec:art-com" class="nav-link" data-scroll-target="#sec\:art-com"> <span class="header-section-number">2.3</span> 艺术竞赛(The Art Competitions)</a>
<ul class="collapse">
<li><a href="#运动员时间参赛项目" id="toc-运动员时间参赛项目" class="nav-link" data-scroll-target="#运动员时间参赛项目"> <span class="header-section-number">2.3.1</span> 运动员、时间、参赛项目</a></li>
<li><a href="#获得奖牌情况-哪个国家获得的艺术竞赛类奖牌数量最多" id="toc-获得奖牌情况-哪个国家获得的艺术竞赛类奖牌数量最多" class="nav-link" data-scroll-target="#获得奖牌情况-哪个国家获得的艺术竞赛类奖牌数量最多"> <span class="header-section-number">2.3.2</span> 获得奖牌情况-哪个国家获得的艺术竞赛类奖牌数量最多</a></li>
</ul></li>
<li><a href="#奥林匹克中的女将们" id="toc-奥林匹克中的女将们" class="nav-link" data-scroll-target="#奥林匹克中的女将们"> <span class="header-section-number">2.4</span> 奥林匹克中的女将们</a>
<ul class="collapse">
<li><a href="#男女运动员数量比较" id="toc-男女运动员数量比较" class="nav-link" data-scroll-target="#男女运动员数量比较"> <span class="header-section-number">2.4.1</span> 男女运动员数量比较</a></li>
<li><a href="#各国参赛男女运动员间数量关系" id="toc-各国参赛男女运动员间数量关系" class="nav-link" data-scroll-target="#各国参赛男女运动员间数量关系"> <span class="header-section-number">2.4.2</span> 各国参赛男女运动员间数量关系</a></li>
</ul></li>
<li><a href="#奖牌榜medal-count" id="toc-奖牌榜medal-count" class="nav-link" data-scroll-target="#奖牌榜medal-count"> <span class="header-section-number">2.5</span> 奖牌榜(Medal Count)</a></li>
<li><a href="#地理信息地图" id="toc-地理信息地图" class="nav-link" data-scroll-target="#地理信息地图"> <span class="header-section-number">2.6</span> 地理信息地图</a>
<ul class="collapse">
<li><a href="#年奥运会情况" id="toc-年奥运会情况" class="nav-link" data-scroll-target="#年奥运会情况"> <span class="header-section-number">2.6.1</span> 1928年奥运会情况</a></li>
<li><a href="#年奥运会情况-1" id="toc-年奥运会情况-1" class="nav-link" data-scroll-target="#年奥运会情况-1"> <span class="header-section-number">2.6.2</span> 1972年奥运会情况</a></li>
<li><a href="#年奥运会情况-2" id="toc-年奥运会情况-2" class="nav-link" data-scroll-target="#年奥运会情况-2"> <span class="header-section-number">2.6.3</span> 2016年奥运会情况</a></li>
</ul></li>
<li><a href="#参赛运动员身高体重" id="toc-参赛运动员身高体重" class="nav-link" data-scroll-target="#参赛运动员身高体重"> <span class="header-section-number">2.7</span> 参赛运动员身高体重</a>
<ul class="collapse">
<li><a href="#数据完整性及可用性检测" id="toc-数据完整性及可用性检测" class="nav-link" data-scroll-target="#数据完整性及可用性检测"> <span class="header-section-number">2.7.1</span> 数据完整性及可用性检测</a></li>
<li><a href="#身高体重" id="toc-身高体重" class="nav-link" data-scroll-target="#身高体重"> <span class="header-section-number">2.7.2</span> 身高体重</a></li>
<li><a href="#change-in-weight-vs-change-in-height-over-times-across-mens-sports" id="toc-change-in-weight-vs-change-in-height-over-times-across-mens-sports" class="nav-link" data-scroll-target="#change-in-weight-vs-change-in-height-over-times-across-mens-sports"> <span class="header-section-number">2.7.3</span> change in Weight VS change in Height over times across men’s sports</a></li>
</ul></li>
</ul>
</nav>
</div>
<!-- main -->
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title"><span id="Olympic-history" class="quarto-section-identifier d-none d-lg-block"><span class="chapter-number">2</span> <span class="chapter-title">Olympic history</span></span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<section id="olympic-intro" class="level2" data-number="2.1">
<h2 data-number="2.1" class="anchored" data-anchor-id="olympic-intro"><span class="header-section-number">2.1</span> 介绍</h2>
<p>本项目的主要目标是阐明奥运会历史的主要模式,例如运动员、运动、参与国家的数量,哪些国家的运动员最多,赢得奖牌情况,运动员的特性(eg:性别、身体特征等)。</p>
<p>我将一些你可能不知道的奥运历史上特别有趣的方面进行放大化。你知道纳粹德国举办了1936年奥运会,而那届奥运会他们打败了所有人?你知道绘画和诗歌曾经是奥运会项目吗?这些历史小花絮同样是我的关注点。</p>
<p>首先,我们读取数据,并对每列的数据类型进行定义。</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>file<span class="ot"><-</span> <span class="st">"D:/Tools/Rwork/0.Study R/kaggle-project/data/olympics/athlete_events.csv"</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>data <span class="ot"><-</span> <span class="fu">read_csv</span>(file,</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="at">col_types =</span> <span class="fu">cols</span>(</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="at">ID =</span> <span class="fu">col_character</span>(),</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="at">Name =</span> <span class="fu">col_character</span>(),</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="at">Sex =</span> <span class="fu">col_factor</span>(<span class="at">levels =</span> <span class="fu">c</span>(<span class="st">"M"</span>,<span class="st">"F"</span>)),</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> <span class="at">Age =</span> <span class="fu">col_integer</span>(),</span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> <span class="at">Height =</span> <span class="fu">col_double</span>(),</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="at">Weight =</span> <span class="fu">col_double</span>(),</span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> <span class="at">Team =</span> <span class="fu">col_character</span>(),</span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> <span class="at">NOC =</span> <span class="fu">col_character</span>(),</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a> <span class="at">Games =</span> <span class="fu">col_character</span>(),</span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a> <span class="at">Year =</span> <span class="fu">col_integer</span>(),</span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a> <span class="at">Season =</span> <span class="fu">col_factor</span>(<span class="at">levels =</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">c</span>(<span class="st">"Summer"</span>,<span class="st">"Winter"</span>)),</span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a> <span class="at">City =</span> <span class="fu">col_character</span>(),</span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a> <span class="at">Sport =</span> <span class="fu">col_character</span>(),</span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a> <span class="at">Event =</span> <span class="fu">col_character</span>(),</span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true" tabindex="-1"></a> <span class="at">Medal =</span> <span class="fu">col_factor</span>(<span class="at">levels =</span></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a> <span class="fu">c</span>(<span class="st">"Gold"</span>,<span class="st">"Silver"</span>,<span class="st">"Bronze"</span>))</span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a> ))</span>
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(data)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6 × 15
ID Name Sex Age Height Weight Team NOC Games Year Season City
<chr> <chr> <fct> <int> <dbl> <dbl> <chr> <chr> <chr> <int> <fct> <chr>
1 1 A Dijiang M 24 180 80 China CHN 1992… 1992 Summer Barc…
2 2 A Lamusi M 23 170 60 China CHN 2012… 2012 Summer Lond…
3 3 Gunnar N… M 24 NA NA Denm… DEN 1920… 1920 Summer Antw…
4 4 Edgar Li… M 34 NA NA Denm… DEN 1900… 1900 Summer Paris
5 5 Christin… F 21 185 82 Neth… NED 1988… 1988 Winter Calg…
6 5 Christin… F 21 185 82 Neth… NED 1988… 1988 Winter Calg…
# … with 3 more variables: Sport <chr>, Event <chr>, Medal <fct></code></pre>
</div>
</div>
</section>
<section id="运动员国家和时间" class="level2" data-number="2.2">
<h2 data-number="2.2" class="anchored" data-anchor-id="运动员国家和时间"><span class="header-section-number">2.2</span> 运动员、国家和时间</h2>
<section id="随着时间的推移运动员国家和赛事的数量是否发生了变化" class="level3" data-number="2.2.1">
<h3 data-number="2.2.1" class="anchored" data-anchor-id="随着时间的推移运动员国家和赛事的数量是否发生了变化"><span class="header-section-number">2.2.1</span> 随着时间的推移,运动员、国家和赛事的数量是否发生了变化?</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>counts <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Sport <span class="sc">!=</span> <span class="st">"Art Competitions"</span>) <span class="sc">%>%</span> <span class="co"># 去掉艺术类的运动类别</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Year, Season) <span class="sc">%>%</span> </span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="at">Athletes =</span> <span class="fu">length</span>(<span class="fu">unique</span>(ID)),</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> <span class="at">Nations =</span> <span class="fu">length</span>(<span class="fu">unique</span>(NOC)),</span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="at">Events =</span> <span class="fu">length</span>(<span class="fu">unique</span>(Event))</span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a>counts</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 51 × 5
# Groups: Year [35]
Year Season Athletes Nations Events
<int> <fct> <int> <int> <int>
1 1896 Summer 176 12 43
2 1900 Summer 1224 31 90
3 1904 Summer 650 15 95
4 1906 Summer 841 21 74
5 1908 Summer 2024 22 109
6 1912 Summer 2377 27 102
7 1920 Summer 2665 29 153
8 1924 Summer 3067 44 126
9 1924 Winter 313 19 17
10 1928 Summer 2877 46 109
# … with 41 more rows</code></pre>
</div>
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 作图</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a><span class="co"># 运动员数量及关键时间点</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>p1 <span class="ot"><-</span> <span class="fu">ggplot</span>(counts, <span class="fu">aes</span>(<span class="at">x =</span> Year, <span class="at">y =</span> Athletes, </span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="at">group =</span> Season, <span class="at">color =</span> Season)) <span class="sc">+</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="at">size =</span> <span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_color_manual</span>(<span class="at">values =</span> <span class="fu">c</span>(<span class="st">"darkorange"</span>, <span class="st">"darkblue"</span>)) <span class="sc">+</span> <span class="co"># 手动设置图形颜色</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">xlab</span>(<span class="st">" "</span>) <span class="sc">+</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">annotate</span>(<span class="st">"text"</span>, <span class="at">x =</span> <span class="fu">c</span>(<span class="dv">1932</span>, <span class="dv">1956</span>, <span class="dv">1976</span>, <span class="dv">1980</span>),</span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> <span class="fu">c</span>(<span class="dv">2000</span>, <span class="dv">2750</span>, <span class="dv">6800</span>, <span class="dv">4700</span>),</span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="fu">c</span>(</span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a> <span class="st">"L.A. 1932"</span>,</span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a> <span class="st">"Melbourne 1956"</span>,</span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a> <span class="st">"Montreal 1976"</span>,</span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a> <span class="st">"Moscow 1980"</span>),</span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a> <span class="at">size=</span><span class="dv">3</span>) <span class="sc">+</span> <span class="co"># 对几个临界拐点进行标记。</span></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a> <span class="co"># 针对两次世界大战的时间做出标记</span></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true" tabindex="-1"></a> <span class="fu">annotate</span>(<span class="st">"text"</span>, <span class="at">x =</span> <span class="fu">c</span>(<span class="dv">1916</span>,<span class="dv">1942</span>), <span class="at">y =</span> <span class="fu">c</span>(<span class="dv">10000</span>,<span class="dv">10000</span>),</span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="fu">c</span>(<span class="st">"WWI"</span>, <span class="st">"WWII"</span>), </span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true" tabindex="-1"></a> <span class="at">size =</span> <span class="dv">4</span>, <span class="at">color =</span> <span class="st">"red"</span>) <span class="sc">+</span></span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_segment</span>(<span class="fu">aes</span>(<span class="at">x =</span> <span class="dv">1914</span>, <span class="at">y =</span> <span class="dv">8000</span>, <span class="at">xend =</span> <span class="dv">1918</span>, <span class="at">yend =</span> <span class="dv">8000</span>),</span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true" tabindex="-1"></a> <span class="at">color =</span> <span class="st">"red"</span>, <span class="at">size =</span> <span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_segment</span>(<span class="fu">aes</span>(<span class="at">x =</span> <span class="dv">1939</span>,<span class="at">y =</span> <span class="dv">8000</span>, <span class="at">xend =</span> <span class="dv">1945</span>, <span class="at">yend =</span> <span class="dv">8000</span>),</span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true" tabindex="-1"></a> <span class="at">color =</span> <span class="st">"red"</span>, <span class="at">size=</span><span class="dv">2</span>) <span class="sc">+</span> </span>
<span id="cb5-25"><a href="#cb5-25" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">1890</span>, <span class="dv">2020</span>, <span class="dv">4</span>)) <span class="sc">+</span></span>
<span id="cb5-26"><a href="#cb5-26" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">15000</span>, <span class="dv">5000</span>)) <span class="sc">+</span></span>
<span id="cb5-27"><a href="#cb5-27" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb5-28"><a href="#cb5-28" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>, <span class="at">angle =</span> <span class="dv">90</span>, <span class="at">vjust =</span> <span class="fl">0.4</span>, <span class="at">face =</span> <span class="st">"bold"</span>))</span>
<span id="cb5-29"><a href="#cb5-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-30"><a href="#cb5-30" aria-hidden="true" tabindex="-1"></a><span class="co"># 参与国家数量及关键时间点</span></span>
<span id="cb5-31"><a href="#cb5-31" aria-hidden="true" tabindex="-1"></a>p2 <span class="ot"><-</span> <span class="fu">ggplot</span>(counts, <span class="fu">aes</span>(<span class="at">x =</span> Year, <span class="at">y =</span> Nations, </span>
<span id="cb5-32"><a href="#cb5-32" aria-hidden="true" tabindex="-1"></a> <span class="at">group =</span> Season, <span class="at">color =</span> Season)) <span class="sc">+</span></span>
<span id="cb5-33"><a href="#cb5-33" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="at">size =</span> <span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb5-34"><a href="#cb5-34" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span></span>
<span id="cb5-35"><a href="#cb5-35" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_color_manual</span>(<span class="at">values =</span> <span class="fu">c</span>(<span class="st">"darkorange"</span>, <span class="st">"darkblue"</span>)) <span class="sc">+</span></span>
<span id="cb5-36"><a href="#cb5-36" aria-hidden="true" tabindex="-1"></a> <span class="fu">xlab</span>(<span class="st">""</span>) <span class="sc">+</span></span>
<span id="cb5-37"><a href="#cb5-37" aria-hidden="true" tabindex="-1"></a> <span class="fu">annotate</span>(<span class="st">"text"</span>, <span class="at">x =</span> <span class="fu">c</span>(<span class="dv">1932</span>, <span class="dv">1976</span>, <span class="dv">1980</span>),</span>
<span id="cb5-38"><a href="#cb5-38" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> <span class="fu">c</span>(<span class="dv">60</span>, <span class="dv">105</span>, <span class="dv">70</span>),</span>
<span id="cb5-39"><a href="#cb5-39" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="fu">c</span>(<span class="st">"L.A. 1932"</span>,</span>
<span id="cb5-40"><a href="#cb5-40" aria-hidden="true" tabindex="-1"></a> <span class="st">"Montreal 1976"</span>,</span>
<span id="cb5-41"><a href="#cb5-41" aria-hidden="true" tabindex="-1"></a> <span class="st">"Moscow 1980"</span>)) <span class="sc">+</span></span>
<span id="cb5-42"><a href="#cb5-42" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">1890</span>, <span class="dv">2020</span>, <span class="dv">4</span>)) <span class="sc">+</span></span>
<span id="cb5-43"><a href="#cb5-43" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">250</span>, <span class="dv">50</span>)) <span class="sc">+</span></span>
<span id="cb5-44"><a href="#cb5-44" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span> </span>
<span id="cb5-45"><a href="#cb5-45" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>, <span class="at">angle =</span> <span class="dv">90</span>, <span class="at">vjust =</span> <span class="fl">0.4</span>, <span class="at">face =</span> <span class="st">"bold"</span>))</span>
<span id="cb5-46"><a href="#cb5-46" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-47"><a href="#cb5-47" aria-hidden="true" tabindex="-1"></a><span class="co"># 参赛项目</span></span>
<span id="cb5-48"><a href="#cb5-48" aria-hidden="true" tabindex="-1"></a>p3 <span class="ot"><-</span> <span class="fu">ggplot</span>(counts, <span class="fu">aes</span>(<span class="at">x =</span> Year, <span class="at">y =</span> Events, <span class="at">group =</span> Season, <span class="at">color =</span> Season)) <span class="sc">+</span></span>
<span id="cb5-49"><a href="#cb5-49" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="at">size =</span> <span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb5-50"><a href="#cb5-50" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span></span>
<span id="cb5-51"><a href="#cb5-51" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_color_manual</span>(<span class="at">values =</span> <span class="fu">c</span>(<span class="st">"darkorange"</span>, <span class="st">"darkblue"</span>)) <span class="sc">+</span></span>
<span id="cb5-52"><a href="#cb5-52" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">1890</span>, <span class="dv">2020</span>, <span class="dv">4</span>)) <span class="sc">+</span></span>
<span id="cb5-53"><a href="#cb5-53" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">350</span>, <span class="dv">50</span>)) <span class="sc">+</span></span>
<span id="cb5-54"><a href="#cb5-54" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb5-55"><a href="#cb5-55" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>, <span class="at">angle =</span> <span class="dv">90</span>, <span class="at">vjust =</span> <span class="fl">0.4</span>, <span class="at">face =</span> <span class="st">"bold"</span>))</span>
<span id="cb5-56"><a href="#cb5-56" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-57"><a href="#cb5-57" aria-hidden="true" tabindex="-1"></a><span class="fu">grid.arrange</span>(p1, p2, p3, <span class="at">ncol =</span> <span class="dv">1</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="2-Olympic-history_files/figure-html/countNO-1.png" class="img-fluid figure-img" width="672"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">(ref:fig-countNO)</figcaption><p></p>
</figure>
</div>
</div>
</div>
<p>(ref:fig-countNO) 随着时间的推移,运动员、国家和赛事的数量的变化情况</p>
<p>从图@ref(fig:countNO) 可以看出两次世界大战期间,奥运会基本处于停滞状态(WWI:1912-1920,WWII:1936-1948)。此外,有几届值得注意的奥运会上发生了一些事件,在图形中呈现为明显的下降趋势:</p>
<ul>
<li><p>L.A., 1932: 1932年洛杉矶奥运会,当时的美国正处于大萧条期间,许多运动员没办法负担到奥运会的差旅费用,导致参加本届奥运会的国家机器运动员数量骤降。</p></li>
<li><p>Melbourne, 1956:1956年墨尔本奥运会是事端最多的一届奥运会:1、由于战争立场不同,包括埃及、以色列、伊拉克和黎巴嫩在内的一些中东及非洲国家,西班牙、荷兰、瑞士、哥伦比亚等欧洲国家均抵制本届奥运会;2.由于台湾问题,我国也未参加本届奥运会。</p></li>
<li><p>Montreal, 1976:1976年蒙特利尔奥运会,由于发生了抵制运动,25个国家(大部分为非洲国家)未参加本届奥运会。</p></li>
<li><p>Moscow, 1980:1980年莫斯科奥运会,由于苏联军队对阿富汗的入侵,包括美国在内的66个国家对本届奥运会进行了抵制,本届奥运会最终仅有80个国家参加,是自1956年以来最少国家参加的一届,而许多参赛的国家也只派一名旗手,以奥运会会旗代替国旗进场。这是奥运历史上最严重的一次危机,从一定程度上威胁了奥林匹克运动的发展。</p></li>
</ul>
<p>从2000年开始,奥运会的增长势头(比赛项目额参赛运动员数量)趋于平缓,夏季奥运会迎来了它的饱和点。而冬季奥运会处于虽然还有一定上升空间,但冰雪运动受限于气候和场地,在很多国家并不普吉,所以其涨势并不明显。</p>
</section>
</section>
<section id="sec:art-com" class="level2" data-number="2.3">
<h2 data-number="2.3" class="anchored" data-anchor-id="sec:art-com"><span class="header-section-number">2.3</span> 艺术竞赛(The Art Competitions)</h2>
<section id="运动员时间参赛项目" class="level3" data-number="2.3.1">
<h3 data-number="2.3.1" class="anchored" data-anchor-id="运动员时间参赛项目"><span class="header-section-number">2.3.1</span> 运动员、时间、参赛项目</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>art <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Sport <span class="sc">==</span> <span class="st">"Art Competitions"</span>) <span class="sc">%>%</span> </span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(Name, Sex, Age, Team, NOC, Year, City, Event, Medal)</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(art)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6 × 9
Name Sex Age Team NOC Year City Event Medal
<chr> <fct> <int> <chr> <chr> <int> <chr> <chr> <fct>
1 Win Valdemar Aaltonen M 54 Finland FIN 1948 London Art C… <NA>
2 Adolf Gaston Abel M 45 Germany GER 1928 Amsterdam Art C… <NA>
3 Adolf Gaston Abel M 45 Germany GER 1928 Amsterdam Art C… <NA>
4 Georges Achille-Fould F 55 France FRA 1924 Paris Art C… <NA>
5 Dsir Antoine Acket M 27 Belgium BEL 1932 Los Angeles Art C… <NA>
6 Dsir Antoine Acket M 27 Belgium BEL 1932 Los Angeles Art C… <NA> </code></pre>
</div>
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 基础计算</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>count_art <span class="ot"><-</span> art <span class="sc">%>%</span> </span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Year) <span class="sc">%>%</span> </span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(</span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> <span class="at">Events =</span> <span class="fu">length</span>(<span class="fu">unique</span>(Event)),</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a> <span class="at">Nations =</span> <span class="fu">length</span>(<span class="fu">unique</span>(Team)),</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a> <span class="at">Artists =</span> <span class="fu">length</span>(<span class="fu">unique</span>(Name))</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(count_art)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6 × 4
Year Events Nations Artists
<int> <int> <int> <int>
1 1912 5 12 33
2 1920 5 5 11
3 1924 5 24 189
4 1928 13 19 370
5 1932 13 36 588
6 1936 19 24 527</code></pre>
</div>
</div>
<p>在最初的奥运会中,还存在艺术竞赛(Art Competition)项目的比拼,准确的说从1912年至1948年间的几届奥运会。</p>
<p>1954年,国际奥委会决定艺术竞赛不再作为奥运会的比赛项目。</p>
<p>虽然艺术竞赛的数据仅占本数据集的1.3%,但考虑到其在奥运会理事上的特殊意义,仍有必要对其进行探索分析。</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 提取有关艺术竞赛的数据</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a>art <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Sport <span class="sc">==</span> <span class="st">"Art Competitions"</span>) <span class="sc">%>%</span> </span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(Name, Sex, Age, Team, NOC, Year, City, Event, Medal)</span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a><span class="co"># 计算每年的Events, Nations, Artists数量</span></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a>counts_art <span class="ot"><-</span> art <span class="sc">%>%</span> </span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Team <span class="sc">!=</span> <span class="st">"Unknow"</span>) <span class="sc">%>%</span> <span class="co"># 剔除国籍不确定的运动员</span></span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Year) <span class="sc">%>%</span> </span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(</span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a> <span class="at">Events =</span> <span class="fu">length</span>(<span class="fu">unique</span>(Event)),</span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a> <span class="at">Nations =</span> <span class="fu">length</span>(<span class="fu">unique</span>(Team)),</span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a> <span class="at">Artisit =</span> <span class="fu">length</span>(<span class="fu">unique</span>(Name))</span>
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>p4 <span class="ot"><-</span> <span class="fu">ggplot</span>(counts_art, <span class="fu">aes</span>(<span class="at">x =</span> Year, <span class="at">y =</span> Events)) <span class="sc">+</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="at">size =</span> <span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">xlab</span>(<span class="st">" "</span>) <span class="sc">+</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="fu">min</span>(counts_art[<span class="st">"Year"</span>]), <span class="fu">max</span>(counts_art[<span class="st">"Year"</span>]), <span class="dv">4</span>)) <span class="sc">+</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">20</span>, <span class="dv">2</span>)) <span class="sc">+</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>, <span class="at">vjust =</span> <span class="fl">0.4</span>, <span class="at">face =</span> <span class="st">"bold"</span>))</span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a>p5 <span class="ot"><-</span> <span class="fu">ggplot</span>(counts_art, <span class="fu">aes</span>(<span class="at">x =</span> Year, <span class="at">y =</span> Nations)) <span class="sc">+</span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="at">size =</span> <span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span> </span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">xlab</span>(<span class="st">" "</span>) <span class="sc">+</span></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="fu">min</span>(counts_art[<span class="st">"Year"</span>]), <span class="fu">max</span>(counts_art[<span class="st">"Year"</span>]), <span class="dv">4</span>)) <span class="sc">+</span></span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">40</span>, <span class="dv">5</span>)) <span class="sc">+</span></span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>, <span class="at">vjust =</span> <span class="fl">0.4</span>, <span class="at">face =</span> <span class="st">"bold"</span>))</span>
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true" tabindex="-1"></a>p6 <span class="ot"><-</span> <span class="fu">ggplot</span>(counts_art, <span class="fu">aes</span>(<span class="at">x =</span> Year, <span class="at">y =</span> Artisit)) <span class="sc">+</span></span>
<span id="cb11-20"><a href="#cb11-20" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="at">size =</span> <span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb11-21"><a href="#cb11-21" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span> </span>
<span id="cb11-22"><a href="#cb11-22" aria-hidden="true" tabindex="-1"></a> <span class="fu">xlab</span>(<span class="st">" "</span>) <span class="sc">+</span></span>
<span id="cb11-23"><a href="#cb11-23" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="fu">min</span>(counts_art[<span class="st">"Year"</span>]), <span class="fu">max</span>(counts_art[<span class="st">"Year"</span>]), <span class="dv">4</span>)) <span class="sc">+</span></span>
<span id="cb11-24"><a href="#cb11-24" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">600</span>, <span class="dv">100</span>)) <span class="sc">+</span></span>
<span id="cb11-25"><a href="#cb11-25" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb11-26"><a href="#cb11-26" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">size =</span> <span class="dv">10</span>, <span class="at">vjust =</span> <span class="fl">0.4</span>, <span class="at">face =</span> <span class="st">"bold"</span>))</span>
<span id="cb11-27"><a href="#cb11-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-28"><a href="#cb11-28" aria-hidden="true" tabindex="-1"></a><span class="fu">grid.arrange</span>(p4, p5, p6, <span class="at">ncol =</span> <span class="dv">1</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="2-Olympic-history_files/figure-html/art-competition-1.png" class="img-fluid figure-img" width="672"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">(ref:fig-art-competition)</figcaption><p></p>
</figure>
</div>
</div>
</div>
<p>(ref:fig-art-competition) 历届奥运会艺术竞赛随时间变化图(参与国家、参赛运动员、比赛项目)</p>
<p>如图@ref(fig:art-competition)所示,艺术竞赛的数据变化呈不规则的增长趋势。可以看到,与1920年相比,1924年奥运会参与艺术竞赛的国家和运动员数量均有相对较大幅度的增长,这或许是1928年奥运会艺术竞赛比赛项目增多的一个原因。</p>
</section>
<section id="获得奖牌情况-哪个国家获得的艺术竞赛类奖牌数量最多" class="level3" data-number="2.3.2">
<h3 data-number="2.3.2" class="anchored" data-anchor-id="获得奖牌情况-哪个国家获得的艺术竞赛类奖牌数量最多"><span class="header-section-number">2.3.2</span> 获得奖牌情况-哪个国家获得的艺术竞赛类奖牌数量最多</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 计算每个国家所获奖牌数量</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>medal_counts_arts <span class="ot"><-</span> art <span class="sc">%>%</span> </span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(<span class="sc">!</span><span class="fu">is.na</span>(Medal)) <span class="sc">%>%</span> </span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Team, Medal) <span class="sc">%>%</span> </span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">Count =</span> <span class="fu">length</span>(Medal))</span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a><span class="co"># 根据奖牌数量对国家进行排序</span></span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a>levs_art <span class="ot"><-</span> medal_counts_arts <span class="sc">%>%</span> </span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Team) <span class="sc">%>%</span> </span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">Total =</span> <span class="fu">sum</span>(Count)) <span class="sc">%>%</span> </span>
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">arrange</span>(Total) <span class="sc">%>%</span> </span>
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(Team)</span>
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true" tabindex="-1"></a>medal_counts_arts<span class="sc">$</span>Team <span class="ot"><-</span> <span class="fu">factor</span>(medal_counts_arts<span class="sc">$</span>Team, <span class="at">levels =</span> levs_art<span class="sc">$</span>Team)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(medal_counts_arts, <span class="fu">aes</span>(<span class="at">x =</span> Team, <span class="at">y =</span> Count, <span class="at">fill =</span> Medal)) <span class="sc">+</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_col</span>() <span class="sc">+</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">coord_flip</span>() <span class="sc">+</span></span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">30</span>, <span class="dv">5</span>)) <span class="sc">+</span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_fill_manual</span>(<span class="at">values =</span> <span class="fu">c</span>(<span class="st">"gold1"</span>, <span class="st">"gray70"</span>, <span class="st">"gold4"</span>)) <span class="sc">+</span></span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggtitle</span>(<span class="st">"艺术竞赛奖牌榜"</span>) <span class="sc">+</span></span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="2-Olympic-history_files/figure-html/medal-arts-1.png" class="img-fluid figure-img" width="672"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">(ref:fig-medal-arts)</figcaption><p></p>
</figure>
</div>
</div>
</div>
<p>(ref:fig-medal-arts) 各国艺术竞赛奖牌榜</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>art_country <span class="ot"><-</span> <span class="fu">nrow</span>(<span class="fu">unique</span>(art[<span class="st">"Team"</span>]))</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a>art_country_medal <span class="ot"><-</span> <span class="fu">nrow</span>(medal_counts_arts <span class="sc">%>%</span> </span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">country =</span> <span class="fu">length</span>(<span class="fu">unique</span>(Team)))</span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>共有51个国家参加了奥运会的艺术竞赛类项目,仅有不到一半数量的国家(23)获得了奖牌(如图@ref(fig:medal-arts)所示),排名前三位的为德国、法国、意大利。</p>
</section>
</section>
<section id="奥林匹克中的女将们" class="level2" data-number="2.4">
<h2 data-number="2.4" class="anchored" data-anchor-id="奥林匹克中的女将们"><span class="header-section-number">2.4</span> 奥林匹克中的女将们</h2>
<p>现代奥林匹克之父顾拜旦曾今极力反对女性参加奥运会。其后的IOC主席也同样支持这个观点。尽管有多方面的阻力,从第一届奥运会(1896年)开始的每届奥运会均有女性参与其中。所以我们在这里探索一下女性参加奥运会的历史趋势:多少人?从哪里来?她们如何找到途经参加的?</p>
<p>本部分中,对数据集进行如下处理:</p>
<ol type="1">
<li><p>将第@sec:art-com节中讨论过的艺术竞赛数据剔除。</p></li>
<li><p>将夏季和冬季奥运会合并为“Olympiads”列,即每四年期内包括一届夏季奥运会和一届冬季奥运会。</p></li>
</ol>
<p>让我们开始!</p>
<section id="男女运动员数量比较" class="level3" data-number="2.4.1">
<h3 data-number="2.4.1" class="anchored" data-anchor-id="男女运动员数量比较"><span class="header-section-number">2.4.1</span> 男女运动员数量比较</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 剔除艺术竞赛项目数据</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>data <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Sport <span class="sc">!=</span> <span class="st">"Art Competition"</span>)</span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a><span class="co"># 对Year列数据重新编码(1992年之后,与夏季奥运会匹配)</span></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a><span class="co"># 处理后,冬季和夏季奥运会举办时间的已匹配</span></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a>original <span class="ot"><-</span> <span class="fu">c</span>(<span class="dv">1994</span>, <span class="dv">1998</span>, <span class="dv">2002</span>, <span class="dv">2006</span>, <span class="dv">2010</span>, <span class="dv">2014</span>)</span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true" tabindex="-1"></a>new <span class="ot"><-</span> <span class="fu">c</span>(<span class="dv">1996</span>, <span class="dv">2000</span>, <span class="dv">2004</span>, <span class="dv">2008</span>, <span class="dv">2012</span>, <span class="dv">2016</span>)</span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(original)) {</span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true" tabindex="-1"></a> data<span class="sc">$</span>Year <span class="ot"><-</span> <span class="fu">gsub</span>(original[i], new[i], data<span class="sc">$</span>Year)</span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb15-12"><a href="#cb15-12" aria-hidden="true" tabindex="-1"></a>data<span class="sc">$</span>Year <span class="ot"><-</span> <span class="fu">as.integer</span>(data<span class="sc">$</span>Year)</span>
<span id="cb15-13"><a href="#cb15-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-14"><a href="#cb15-14" aria-hidden="true" tabindex="-1"></a>counts_sex <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb15-15"><a href="#cb15-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Year, Sex) <span class="sc">%>%</span> </span>
<span id="cb15-16"><a href="#cb15-16" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">Athletes =</span> <span class="fu">length</span>(<span class="fu">unique</span>(ID)))</span>
<span id="cb15-17"><a href="#cb15-17" aria-hidden="true" tabindex="-1"></a>counts_sex<span class="sc">$</span>Year <span class="ot"><-</span> <span class="fu">as.integer</span>(counts_sex<span class="sc">$</span>Year)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(counts_sex, <span class="fu">aes</span>(<span class="at">x =</span> Year, <span class="at">y =</span> Athletes, <span class="at">group =</span> Sex, <span class="at">color =</span> Sex)) <span class="sc">+</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="at">size =</span> <span class="dv">2</span>) <span class="sc">+</span> </span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_color_manual</span>(<span class="at">values =</span> <span class="fu">c</span>(<span class="st">"darkblue"</span>, <span class="st">"red"</span>)) <span class="sc">+</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">1896</span>, <span class="dv">2016</span>, <span class="dv">4</span>)) <span class="sc">+</span></span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_y_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">9000</span>, <span class="dv">500</span>)) <span class="sc">+</span></span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Number of male and female Olympians over time"</span>) <span class="sc">+</span></span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">plot.title=</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>),</span>
<span id="cb16-10"><a href="#cb16-10" aria-hidden="true" tabindex="-1"></a> <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">angle =</span> <span class="dv">90</span>, <span class="at">face =</span> <span class="st">"bold"</span>, <span class="at">vjust =</span> <span class="fl">0.5</span>)) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="2-Olympic-history_files/figure-html/counts-sex-1.png" class="img-fluid figure-img" width="672"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">(ref:fig-counts-sex)</figcaption><p></p>
</figure>
</div>
</div>
</div>
<p>(ref:fig-counts-sex) 历届奥运会南云运动员数量</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>counts_sex_latest <span class="ot"><-</span> counts_sex <span class="sc">%>%</span> </span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Year <span class="sc">==</span> <span class="dv">2016</span>)</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a>counts_sex_latest</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 2 × 3
# Groups: Year [1]
Year Sex Athletes
<int> <fct> <int>
1 2016 M 7788
2 2016 F 6133</code></pre>
</div>
</div>
<p>如图@ref(fig:counts-sex)所示,直到1996年,参加奥运会的女运动员数量的变化趋势都与男运动员相同,此时男运动员的数量达到8000人的最顶点,而此时女运动员的数量还在以一个较高的增长率上升。最近的一届奥运会(2014年索契冬奥会和2016年里约奥运会中),女运动的数量已经超过了0.4405574。</p>
</section>
<section id="各国参赛男女运动员间数量关系" class="level3" data-number="2.4.2">
<h3 data-number="2.4.2" class="anchored" data-anchor-id="各国参赛男女运动员间数量关系"><span class="header-section-number">2.4.2</span> 各国参赛男女运动员间数量关系</h3>
<p>选择1936,1956,1976,1996,2016五个年份的数据进行分析。这五年的数据互相间隔20年,可以独立的展示独立的回归曲线。</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Count M/F Total per country per Olympics</span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>counts_NOC <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Year <span class="sc">%in%</span> <span class="fu">c</span>(<span class="dv">1936</span>, <span class="dv">1956</span>, <span class="dv">1976</span>, <span class="dv">1996</span>, <span class="dv">2016</span>)) <span class="sc">%>%</span> </span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Year, NOC, Sex) <span class="sc">%>%</span> </span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">Count =</span> <span class="fu">length</span>(<span class="fu">unique</span>(ID))) <span class="sc">%>%</span> </span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">spread</span>(Sex, Count) <span class="sc">%>%</span> <span class="co"># 按照Sex为key,Count为value的规则进行pivot_wider()操作。</span></span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Total =</span> <span class="fu">sum</span>(M, F, <span class="at">na.rm =</span> T)) <span class="co"># 计算运动员总数</span></span>
<span id="cb19-8"><a href="#cb19-8" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(counts_NOC)[<span class="dv">3</span><span class="sc">:</span> <span class="dv">4</span>] <span class="ot"><-</span> <span class="fu">c</span>(<span class="st">"Male"</span>, <span class="st">"Female"</span>)</span>
<span id="cb19-9"><a href="#cb19-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-10"><a href="#cb19-10" aria-hidden="true" tabindex="-1"></a><span class="co"># 将缺失值变为0</span></span>
<span id="cb19-11"><a href="#cb19-11" aria-hidden="true" tabindex="-1"></a>counts_NOC<span class="sc">$</span>Male[<span class="fu">is.na</span>(counts_NOC<span class="sc">$</span>Male)] <span class="ot"><-</span> <span class="dv">0</span></span>
<span id="cb19-12"><a href="#cb19-12" aria-hidden="true" tabindex="-1"></a>counts_NOC<span class="sc">$</span>Female[<span class="fu">is.na</span>(counts_NOC<span class="sc">$</span>Female)] <span class="ot"><-</span> <span class="dv">0</span></span>
<span id="cb19-13"><a href="#cb19-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-14"><a href="#cb19-14" aria-hidden="true" tabindex="-1"></a>counts_NOC<span class="sc">$</span>Year <span class="ot"><-</span> <span class="fu">as.factor</span>(counts_NOC<span class="sc">$</span>Year) <span class="co"># 将Year列转化为因子</span></span>
<span id="cb19-15"><a href="#cb19-15" aria-hidden="true" tabindex="-1"></a>counts_NOC</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 622 × 5
# Groups: Year, NOC [622]
Year NOC Male Female Total
<fct> <chr> <dbl> <dbl> <int>
1 1936 AFG 15 0 15
2 1936 ARG 50 1 51
3 1936 AUS 29 4 33
4 1936 AUT 265 27 292
5 1936 BEL 168 8 176
6 1936 BER 5 0 5
7 1936 BOL 2 0 2
8 1936 BRA 67 6 73
9 1936 BUL 33 0 33
10 1936 CAN 101 25 126
# … with 612 more rows</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(counts_NOC, <span class="fu">aes</span>(<span class="at">x =</span> Male, <span class="at">y =</span> Female, <span class="at">group =</span> Year, <span class="at">color =</span> Year)) <span class="sc">+</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="at">alpha =</span> <span class="fl">0.5</span>) <span class="sc">+</span></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_abline</span>(<span class="at">intercept =</span> <span class="dv">0</span>, <span class="at">slope =</span> <span class="dv">1</span>, <span class="at">linetype =</span> <span class="st">"dashed"</span>) <span class="sc">+</span></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_smooth</span>(<span class="at">method =</span> <span class="st">"lm"</span>, <span class="at">se =</span> <span class="cn">FALSE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="2-Olympic-history_files/figure-html/5-years-regression-1.png" class="img-fluid figure-img" width="672"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">(ref:fig-5-years)</figcaption><p></p>
</figure>
</div>
</div>
</div>
<p>(ref:fig-5-years) 各国参加奥运会男女运动员比例关系</p>
<p>从图@ref(fig:5-years-regression)可以看出,与1936-1956年间女运动员的数量增长数量较为缓慢相比,1956-2016年间,女运动员的参赛人数有了明显的提升。从回归曲线(虚线)可以看出,在1996年及2016年,部分国家甚至派出了女性占大多数的参赛代表团。</p>
</section>
</section>
<section id="奖牌榜medal-count" class="level2" data-number="2.5">
<h2 data-number="2.5" class="anchored" data-anchor-id="奖牌榜medal-count"><span class="header-section-number">2.5</span> 奖牌榜(Medal Count)</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 按奖牌多少的顺序计算各国奖牌榜</span></span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>medalCount <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(<span class="sc">!</span><span class="fu">is.na</span>(Medal)) <span class="sc">%>%</span> </span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Sport <span class="sc">!=</span> <span class="st">"Art Competitions"</span>) <span class="sc">%>%</span> </span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Team, Medal) <span class="sc">%>%</span> </span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">Count =</span> <span class="fu">length</span>(Medal))</span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true" tabindex="-1"></a>medalCountLevs <span class="ot"><-</span> medalCount <span class="sc">%>%</span> </span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Team) <span class="sc">%>%</span> </span>
<span id="cb22-10"><a href="#cb22-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">Total =</span> <span class="fu">sum</span>(Count)) <span class="sc">%>%</span> </span>
<span id="cb22-11"><a href="#cb22-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">arrange</span>(Total) <span class="sc">%>%</span> </span>
<span id="cb22-12"><a href="#cb22-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(Team) <span class="sc">%>%</span> </span>
<span id="cb22-13"><a href="#cb22-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">tail</span>(<span class="dv">25</span>)</span>
<span id="cb22-14"><a href="#cb22-14" aria-hidden="true" tabindex="-1"></a>medalCount<span class="sc">$</span>Team <span class="ot"><-</span> <span class="fu">factor</span>(medalCount<span class="sc">$</span>Team, <span class="at">levels =</span> medalCountLevs<span class="sc">$</span>Team)</span>
<span id="cb22-15"><a href="#cb22-15" aria-hidden="true" tabindex="-1"></a>medalCount <span class="ot"><-</span> medalCount <span class="sc">%>%</span> </span>
<span id="cb22-16"><a href="#cb22-16" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Team <span class="sc">!=</span> <span class="st">"NA"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(medalCount, <span class="fu">aes</span>(<span class="at">x =</span> Team, <span class="at">y =</span> Count, <span class="at">fill =</span> Medal)) <span class="sc">+</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_col</span>() <span class="sc">+</span></span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">coord_flip</span>() <span class="sc">+</span></span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_fill_manual</span>(<span class="at">values =</span> <span class="fu">c</span>(<span class="st">"gold1"</span>, <span class="st">"gray70"</span>, <span class="st">"gold4"</span>)) <span class="sc">+</span></span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggtitle</span>(<span class="st">"Olympics Medal Tally"</span>) <span class="sc">+</span></span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="2-Olympic-history_files/figure-html/medal-1.png" class="img-fluid figure-img" width="672"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">(ref:fig-medal)</figcaption><p></p>
</figure>
</div>
</div>
</div>
<p>(ref:fig-medal) 各国历史奖牌榜前50名的国家</p>
<p>图@ref(fig:medal)显示,美国所获的奖牌数最多,而且远多于第二名的苏联。中国排在日本之后,排名第16位。进一步我们看一下中国的奖牌数变化。</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>medalChina <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(<span class="sc">!</span><span class="fu">is.na</span>(Medal)<span class="sc">&</span>Sport <span class="sc">!=</span> <span class="st">"Art Competitions"</span><span class="sc">&</span>Team <span class="sc">==</span> <span class="st">"China"</span>) <span class="sc">%>%</span> </span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Year, Medal) <span class="sc">%>%</span> </span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">Count =</span> <span class="fu">length</span>(Medal))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(medalChina, <span class="fu">aes</span>(<span class="at">x =</span> <span class="fu">reorder</span>(Year, <span class="sc">-</span>Count), <span class="at">y =</span> Count, <span class="at">fill =</span> Medal)) <span class="sc">+</span></span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_col</span>() <span class="sc">+</span></span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_fill_manual</span>(<span class="at">values =</span> <span class="fu">c</span>(<span class="st">"gold1"</span>, <span class="st">"gray70"</span>, <span class="st">"gold4"</span>)) <span class="sc">+</span></span>
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">xlab</span>(<span class="st">" "</span>) <span class="sc">+</span></span>
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">ylab</span>(<span class="st">"奖牌数"</span>) <span class="sc">+</span></span>
<span id="cb25-6"><a href="#cb25-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="2-Olympic-history_files/figure-html/china-medal-1.png" class="img-fluid figure-img" width="672"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">历届奥运会中国奖牌数量变化</figcaption><p></p>
</figure>
</div>
</div>
</div>
<p>图@ref(fig:china-medal)显示,2008年北京奥运会,中国获得奖牌数最多。1988年汉城奥运会,由于苏联、德国等国家重新参加比赛,竞争明显大于1984年奥运会,导致中国获得奖牌数最少,仅5枚金牌。</p>
</section>
<section id="地理信息地图" class="level2" data-number="2.6">
<h2 data-number="2.6" class="anchored" data-anchor-id="地理信息地图"><span class="header-section-number">2.6</span> 地理信息地图</h2>
<p>本部分我们聚焦夏季奥运会,在世界地图上呈现各国参加奥运会人数的变化情况。选取最近的一届2016年奥运会以及分别相隔44年的1972年慕尼黑奥运会和1928年阿姆斯特丹奥运会。</p>
<section id="年奥运会情况" class="level3" data-number="2.6.1">
<h3 data-number="2.6.1" class="anchored" data-anchor-id="年奥运会情况"><span class="header-section-number">2.6.1</span> 1928年奥运会情况</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 读取NOC数据</span></span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a>noc <span class="ot"><-</span> <span class="fu">read_csv</span>(<span class="st">"D:/Tools/Rwork/0.Study R/kaggle-project/data/olympics/noc_regions.csv"</span>,</span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a> <span class="at">col_types =</span> <span class="fu">cols</span>(</span>
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a> <span class="at">NOC =</span> <span class="fu">col_character</span>(),</span>
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a> <span class="at">region =</span> <span class="fu">col_character</span>()</span>
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a> ))</span>
<span id="cb26-7"><a href="#cb26-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-8"><a href="#cb26-8" aria-hidden="true" tabindex="-1"></a><span class="co"># 增加regions数据,去除缺失值</span></span>
<span id="cb26-9"><a href="#cb26-9" aria-hidden="true" tabindex="-1"></a>dataRegions <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb26-10"><a href="#cb26-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">left_join</span>(noc, <span class="at">by =</span> <span class="st">"NOC"</span>) <span class="sc">%>%</span> </span>
<span id="cb26-11"><a href="#cb26-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(<span class="sc">!</span><span class="fu">is.na</span>(region))</span>
<span id="cb26-12"><a href="#cb26-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-13"><a href="#cb26-13" aria-hidden="true" tabindex="-1"></a><span class="co"># 将选择的三届奥运会的数据筛选出来</span></span>
<span id="cb26-14"><a href="#cb26-14" aria-hidden="true" tabindex="-1"></a>amsterdam <span class="ot"><-</span> dataRegions <span class="sc">%>%</span> </span>
<span id="cb26-15"><a href="#cb26-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Games<span class="sc">==</span> <span class="st">"1928 Summer"</span>) <span class="sc">%>%</span> </span>
<span id="cb26-16"><a href="#cb26-16" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(region) <span class="sc">%>%</span> </span>
<span id="cb26-17"><a href="#cb26-17" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">Amsterdam =</span> <span class="fu">length</span>(<span class="fu">unique</span>(ID)))</span>
<span id="cb26-18"><a href="#cb26-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-19"><a href="#cb26-19" aria-hidden="true" tabindex="-1"></a>munich <span class="ot"><-</span> dataRegions <span class="sc">%>%</span> </span>
<span id="cb26-20"><a href="#cb26-20" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Games <span class="sc">==</span> <span class="st">"1972 Summer"</span>) <span class="sc">%>%</span> </span>
<span id="cb26-21"><a href="#cb26-21" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(region) <span class="sc">%>%</span> </span>
<span id="cb26-22"><a href="#cb26-22" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">Munich =</span> <span class="fu">length</span>(<span class="fu">unique</span>(ID)))</span>
<span id="cb26-23"><a href="#cb26-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-24"><a href="#cb26-24" aria-hidden="true" tabindex="-1"></a>rio <span class="ot"><-</span> dataRegions <span class="sc">%>%</span> </span>
<span id="cb26-25"><a href="#cb26-25" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Games <span class="sc">==</span> <span class="st">"2016 Summer"</span>) <span class="sc">%>%</span> </span>
<span id="cb26-26"><a href="#cb26-26" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(region) <span class="sc">%>%</span> </span>
<span id="cb26-27"><a href="#cb26-27" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">Rio =</span> <span class="fu">length</span>(<span class="fu">unique</span>(ID)))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 建立地图</span></span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a>world <span class="ot"><-</span> <span class="fu">map_data</span>(<span class="st">"world"</span>)</span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a>mapdat <span class="ot"><-</span> <span class="fu">tibble</span>(<span class="at">region =</span> <span class="fu">unique</span>(world<span class="sc">$</span>region)) <span class="co"># 提取国家列</span></span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a>mapdat <span class="ot"><-</span> mapdat <span class="sc">%>%</span> </span>
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">left_join</span>(amsterdam, <span class="at">by =</span> <span class="st">"region"</span>) <span class="sc">%>%</span> </span>
<span id="cb27-6"><a href="#cb27-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">left_join</span>(munich, <span class="at">by =</span> <span class="st">"region"</span>) <span class="sc">%>%</span> </span>
<span id="cb27-7"><a href="#cb27-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">left_join</span>(rio, <span class="at">by =</span> <span class="st">"region"</span>)</span>
<span id="cb27-8"><a href="#cb27-8" aria-hidden="true" tabindex="-1"></a>mapdat<span class="sc">$</span>Amsterdam[<span class="fu">is.na</span>(mapdat<span class="sc">$</span>Amsterdam)] <span class="ot"><-</span> <span class="dv">0</span></span>
<span id="cb27-9"><a href="#cb27-9" aria-hidden="true" tabindex="-1"></a>mapdat<span class="sc">$</span>Munich[<span class="fu">is.na</span>(mapdat<span class="sc">$</span>Munich)] <span class="ot"><-</span> <span class="dv">0</span></span>
<span id="cb27-10"><a href="#cb27-10" aria-hidden="true" tabindex="-1"></a>mapdat<span class="sc">$</span>Rio[<span class="fu">is.na</span>(mapdat<span class="sc">$</span>Rio)] <span class="ot"><-</span> <span class="dv">0</span></span>
<span id="cb27-11"><a href="#cb27-11" aria-hidden="true" tabindex="-1"></a>world <span class="ot"><-</span> <span class="fu">left_join</span>(world, mapdat, <span class="at">by =</span> <span class="st">"region"</span>)</span>
<span id="cb27-12"><a href="#cb27-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-13"><a href="#cb27-13" aria-hidden="true" tabindex="-1"></a><span class="co"># 1928</span></span>
<span id="cb27-14"><a href="#cb27-14" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(world, <span class="fu">aes</span>(<span class="at">x =</span> long, <span class="at">y =</span> lat, <span class="at">group =</span> group)) <span class="sc">+</span> </span>
<span id="cb27-15"><a href="#cb27-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_polygon</span>(<span class="fu">aes</span>(<span class="at">fill =</span> Amsterdam)) <span class="sc">+</span></span>
<span id="cb27-16"><a href="#cb27-16" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Amsterdam 1928"</span>,</span>
<span id="cb27-17"><a href="#cb27-17" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="cn">NULL</span>, <span class="at">y =</span> <span class="cn">NULL</span>) <span class="sc">+</span></span>
<span id="cb27-18"><a href="#cb27-18" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">axis.ticks =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb27-19"><a href="#cb27-19" aria-hidden="true" tabindex="-1"></a> <span class="at">axis.text =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb27-20"><a href="#cb27-20" aria-hidden="true" tabindex="-1"></a> <span class="at">panel.background =</span> <span class="fu">element_rect</span>(<span class="at">fill =</span> <span class="st">"navy"</span>), </span>
<span id="cb27-21"><a href="#cb27-21" aria-hidden="true" tabindex="-1"></a> <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>)) <span class="sc">+</span></span>
<span id="cb27-22"><a href="#cb27-22" aria-hidden="true" tabindex="-1"></a> <span class="fu">guides</span>(<span class="at">fill =</span> <span class="fu">guide_colorbar</span>(<span class="at">title =</span> <span class="st">"Athletes"</span>)) <span class="sc">+</span></span>
<span id="cb27-23"><a href="#cb27-23" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_fill_gradient</span>(<span class="at">low =</span> <span class="st">"white"</span>, <span class="at">high =</span> <span class="st">"red"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="2-Olympic-history_files/figure-html/1928-Arc-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="年奥运会情况-1" class="level3" data-number="2.6.2">
<h3 data-number="2.6.2" class="anchored" data-anchor-id="年奥运会情况-1"><span class="header-section-number">2.6.2</span> 1972年奥运会情况</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(world, <span class="fu">aes</span>(<span class="at">x =</span> long, <span class="at">y =</span> lat, <span class="at">group =</span> group)) <span class="sc">+</span></span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_polygon</span>(<span class="fu">aes</span>(<span class="at">fill =</span> Munich)) <span class="sc">+</span></span>
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Munich 1972"</span>,</span>
<span id="cb28-4"><a href="#cb28-4" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="cn">NULL</span>, <span class="at">y =</span> <span class="cn">NULL</span>) <span class="sc">+</span></span>
<span id="cb28-5"><a href="#cb28-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">axis.ticks =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb28-6"><a href="#cb28-6" aria-hidden="true" tabindex="-1"></a> <span class="at">axis.text =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb28-7"><a href="#cb28-7" aria-hidden="true" tabindex="-1"></a> <span class="at">panel.background =</span> <span class="fu">element_rect</span>(<span class="at">fill =</span> <span class="st">"navy"</span>),</span>
<span id="cb28-8"><a href="#cb28-8" aria-hidden="true" tabindex="-1"></a> <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>)) <span class="sc">+</span></span>
<span id="cb28-9"><a href="#cb28-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">guides</span>(<span class="at">fill =</span> <span class="fu">guide_colorbar</span>(<span class="at">title =</span> <span class="st">"Athletes"</span>)) <span class="sc">+</span></span>
<span id="cb28-10"><a href="#cb28-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_fill_gradient2</span>(<span class="at">low =</span> <span class="st">"white"</span>, <span class="at">high =</span> <span class="st">"red"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="2-Olympic-history_files/figure-html/1972-Arc-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="年奥运会情况-2" class="level3" data-number="2.6.3">
<h3 data-number="2.6.3" class="anchored" data-anchor-id="年奥运会情况-2"><span class="header-section-number">2.6.3</span> 2016年奥运会情况</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(world, <span class="fu">aes</span>(<span class="at">x =</span> long, <span class="at">y =</span> lat, <span class="at">group =</span> group)) <span class="sc">+</span></span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_polygon</span>(<span class="fu">aes</span>(<span class="at">fill =</span> Rio)) <span class="sc">+</span></span>
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Rio 2016"</span>, <span class="at">x =</span> <span class="cn">NULL</span>, <span class="at">y =</span> <span class="cn">NULL</span>) <span class="sc">+</span></span>
<span id="cb29-4"><a href="#cb29-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">axis.ticks =</span> <span class="fu">element_blank</span>(),</span>
<span id="cb29-5"><a href="#cb29-5" aria-hidden="true" tabindex="-1"></a> <span class="at">axis.text =</span><span class="fu">element_blank</span>(),</span>
<span id="cb29-6"><a href="#cb29-6" aria-hidden="true" tabindex="-1"></a> <span class="at">panel.background =</span> <span class="fu">element_rect</span>(<span class="at">fill =</span> <span class="st">"navy"</span>),</span>
<span id="cb29-7"><a href="#cb29-7" aria-hidden="true" tabindex="-1"></a> <span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>)) <span class="sc">+</span></span>
<span id="cb29-8"><a href="#cb29-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">guides</span>(<span class="at">fill =</span> <span class="fu">guide_colorbar</span>(<span class="at">title =</span> <span class="st">"Athletes"</span>)) <span class="sc">+</span></span>
<span id="cb29-9"><a href="#cb29-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_fill_gradient2</span>(<span class="at">low =</span> <span class="st">"white"</span>, <span class="at">high =</span> <span class="st">"red"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="2-Olympic-history_files/figure-html/2016-Arc-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
</section>
<section id="参赛运动员身高体重" class="level2" data-number="2.7">
<h2 data-number="2.7" class="anchored" data-anchor-id="参赛运动员身高体重"><span class="header-section-number">2.7</span> 参赛运动员身高体重</h2>
<p>更高、更快、更强是奥运会的座右铭,而每届奥运会的参赛运动员似乎也比之前奥运会更快更强。要验证这个观点,我们需要通过本数据探索历届奥运会运动员身高及体重的变化趋势。</p>
<section id="数据完整性及可用性检测" class="level3" data-number="2.7.1">
<h3 data-number="2.7.1" class="anchored" data-anchor-id="数据完整性及可用性检测"><span class="header-section-number">2.7.1</span> 数据完整性及可用性检测</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a>data <span class="sc">%>%</span> <span class="fu">group_by</span>(Year, Sex) <span class="sc">%>%</span> </span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">Present =</span> <span class="fu">length</span>(<span class="fu">unique</span>(ID[<span class="fu">which</span>(<span class="sc">!</span><span class="fu">is.na</span>(Height)<span class="sc">&!</span><span class="fu">is.na</span>(Weight))])),</span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a> <span class="at">Total =</span> <span class="fu">length</span>(<span class="fu">unique</span>(ID))) <span class="sc">%>%</span> </span>
<span id="cb30-4"><a href="#cb30-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Proportion =</span> Present<span class="sc">/</span>Total) <span class="sc">%>%</span> </span>
<span id="cb30-5"><a href="#cb30-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> Year, <span class="at">y =</span> Proportion, <span class="at">group =</span> Sex, <span class="at">color =</span> Sex)) <span class="sc">+</span></span>
<span id="cb30-6"><a href="#cb30-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb30-7"><a href="#cb30-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>() <span class="sc">+</span></span>
<span id="cb30-8"><a href="#cb30-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_color_manual</span>(<span class="at">values =</span> <span class="fu">c</span>(<span class="st">"darkblue"</span>, <span class="st">"red"</span>)) <span class="sc">+</span></span>
<span id="cb30-9"><a href="#cb30-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">plot.title =</span> <span class="fu">element_text</span>(<span class="at">hjust =</span> <span class="fl">0.5</span>),</span>
<span id="cb30-10"><a href="#cb30-10" aria-hidden="true" tabindex="-1"></a> <span class="at">axis.text.x =</span> <span class="fu">element_text</span>(<span class="at">face =</span> <span class="st">"bold"</span>, <span class="at">angle =</span> <span class="dv">90</span>)) <span class="sc">+</span></span>
<span id="cb30-11"><a href="#cb30-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Height/Weight data completeness from each Olympics"</span>) <span class="sc">+</span></span>
<span id="cb30-12"><a href="#cb30-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">1896</span>, <span class="dv">2016</span>, <span class="dv">4</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="2-Olympic-history_files/figure-html/data-completeness-1.png" class="img-fluid figure-img" width="672"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">Height/Weight data completeness from each Olympics</figcaption><p></p>
</figure>
</div>
</div>
</div>
<p>图@ref(fig:data-completeness)所示,1960年,数据的完整性有一个巨大的飞跃,且从本届奥运会开始,数据的完整性均超过了85%(除1992年外)。鉴于此,我们选取从1960年开始的数据,共包括56年间的15届奥运会。</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb31"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a>data <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(<span class="sc">!</span><span class="fu">is.na</span>(Height), <span class="sc">!</span><span class="fu">is.na</span>(Weight), Year<span class="sc">></span> <span class="dv">1959</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="身高体重" class="level3" data-number="2.7.2">
<h3 data-number="2.7.2" class="anchored" data-anchor-id="身高体重"><span class="header-section-number">2.7.2</span> 身高体重</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb32"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a>pHeight <span class="ot"><-</span> <span class="fu">ggplot</span>(data, <span class="fu">aes</span>(<span class="at">x =</span> <span class="fu">as.factor</span>(Year), <span class="at">y =</span> Height, <span class="at">fill =</span> Sex)) <span class="sc">+</span></span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_boxplot</span>(<span class="at">alpha =</span> <span class="fl">0.75</span>) <span class="sc">+</span></span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">xlab</span>(<span class="st">"Olympiad Year"</span>) <span class="sc">+</span> <span class="fu">ylab</span>(<span class="st">"Height(cm)"</span>) <span class="sc">+</span></span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_fill_manual</span>(<span class="at">values =</span> <span class="fu">c</span>(<span class="st">"blue"</span>, <span class="st">"red"</span>))</span>
<span id="cb32-5"><a href="#cb32-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb32-6"><a href="#cb32-6" aria-hidden="true" tabindex="-1"></a>pWeight <span class="ot"><-</span> <span class="fu">ggplot</span>(data, <span class="fu">aes</span>(<span class="at">x =</span> <span class="fu">as.factor</span>(Year), <span class="at">y =</span> Weight, <span class="at">fill =</span> Sex)) <span class="sc">+</span></span>
<span id="cb32-7"><a href="#cb32-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_boxplot</span>(<span class="at">alpha =</span> <span class="fl">0.75</span>) <span class="sc">+</span></span>
<span id="cb32-8"><a href="#cb32-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">xlab</span>(<span class="st">"Olympiad Year"</span>) <span class="sc">+</span> <span class="fu">ylab</span>(<span class="st">"Weight(kg)"</span>) <span class="sc">+</span></span>
<span id="cb32-9"><a href="#cb32-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_fill_manual</span>(<span class="at">values =</span> <span class="fu">c</span>(<span class="st">"blue"</span>, <span class="st">"red"</span>))</span>
<span id="cb32-10"><a href="#cb32-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb32-11"><a href="#cb32-11" aria-hidden="true" tabindex="-1"></a><span class="fu">grid.arrange</span>(pHeight, pWeight,<span class="at">ncol =</span> <span class="dv">1</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="2-Olympic-history_files/figure-html/WH-overtime-1.png" class="img-fluid figure-img" width="672"></p>
<p></p><figcaption aria-hidden="true" class="figure-caption">Athlete height & weight over time</figcaption><p></p>
</figure>
</div>
</div>
</div>
<p>图@ref(fig:WH-overtime)显示,运动员身高体重(包括男女)均呈现稳步上升的趋势。但是,由于不同运动项目要求体型不同,图@ref(fig:WH-overtime)可能隐藏了一些重要的变化规律。因此,必须进一步深入探索不同项目中身高体重数据变化的趋势。然而,在奥运会的历史上,运动项目是不断变化的,首先,必须筛选出1960~2016年间奥运会都设立的比赛项目。</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 筛选1960年奥运会的项目</span></span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a>events <span class="ot"><-</span> data[data<span class="sc">$</span>Year <span class="sc">==</span> <span class="dv">1960</span>, <span class="st">"Event"</span>] <span class="sc">%>%</span> </span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a> unique <span class="sc">%>%</span> </span>
<span id="cb33-4"><a href="#cb33-4" aria-hidden="true" tabindex="-1"></a> .<span class="sc">$</span>Event </span>
<span id="cb33-5"><a href="#cb33-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-6"><a href="#cb33-6" aria-hidden="true" tabindex="-1"></a>years <span class="ot"><-</span> data<span class="sc">$</span>Year <span class="sc">%>%</span> </span>
<span id="cb33-7"><a href="#cb33-7" aria-hidden="true" tabindex="-1"></a> unique <span class="sc">%>%</span> </span>
<span id="cb33-8"><a href="#cb33-8" aria-hidden="true" tabindex="-1"></a> sort <span class="sc">%>%</span> <span class="fu">tail</span>(<span class="sc">-</span><span class="dv">1</span>)</span>
<span id="cb33-9"><a href="#cb33-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-10"><a href="#cb33-10" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(years)) {</span>
<span id="cb33-11"><a href="#cb33-11" aria-hidden="true" tabindex="-1"></a> nxt <span class="ot"><-</span> data[data<span class="sc">$</span>Year <span class="sc">==</span> years[i], <span class="st">"Event"</span>] <span class="sc">%>%</span> </span>
<span id="cb33-12"><a href="#cb33-12" aria-hidden="true" tabindex="-1"></a> unique <span class="sc">%>%</span> .<span class="sc">$</span>Event</span>
<span id="cb33-13"><a href="#cb33-13" aria-hidden="true" tabindex="-1"></a> events <span class="ot"><-</span> <span class="fu">intersect</span>(events, nxt)</span>
<span id="cb33-14"><a href="#cb33-14" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb33-15"><a href="#cb33-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-16"><a href="#cb33-16" aria-hidden="true" tabindex="-1"></a><span class="co"># 按照1960年项目对之后的项目进行筛选</span></span>
<span id="cb33-17"><a href="#cb33-17" aria-hidden="true" tabindex="-1"></a>data <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb33-18"><a href="#cb33-18" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(Event <span class="sc">%in%</span> events)</span>
<span id="cb33-19"><a href="#cb33-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-20"><a href="#cb33-20" aria-hidden="true" tabindex="-1"></a><span class="co"># get list of sports matching events</span></span>
<span id="cb33-21"><a href="#cb33-21" aria-hidden="true" tabindex="-1"></a>sportsEvents <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb33-22"><a href="#cb33-22" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(Sport, Event) <span class="sc">%>%</span> </span>
<span id="cb33-23"><a href="#cb33-23" aria-hidden="true" tabindex="-1"></a> unique</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="change-in-weight-vs-change-in-height-over-times-across-mens-sports" class="level3" data-number="2.7.3">
<h3 data-number="2.7.3" class="anchored" data-anchor-id="change-in-weight-vs-change-in-height-over-times-across-mens-sports"><span class="header-section-number">2.7.3</span> change in Weight VS change in Height over times across men’s sports</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 剔除摔跤、举重、拳击、马术</span></span>
<span id="cb34-2"><a href="#cb34-2" aria-hidden="true" tabindex="-1"></a>sportsEvents <span class="ot"><-</span> sportsEvents <span class="sc">%>%</span> </span>
<span id="cb34-3"><a href="#cb34-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(<span class="sc">!</span>Sport <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"Wrestling"</span>, <span class="st">"Weightlifting"</span>, <span class="st">"Boxing"</span>, <span class="st">"Equestrianism"</span>)) <span class="sc">%>%</span> </span>
<span id="cb34-4"><a href="#cb34-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(<span class="sc">!</span>Event <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"Figure Skating Mixed Pairs"</span>)) <span class="sc">%>%</span> </span>
<span id="cb34-5"><a href="#cb34-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">arrange</span>(Sport)</span>
<span id="cb34-6"><a href="#cb34-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-7"><a href="#cb34-7" aria-hidden="true" tabindex="-1"></a><span class="co"># 增加一列 men/women/mixed 区分男女项目</span></span>
<span id="cb34-8"><a href="#cb34-8" aria-hidden="true" tabindex="-1"></a>sportsEvents<span class="sc">$</span>Sex <span class="ot"><-</span> <span class="fu">ifelse</span>(<span class="fu">grepl</span>(<span class="st">"Women"</span>, sportsEvents<span class="sc">$</span>Event), <span class="st">"Women"</span>, <span class="st">"Men"</span>)</span>
<span id="cb34-9"><a href="#cb34-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-10"><a href="#cb34-10" aria-hidden="true" tabindex="-1"></a><span class="co"># 创建循环,进行回归</span></span>
<span id="cb34-11"><a href="#cb34-11" aria-hidden="true" tabindex="-1"></a>s.height <span class="ot"><-</span> s.weight <span class="ot"><-</span> <span class="fu">c</span>()</span>
<span id="cb34-12"><a href="#cb34-12" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">nrow</span>(sportsEvents)) {</span>
<span id="cb34-13"><a href="#cb34-13" aria-hidden="true" tabindex="-1"></a> temp <span class="ot"><-</span> data <span class="sc">%>%</span> <span class="fu">filter</span>(Event <span class="sc">==</span> sportsEvents<span class="sc">$</span>Event[i])</span>
<span id="cb34-14"><a href="#cb34-14" aria-hidden="true" tabindex="-1"></a> lm.height <span class="ot"><-</span> <span class="fu">lm</span>(Height <span class="sc">~</span> Year, <span class="at">data =</span> temp)</span>
<span id="cb34-15"><a href="#cb34-15" aria-hidden="true" tabindex="-1"></a> lm.weight <span class="ot"><-</span> <span class="fu">lm</span>(Weight <span class="sc">~</span> Year, <span class="at">data =</span> temp)</span>
<span id="cb34-16"><a href="#cb34-16" aria-hidden="true" tabindex="-1"></a> s.height[i] <span class="ot"><-</span> lm.height<span class="sc">$</span>coefficients[<span class="st">"Year"</span>]</span>
<span id="cb34-17"><a href="#cb34-17" aria-hidden="true" tabindex="-1"></a> s.weight[i] <span class="ot"><-</span> lm.weight<span class="sc">$</span>coefficients[<span class="st">"Year"</span>]</span>
<span id="cb34-18"><a href="#cb34-18" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb34-19"><a href="#cb34-19" aria-hidden="true" tabindex="-1"></a>slopes <span class="ot"><-</span> <span class="fu">tibble</span>(<span class="at">Sport =</span> sportsEvents<span class="sc">$</span>Sport,</span>
<span id="cb34-20"><a href="#cb34-20" aria-hidden="true" tabindex="-1"></a> <span class="at">Event =</span> sportsEvents<span class="sc">$</span>Event,</span>
<span id="cb34-21"><a href="#cb34-21" aria-hidden="true" tabindex="-1"></a> <span class="at">Sex =</span> sportsEvents<span class="sc">$</span>Sex,</span>
<span id="cb34-22"><a href="#cb34-22" aria-hidden="true" tabindex="-1"></a> <span class="at">Height =</span> s.height,</span>
<span id="cb34-23"><a href="#cb34-23" aria-hidden="true" tabindex="-1"></a> <span class="at">Weight =</span> s.weight)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const clipboard = new window.ClipboardJS('.code-copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
setTimeout(function() {
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
let href = ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const cites = ref.parentNode.getAttribute('data-cites').split(' ');
tippyHover(ref, function() {
var popup = window.document.createElement('div');
cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');