-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_visualizations_answers.html
More file actions
1900 lines (1764 loc) · 132 KB
/
Copy path2_visualizations_answers.html
File metadata and controls
1900 lines (1764 loc) · 132 KB
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 lang="en"><head>
<script src="2_visualizations_files/libs/clipboard/clipboard.min.js"></script>
<script src="2_visualizations_files/libs/quarto-html/tabby.min.js"></script>
<script src="2_visualizations_files/libs/quarto-html/popper.min.js"></script>
<script src="2_visualizations_files/libs/quarto-html/tippy.umd.min.js"></script>
<link href="2_visualizations_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="2_visualizations_files/libs/quarto-html/light-border.css" rel="stylesheet">
<link href="2_visualizations_files/libs/quarto-html/quarto-syntax-highlighting-e26003cea8cd680ca0c55a263523d882.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<link href="2_visualizations_files/libs/quarto-contrib/fontawesome6-0.1.0/all.css" rel="stylesheet">
<link href="2_visualizations_files/libs/quarto-contrib/fontawesome6-0.1.0/latex-fontsize.css" rel="stylesheet"><meta charset="utf-8">
<meta name="generator" content="quarto-1.6.39">
<meta name="dcterms.date" content="2026-02-19">
<title>Visualizing Data in R</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="2_visualizations_files/libs/revealjs/dist/reset.css">
<link rel="stylesheet" href="2_visualizations_files/libs/revealjs/dist/reveal.css">
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { 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 { display: inline-block; 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
{ color: #003b4f; background-color: #f1f3f5; }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span { color: #003b4f; } /* Normal */
code span.al { color: #ad0000; } /* Alert */
code span.an { color: #5e5e5e; } /* Annotation */
code span.at { color: #657422; } /* Attribute */
code span.bn { color: #ad0000; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #003b4f; font-weight: bold; } /* ControlFlow */
code span.ch { color: #20794d; } /* Char */
code span.cn { color: #8f5902; } /* Constant */
code span.co { color: #5e5e5e; } /* Comment */
code span.cv { color: #5e5e5e; font-style: italic; } /* CommentVar */
code span.do { color: #5e5e5e; font-style: italic; } /* Documentation */
code span.dt { color: #ad0000; } /* DataType */
code span.dv { color: #ad0000; } /* DecVal */
code span.er { color: #ad0000; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #ad0000; } /* Float */
code span.fu { color: #4758ab; } /* Function */
code span.im { color: #00769e; } /* Import */
code span.in { color: #5e5e5e; } /* Information */
code span.kw { color: #003b4f; font-weight: bold; } /* Keyword */
code span.op { color: #5e5e5e; } /* Operator */
code span.ot { color: #003b4f; } /* Other */
code span.pp { color: #ad0000; } /* Preprocessor */
code span.sc { color: #5e5e5e; } /* SpecialChar */
code span.ss { color: #20794d; } /* SpecialString */
code span.st { color: #20794d; } /* String */
code span.va { color: #111111; } /* Variable */
code span.vs { color: #20794d; } /* VerbatimString */
code span.wa { color: #5e5e5e; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="2_visualizations_files/libs/revealjs/dist/theme/quarto-560a7fb8c8fb23736e113fee4ef09eaa.css">
<link href="2_visualizations_files/libs/revealjs/plugin/quarto-line-highlight/line-highlight.css" rel="stylesheet">
<link href="2_visualizations_files/libs/revealjs/plugin/reveal-menu/menu.css" rel="stylesheet">
<link href="2_visualizations_files/libs/revealjs/plugin/reveal-menu/quarto-menu.css" rel="stylesheet">
<link href="2_visualizations_files/libs/revealjs/plugin/quarto-support/footer.css" rel="stylesheet">
<style type="text/css">
.reveal div.sourceCode {
margin: 0;
overflow: auto;
}
.reveal div.hanging-indent {
margin-left: 1em;
text-indent: -1em;
}
.reveal .slide:not(.center) {
height: 100%;
}
.reveal .slide.scrollable {
overflow-y: auto;
}
.reveal .footnotes {
height: 100%;
overflow-y: auto;
}
.reveal .slide .absolute {
position: absolute;
display: block;
}
.reveal .footnotes ol {
counter-reset: ol;
list-style-type: none;
margin-left: 0;
}
.reveal .footnotes ol li:before {
counter-increment: ol;
content: counter(ol) ". ";
}
.reveal .footnotes ol li > p:first-child {
display: inline-block;
}
.reveal .slide ul,
.reveal .slide ol {
margin-bottom: 0.5em;
}
.reveal .slide ul li,
.reveal .slide ol li {
margin-top: 0.4em;
margin-bottom: 0.2em;
}
.reveal .slide ul[role="tablist"] li {
margin-bottom: 0;
}
.reveal .slide ul li > *:first-child,
.reveal .slide ol li > *:first-child {
margin-block-start: 0;
}
.reveal .slide ul li > *:last-child,
.reveal .slide ol li > *:last-child {
margin-block-end: 0;
}
.reveal .slide .columns:nth-child(3) {
margin-block-start: 0.8em;
}
.reveal blockquote {
box-shadow: none;
}
.reveal .tippy-content>* {
margin-top: 0.2em;
margin-bottom: 0.7em;
}
.reveal .tippy-content>*:last-child {
margin-bottom: 0.2em;
}
.reveal .slide > img.stretch.quarto-figure-center,
.reveal .slide > img.r-stretch.quarto-figure-center {
display: block;
margin-left: auto;
margin-right: auto;
}
.reveal .slide > img.stretch.quarto-figure-left,
.reveal .slide > img.r-stretch.quarto-figure-left {
display: block;
margin-left: 0;
margin-right: auto;
}
.reveal .slide > img.stretch.quarto-figure-right,
.reveal .slide > img.r-stretch.quarto-figure-right {
display: block;
margin-left: auto;
margin-right: 0;
}
</style>
</head>
<body class="quarto-light">
<div class="reveal">
<div class="slides">
<section id="title-slide" data-background-image="figures/viz_fig.png" data-background-position="95% 50%" data-background-size="55%" class="center">
<p class="absolute" style="top:0">Workshop: Dealing with Data in R</p>
<h1 class="title" style="padding-top: 150px;">Visualizing Data in R</h1>
<h3 class="subtitle" style="padding-top:5px;"><strong>A primer on <code>ggplot2</code></strong></h3>
<p style="font-size:70%; padding-top: 120px">
<i class="fa-brands fa-github"></i> <a href="https://github.com/steffilazerte">steffilazerte</a><br>
<i class="fa-brands fa-mastodon"></i> <a href="https://fosstodon.org/@steffilazerte">@steffilazerte@fosstodon.org</a><br>
<i class="fa-brands fa-twitter"></i> <a href="https://twitter.com/steffilazerte">@steffilazerte</a><br>
<i class="fa-solid fa-globe"></i> <a href="https://steffilazerte.ca">steffilazerte.ca</a><br>
<img src="figures/steffi_logo.png" width="30%">
</p>
<p class="date">Compiled: 2026-02-19</p>
</section>
<section>
<section id="first-things-first" class="title-slide slide level1 center">
<h1>First things first</h1>
<div style="text-align:left; padding: 15px 200px 15px 200px">
<p><i class="fa-solid fa-floppy-disk" aria-label="floppy-disk"></i> Save previous script</p>
<p><i class="fa-solid fa-folder-open" aria-label="folder-open"></i> Open New File <br> <span class="small hang">(make sure you’re in the RStudio Project)</span></p>
<p><i class="fa-solid fa-pen" aria-label="pen"></i> Write <code>library(tidyverse)</code> at the top</p>
<p><i class="fa-solid fa-floppy-disk" aria-label="floppy-disk"></i> Save this new script <br> <span class="small hang">(consider names like <code>figs.R</code> or <code>2_figures.R</code>)</span></p>
</div>
</section>
<section id="outline" class="slide level2">
<h2>Outline</h2>
<h3 id="figures-with-ggplot2-a-tidyverse-package">1. Figures with <code>ggplot2</code> <span class="small">(A <code>tidyverse</code> package)</span></h3>
<ul>
<li>Basic plot</li>
<li>Common plot types</li>
<li>Plotting by categories</li>
<li>Adding statistics</li>
<li>Customizing plots</li>
<li>Annotating plots</li>
</ul>
<p><img data-src="figures/hex_ggplot2.png" class="absolute" style="top: 0px; right: 0px; width: 20%; " alt="Hex logo for ggplot2 R package"></p>
<h3 id="combining-figures-with-patchwork">2. Combining figures with <code>patchwork</code></h3>
<h3 id="saving-figures">3. Saving figures</h3>
<p><img data-src="figures/hex_patchwork.png" class="absolute" style="bottom: 30px; right: 0px; width: 20%; " alt="Hex logo for patchwork R package"></p>
</section>
<section id="section" class="slide level2" data-menu-title="ggplot2" data-background-image="figures/horst_ggplot2.png" data-background-size="75%" data-background-position="top" title="A fuzzy monster in a beret and scarf, critiquing their own column graph on a canvas in front of them while other assistant monsters (also in berets) carry over boxes full of elements that can be used to customize a graph (like themes and geometric shapes). In the background is a wall with framed data visualizations. Stylized text reads "ggplot2: build a data masterpiece."">
<h2></h2>
<p><span class="footnote">Artwork by <a href="https://github.com/allisonhorst/stats-illustrations"><span class="citation" data-cites="allison_horst">@allison_horst</span></a></span></p>
</section>
<section id="our-data-set-palmer-penguins" class="slide level2">
<h2>Our data set: Palmer Penguins!</h2>
<p><img data-src="figures/horst_lter_penguins.png" style="width:80.0%" alt="Cartoons of three penguins labelled 'Chinstrap!', 'Gentoo!', and 'Adelie!'"> <img data-src="figures/hex_palmerpenguins.png" class="absolute" style="top: 0px; right: 0px; width: 20%; " alt="Hex logo for palmerpenguins R package"></p>
<p><span class="footnote">Artwork by <a href="https://github.com/allisonhorst/stats-illustrations">@allison_horst</a></span></p>
</section>
<section id="our-data-set-palmer-penguins-1" class="slide level2">
<h2>Our data set: Palmer Penguins!</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href=""></a><span class="fu">library</span>(palmerpenguins)</span>
<span id="cb1-2"><a href=""></a>penguins</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: 344 × 8
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
<fct> <fct> <dbl> <dbl> <int> <int>
1 Adelie Torgersen 39.1 18.7 181 3750
2 Adelie Torgersen 39.5 17.4 186 3800
3 Adelie Torgersen 40.3 18 195 3250
4 Adelie Torgersen NA NA NA NA
5 Adelie Torgersen 36.7 19.3 193 3450
6 Adelie Torgersen 39.3 20.6 190 3650
7 Adelie Torgersen 38.9 17.8 181 3625
8 Adelie Torgersen 39.2 19.6 195 4675
9 Adelie Torgersen 34.1 18.1 193 3475
10 Adelie Torgersen 42 20.2 190 4250
# ℹ 334 more rows
# ℹ 2 more variables: sex <fct>, year <int></code></pre>
</div>
</div>
<p><img data-src="figures/hex_palmerpenguins.png" class="absolute" style="top: 0px; right: 0px; width: 12%; " alt="Hex logo for palmerpenguins R package"></p>
<p><span class="footnote">Artwork by <a href="https://github.com/allisonhorst/stats-illustrations">@allison_horst</a></span></p>
<div class="columns">
<div class="column" style="width:30%;">
<p><img data-src="figures/horst_lter_penguins.png" alt="Cartoons of three penguins labelled 'Chinstrap!', 'Gentoo!', and 'Adelie!'"></p>
</div><div class="column fragment" style="width:70%;">
<blockquote>
<p><strong>Your turn!</strong></p>
<p>Run this code and look at the output in the console</p>
</blockquote>
</div></div>
</section>
<section id="side-note" class="slide level2">
<h2>Side Note</h2>
<h3 id="where-did-the-penguins-data-set-come-from">Where did the <code>penguins</code> data set come from?</h3>
<ul>
<li>Sometimes R packages contain data</li>
<li>If you load a package (i.e. <code>library(palmerpenguins)</code>) you can use the data</li>
<li><strong>Note</strong> that here the data object is called <code>penguins</code> (not <code>palmerpenguins</code>)</li>
<li><strong>Note</strong> this is NOT how you’ll load your own data</li>
</ul>
</section>
<section id="a-basic-plot" class="slide level2">
<h2>A basic plot</h2>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href=""></a><span class="fu">library</span>(palmerpenguins)</span>
<span id="cb3-2"><a href=""></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb3-3"><a href=""></a></span>
<span id="cb3-4"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm)) <span class="sc">+</span></span>
<span id="cb3-5"><a href=""></a> <span class="fu">geom_point</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/basic_plot-1.png" class="quarto-figure quarto-figure-center r-stretch" style="width:70.0%"></section>
<section id="break-it-down" class="slide level2">
<h2>Break it down</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb4" data-code-line-numbers="1,2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href=""></a><span class="fu">library</span>(palmerpenguins)</span>
<span id="cb4-2"><a href=""></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb4-3"><a href=""></a></span>
<span id="cb4-4"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm)) <span class="sc">+</span></span>
<span id="cb4-5"><a href=""></a> <span class="fu">geom_point</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="columns">
<div class="column" style="width:50%;">
<h3 id="library"><code>library()</code></h3>
<ul>
<li>Load the <code>palmerguins</code> package</li>
<li>Now we have access to <code>penguins</code> data</li>
</ul>
</div><div class="column" style="width:50%;">
<div class="cell">
<div class="cell-output-display">
<div>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-3-1.png" width="1200"></p>
</figure>
</div>
</div>
</div>
</div></div>
</section>
<section id="break-it-down-1" class="slide level2">
<h2>Break it down</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb5" data-code-line-numbers="1,2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href=""></a><span class="fu">library</span>(palmerpenguins)</span>
<span id="cb5-2"><a href=""></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb5-3"><a href=""></a></span>
<span id="cb5-4"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm)) <span class="sc">+</span></span>
<span id="cb5-5"><a href=""></a> <span class="fu">geom_point</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="columns">
<div class="column" style="width:50%;">
<h3 id="library-1"><code>library()</code></h3>
<ul>
<li>Load the <code>tidyverse</code> packages<br>
<span class="small">(includes <code>ggplot2</code>)</span></li>
<li>Now we have access to the <code>ggplot()</code> function <span class="small">(and <code>aes()</code> and <code>geom_point()</code> etc.)</span></li>
</ul>
</div><div class="column" style="width:50%;">
<div class="cell">
<div class="cell-output-display">
<div>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-5-1.png" width="1200"></p>
</figure>
</div>
</div>
</div>
</div></div>
</section>
<section id="break-it-down-2" class="slide level2">
<h2>Break it down</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb6" data-code-line-numbers="4"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href=""></a><span class="fu">library</span>(palmerpenguins)</span>
<span id="cb6-2"><a href=""></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb6-3"><a href=""></a></span>
<span id="cb6-4"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm)) <span class="sc">+</span></span>
<span id="cb6-5"><a href=""></a> <span class="fu">geom_point</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="columns">
<div class="column" style="width:50%;">
<h3 id="ggplot"><code>ggplot()</code></h3>
<ul>
<li>Set the attributes of your plot</li>
<li><strong><code>data</code></strong> = Dataset</li>
<li><strong><code>aes</code></strong> = Aesthetics (how the data are used)</li>
<li>Think of this as your plot defaults</li>
</ul>
</div><div class="column" style="width:50%;">
<div class="cell">
<div class="cell-output-display">
<div>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-7-1.png" width="1200"></p>
</figure>
</div>
</div>
</div>
</div></div>
</section>
<section id="break-it-down-3" class="slide level2">
<h2>Break it down</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb7" data-code-line-numbers="5"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href=""></a><span class="fu">library</span>(palmerpenguins)</span>
<span id="cb7-2"><a href=""></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb7-3"><a href=""></a></span>
<span id="cb7-4"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm)) <span class="sc">+</span></span>
<span id="cb7-5"><a href=""></a> <span class="fu">geom_point</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="columns">
<div class="column" style="width:50%;">
<h3 id="geom_point"><code>geom_point()</code></h3>
<ul>
<li>Choose a <code>geom</code> function to display the data</li>
<li>Always <em>added</em> to a <code>ggplot()</code> call with <code>+</code></li>
</ul>
<blockquote>
<p>ggplots are essentially layered objects, starting with a call to <code>ggplot()</code></p>
</blockquote>
</div><div class="column" style="width:50%;">
<div class="cell">
<div class="cell-output-display">
<div>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-9-1.png" width="1200"></p>
</figure>
</div>
</div>
</div>
</div></div>
</section>
<section id="plots-are-layered" class="slide level2">
<h2>Plots are layered</h2>
<div class="columns">
<div class="column small" style="width:50%;">
<div class="cell">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> body_mass_g))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-10-1.png" style="padding-top:0.75em" width="1000"></p>
</figure>
</div>
</div>
</div>
</div><div class="column small" style="width:50%;">
<div class="r-stack">
<div class="cell">
<div class="sourceCode cell-code" id="cb9" data-code-line-numbers="2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> body_mass_g)) <span class="sc">+</span></span>
<span id="cb9-2"><a href=""></a> <span class="fu">geom_boxplot</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>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-11-1.png" width="1000"></p>
</figure>
</div>
</div>
</div>
<div class="fragment">
<div class="cell">
<div class="sourceCode cell-code" id="cb10" data-code-line-numbers="2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> body_mass_g)) <span class="sc">+</span></span>
<span id="cb10-2"><a href=""></a> <span class="fu">geom_point</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>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-12-1.png" width="1000"></p>
</figure>
</div>
</div>
</div>
</div>
<div class="fragment">
<div class="cell">
<div class="sourceCode cell-code" id="cb11" data-code-line-numbers="2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> body_mass_g)) <span class="sc">+</span></span>
<span id="cb11-2"><a href=""></a> <span class="fu">geom_violin</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>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-13-1.png" width="1000"></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div></div>
</section>
<section id="plots-are-layered-1" class="slide level2">
<h2>Plots are layered</h2>
<div class="columns">
<div class="column" style="width:50%;">
<h3 id="you-can-add-multiple-layers">You can add multiple layers</h3>
<div class="r-stack small">
<div class="cell">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> body_mass_g)) <span class="sc">+</span></span>
<span id="cb12-2"><a href=""></a> <span class="fu">geom_boxplot</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>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-14-1.png" width="1000"></p>
</figure>
</div>
</div>
</div>
<div class="fragment">
<div class="cell">
<div class="sourceCode cell-code" id="cb13" data-code-line-numbers="3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> body_mass_g)) <span class="sc">+</span></span>
<span id="cb13-2"><a href=""></a> <span class="fu">geom_boxplot</span>() <span class="sc">+</span></span>
<span id="cb13-3"><a href=""></a> <span class="fu">geom_point</span>(<span class="at">size =</span> <span class="dv">2</span>, <span class="at">colour =</span> <span class="st">"red"</span>, </span>
<span id="cb13-4"><a href=""></a> <span class="at">position =</span> <span class="fu">position_jitter</span>(<span class="at">width =</span> <span class="fl">0.05</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>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-15-1.png" width="1000"></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div><div class="column fragment">
<h3 id="order-matters">Order matters</h3>
<div class="small">
<div class="cell">
<div class="sourceCode cell-code" id="cb14" data-code-line-numbers="2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> body_mass_g)) <span class="sc">+</span></span>
<span id="cb14-2"><a href=""></a> <span class="fu">geom_point</span>(<span class="at">size =</span> <span class="dv">2</span>, <span class="at">colour =</span> <span class="st">"red"</span>,</span>
<span id="cb14-3"><a href=""></a> <span class="at">position =</span> <span class="fu">position_jitter</span>(<span class="at">width =</span> <span class="fl">0.05</span>)) <span class="sc">+</span></span>
<span id="cb14-4"><a href=""></a> <span class="fu">geom_boxplot</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>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-16-1.png" width="1000"></p>
</figure>
</div>
</div>
</div>
</div>
</div></div>
</section>
<section id="plots-are-objects" class="slide level2">
<h2>Plots are objects</h2>
<h3 id="any-ggplot-can-be-saved-as-an-object">Any ggplot can be saved as an object</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href=""></a>g <span class="ot"><-</span> <span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> body_mass_g))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="columns">
<div class="column fragment" style="width:50%;">
<div class="cell">
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href=""></a>g</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-18-1.png" width="1000"></p>
</figure>
</div>
</div>
</div>
</div><div class="column fragment" style="width:50%;">
<div class="cell">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href=""></a>g <span class="sc">+</span> <span class="fu">geom_boxplot</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>
<figure>
<p><img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-19-1.png" width="1000"></p>
</figure>
</div>
</div>
</div>
</div></div>
</section></section>
<section>
<section id="more-geoms" class="title-slide slide level1 center">
<h1>More Geoms</h1>
<p><strong>(Plot types)</strong></p>
</section>
<section id="geoms-lines" class="slide level2">
<h2>Geoms: Lines</h2>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb18" data-code-line-numbers="2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb18-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm)) <span class="sc">+</span></span>
<span id="cb18-2"><a href=""></a> <span class="fu">geom_line</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-20-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1600"></section>
<section id="geoms-boxplots" class="slide level2">
<h2>Geoms: Boxplots</h2>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb19" data-code-line-numbers="2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> species, <span class="at">y =</span> flipper_length_mm)) <span class="sc">+</span></span>
<span id="cb19-2"><a href=""></a> <span class="fu">geom_boxplot</span>() </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-21-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1600"></section>
<section id="geoms-histogram" class="slide level2">
<h2>Geoms: Histogram</h2>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb20" data-code-line-numbers="2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb20-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g)) <span class="sc">+</span></span>
<span id="cb20-2"><a href=""></a> <span class="fu">geom_histogram</span>(<span class="at">binwidth =</span> <span class="dv">100</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-22-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1600"><p><span class="note fragment absolute" style="top: 5%; left: 80%; width: 30%; "><strong>Note</strong>:<br>We only need 1 aesthetic here</span></p>
</section>
<section id="geoms-barplots" class="slide level2">
<h2>Geoms: Barplots</h2>
<h3 id="let-ggplot-count-your-data">Let <code>ggplot</code> count your data</h3>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb21" data-code-line-numbers="2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex)) <span class="sc">+</span></span>
<span id="cb21-2"><a href=""></a> <span class="fu">geom_bar</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-23-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="geoms-barplots-1" class="slide level2">
<h2>Geoms: Barplots</h2>
<h3 id="you-can-also-provide-the-counts">You can also provide the counts</h3>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb22" data-code-line-numbers="6"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb22-1"><a href=""></a><span class="co"># Create our own data frame</span></span>
<span id="cb22-2"><a href=""></a>species_counts <span class="ot"><-</span> <span class="fu">data.frame</span>(<span class="at">species =</span> <span class="fu">c</span>(<span class="st">"Adelie"</span>, <span class="st">"Chinstrap"</span>, <span class="st">"Gentoo"</span>),</span>
<span id="cb22-3"><a href=""></a> <span class="at">n =</span> <span class="fu">c</span>(<span class="dv">152</span>, <span class="dv">68</span>, <span class="dv">124</span>))</span>
<span id="cb22-4"><a href=""></a></span>
<span id="cb22-5"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> species_counts, <span class="fu">aes</span>(<span class="at">x =</span> species, <span class="at">y =</span> n)) <span class="sc">+</span></span>
<span id="cb22-6"><a href=""></a> <span class="fu">geom_bar</span>(<span class="at">stat =</span> <span class="st">"identity"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-24-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="your-turn-create-this-plot" class="slide level2">
<h2>Your Turn: Create this plot</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> ____, <span class="fu">aes</span>(<span class="at">x =</span> ____, <span class="at">y =</span> ____)) <span class="sc">+</span></span>
<span id="cb23-2"><a href=""></a> <span class="fu">geom_____</span>(____)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/yt_boxplot-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"><p><span class="note absolute" style="top: 5%; left: 80%; width: 250px; "><strong>Too Easy?</strong><br>Plot points on top<br><small>Why not consider jittering them?</small></span></p>
</section>
<section id="your-turn-create-this-plot-1" class="slide level2" data-visibility="visible">
<h2>Your Turn: Create this plot</h2>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb24-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> island, <span class="at">y =</span> bill_depth_mm)) <span class="sc">+</span></span>
<span id="cb24-2"><a href=""></a> <span class="fu">geom_boxplot</span>(<span class="at">colour =</span> <span class="st">"blue"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-26-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="your-turn-create-this-plot-2" class="slide level2" data-visibility="visible">
<h2>Your Turn: Create this plot</h2>
<p><strong>Too Easy?</strong></p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb25" data-code-line-numbers="3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> island, <span class="at">y =</span> bill_depth_mm)) <span class="sc">+</span></span>
<span id="cb25-2"><a href=""></a> <span class="fu">geom_boxplot</span>(<span class="at">colour =</span> <span class="st">"blue"</span>) <span class="sc">+</span></span>
<span id="cb25-3"><a href=""></a> <span class="fu">geom_point</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-27-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="your-turn-create-this-plot-3" class="slide level2" data-visibility="visible">
<h2>Your Turn: Create this plot</h2>
<p><strong>Too Easy?</strong></p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb26" data-code-line-numbers="3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb26-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> island, <span class="at">y =</span> bill_depth_mm)) <span class="sc">+</span></span>
<span id="cb26-2"><a href=""></a> <span class="fu">geom_boxplot</span>(<span class="at">colour =</span> <span class="st">"blue"</span>) <span class="sc">+</span></span>
<span id="cb26-3"><a href=""></a> <span class="fu">geom_point</span>(<span class="at">position =</span> <span class="fu">position_jitter</span>(<span class="at">width =</span> <span class="fl">0.1</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-28-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="your-turn-create-this-plot-4" class="slide level2" data-visibility="visible">
<h2>Your Turn: Create this plot</h2>
<p><strong>Too Easy?</strong></p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb27" data-code-line-numbers="3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb27-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> island, <span class="at">y =</span> bill_depth_mm)) <span class="sc">+</span></span>
<span id="cb27-2"><a href=""></a> <span class="fu">geom_boxplot</span>(<span class="at">colour =</span> <span class="st">"blue"</span>) <span class="sc">+</span></span>
<span id="cb27-3"><a href=""></a> <span class="fu">geom_count</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-29-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section></section>
<section>
<section id="showing-data-by-group" class="title-slide slide level1 center">
<h1>Showing data by group</h1>
</section>
<section id="mapping-aesthetics" class="slide level2">
<h2>Mapping aesthetics</h2>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb28-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm)) <span class="sc">+</span></span>
<span id="cb28-2"><a href=""></a> <span class="fu">geom_point</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-30-1.png" class="quarto-figure quarto-figure-center r-stretch" style="width:80.0%"></section>
<section id="mapping-aesthetics-1" class="slide level2">
<h2>Mapping aesthetics</h2>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb29-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm, <span class="at">colour =</span> sex)) <span class="sc">+</span></span>
<span id="cb29-2"><a href=""></a> <span class="fu">geom_point</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-31-1.png" class="quarto-figure quarto-figure-center r-stretch" style="width:80.0%"></section>
<section id="mapping-aesthetics-2" class="slide level2">
<h2>Mapping aesthetics</h2>
<h3 id="ggplot-automatically-populates-the-legends-combining-where-it-can"><code>ggplot</code> automatically populates the legends (combining where it can)</h3>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb30-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm, <span class="at">colour =</span> sex, <span class="at">shape =</span> sex)) <span class="sc">+</span></span>
<span id="cb30-2"><a href=""></a> <span class="fu">geom_point</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-32-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="faceting-facet_wrap" class="slide level2">
<h2>Faceting: <code>facet_wrap()</code></h2>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb31" data-code-line-numbers="3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb31-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm, <span class="at">colour =</span> sex)) <span class="sc">+</span></span>
<span id="cb31-2"><a href=""></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb31-3"><a href=""></a> <span class="fu">facet_wrap</span>(<span class="sc">~</span> species)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-33-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1600"><blockquote>
<p>Split plots by <strong>one</strong> grouping variable</p>
</blockquote>
</section>
<section id="faceting-facet_grid" class="slide level2">
<h2>Faceting: <code>facet_grid()</code></h2>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb32" data-code-line-numbers="3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb32-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm, <span class="at">colour =</span> sex)) <span class="sc">+</span></span>
<span id="cb32-2"><a href=""></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb32-3"><a href=""></a> <span class="fu">facet_grid</span>(sex <span class="sc">~</span> species)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-34-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1600"><blockquote>
<p>Split plots by <strong>two</strong> grouping variables</p>
</blockquote>
</section>
<section id="your-turn-create-this-plot-5" class="slide level2">
<h2>Your Turn: Create this plot</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb33-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> ____, <span class="fu">aes</span>(_____________________________________)) <span class="sc">+</span></span>
<span id="cb33-2"><a href=""></a> ______________ <span class="sc">+</span></span>
<span id="cb33-3"><a href=""></a> ______________</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/yt_facet-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"><blockquote>
<p><strong>Hint:</strong> <code>colour</code> is for outlining with a colour, <code>fill</code> is for ‘filling’ with a colour <br> <strong>Too Easy?</strong> Split boxplots by sex <strong>and</strong> island</p>
</blockquote>
</section>
<section id="your-turn-create-this-plot-6" class="slide level2" data-visibility="visible">
<h2>Your Turn: Create this plot</h2>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb34-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> flipper_length_mm, <span class="at">fill =</span> sex)) <span class="sc">+</span></span>
<span id="cb34-2"><a href=""></a> <span class="fu">geom_boxplot</span>() <span class="sc">+</span></span>
<span id="cb34-3"><a href=""></a> <span class="fu">facet_wrap</span>(<span class="sc">~</span> species)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-36-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"><blockquote>
<p><strong>Hint:</strong> <code>colour</code> is for outlining with a colour, <code>fill</code> is for ‘filling’ with a colour <br> <strong>Too Easy?</strong> Split boxplots by sex <strong>and</strong> island</p>
</blockquote>
</section>
<section id="your-turn-create-this-plot-7" class="slide level2" data-visibility="visible">
<h2>Your Turn: Create this plot</h2>
<p><strong>Too Easy?</strong></p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb35"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb35-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> flipper_length_mm, <span class="at">fill =</span> island)) <span class="sc">+</span></span>
<span id="cb35-2"><a href=""></a> <span class="fu">geom_boxplot</span>() <span class="sc">+</span></span>
<span id="cb35-3"><a href=""></a> <span class="fu">facet_wrap</span>(<span class="sc">~</span> species)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-37-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"><blockquote>
<p>Small change (<code>fill = sex</code> to <code>fill = island</code>) results in completely different plot</p>
</blockquote>
</section></section>
<section>
<section id="adding-statistics-to-plots" class="title-slide slide level1 center">
<h1>Adding Statistics to Plots</h1>
</section>
<section id="summarizing-data" class="slide level2">
<h2>Summarizing data</h2>
<h3 id="add-data-means-as-points">Add data means as points</h3>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb36" data-code-line-numbers="2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb36-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> body_mass_g)) <span class="sc">+</span></span>
<span id="cb36-2"><a href=""></a> <span class="fu">stat_summary</span>(<span class="at">geom =</span> <span class="st">"point"</span>, <span class="at">fun =</span> mean)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-38-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="summarizing-data-1" class="slide level2">
<h2>Summarizing data</h2>
<h3 id="add-error-bars-calculated-from-the-data">Add error bars, calculated from the data</h3>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb37" data-code-line-numbers="3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb37-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> sex, <span class="at">y =</span> body_mass_g)) <span class="sc">+</span></span>
<span id="cb37-2"><a href=""></a> <span class="fu">stat_summary</span>(<span class="at">geom =</span> <span class="st">"point"</span>, <span class="at">fun =</span> mean) <span class="sc">+</span></span>
<span id="cb37-3"><a href=""></a> <span class="fu">stat_summary</span>(<span class="at">geom =</span> <span class="st">"errorbar"</span>, <span class="at">width =</span> <span class="fl">0.05</span>, <span class="at">fun.data =</span> mean_se)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-39-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section></section>
<section>
<section id="trendlines-regression-lines" class="title-slide slide level1 center">
<h1>Trendlines / Regression Lines</h1>
</section>
<section id="trendlines-regression-lines-1" class="slide level2">
<h2>Trendlines / Regression lines</h2>
<h3 id="geom_line-is-connect-the-dots-not-a-trend-or-linear-model"><code>geom_line()</code> is connect-the-dots, not a trend or linear model</h3>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb38-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm)) <span class="sc">+</span></span>
<span id="cb38-2"><a href=""></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb38-3"><a href=""></a> <span class="fu">geom_line</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-40-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"><p><span class="note fragment absolute" style="left: 80%; bottom: 10%; width: 30%; ">Not what we’re looking for</span></p>
</section>
<section id="trendlines-regression-lines-2" class="slide level2">
<h2>Trendlines / Regression lines</h2>
<h3 id="lets-add-a-trend-line-properly">Let’s add a trend line properly</h3>
<p>Start with basic plot:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb39"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb39-1"><a href=""></a>g <span class="ot"><-</span> <span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm)) <span class="sc">+</span></span>
<span id="cb39-2"><a href=""></a> <span class="fu">geom_point</span>()</span>
<span id="cb39-3"><a href=""></a>g</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-41-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="trendlines-regression-lines-3" class="slide level2">
<h2>Trendlines / Regression lines</h2>
<h3 id="add-the-stat_smooth">Add the <code>stat_smooth()</code></h3>
<ul>
<li><code>lm</code> is for “linear model” (i.e. trendline)</li>
<li>grey ribbon = standard error</li>
</ul>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb40-1"><a href=""></a>g <span class="sc">+</span> <span class="fu">stat_smooth</span>(<span class="at">method =</span> <span class="st">"lm"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-42-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="trendlines-regression-lines-4" class="slide level2">
<h2>Trendlines / Regression lines</h2>
<h3 id="add-the-stat_smooth-1">Add the <code>stat_smooth()</code></h3>
<ul>
<li>remove the grey ribbon <code>se = FALSE</code></li>
</ul>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb41-1"><a href=""></a>g <span class="sc">+</span> <span class="fu">stat_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>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-43-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="trendlines-regression-lines-5" class="slide level2">
<h2>Trendlines / Regression lines</h2>
<h3 id="a-line-for-each-group">A line for each group</h3>
<ul>
<li>Specify group (here we use <code>colour</code> to specify <code>species</code>)</li>
</ul>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb42"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb42-1"><a href=""></a>g <span class="ot"><-</span> <span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm, <span class="at">colour =</span> species)) <span class="sc">+</span></span>
<span id="cb42-2"><a href=""></a> <span class="fu">geom_point</span>()</span>
<span id="cb42-3"><a href=""></a>g</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-44-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="trendlines-regression-lines-6" class="slide level2">
<h2>Trendlines / Regression lines</h2>
<h3 id="a-line-for-each-group-1">A line for each group</h3>
<ul>
<li><code>stat_smooth()</code> automatically uses the same grouping</li>
</ul>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb43"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb43-1"><a href=""></a>g <span class="sc">+</span> <span class="fu">stat_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>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-45-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="trendlines-regression-lines-7" class="slide level2">
<h2>Trendlines / Regression lines</h2>
<h3 id="a-line-for-each-group-and-overall">A line for each group AND overall</h3>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb44"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb44-1"><a href=""></a>g <span class="sc">+</span></span>
<span id="cb44-2"><a href=""></a> <span class="fu">stat_smooth</span>(<span class="at">method =</span> <span class="st">"lm"</span>, <span class="at">se =</span> <span class="cn">FALSE</span>) <span class="sc">+</span></span>
<span id="cb44-3"><a href=""></a> <span class="fu">stat_smooth</span>(<span class="at">method =</span> <span class="st">"lm"</span>, <span class="at">se =</span> <span class="cn">FALSE</span>, <span class="at">colour =</span> <span class="st">"black"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-46-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="your-turn-create-this-plot-8" class="slide level2">
<h2>Your Turn: Create this plot</h2>
<ul>
<li>A scatter plot: Flipper Length by Body Mass grouped by Species</li>
<li>With <em>a single regression line for the overall trend</em></li>
</ul>
<blockquote>
<p><strong>Too Easy?</strong> Add regression lines for each species as well<br>
<span class="small">Can you make the species lines larger?</span><br>
<span class="small">Can you indicate which points are female and which are male?</span></p>
</blockquote>
</section>
<section id="your-turn-create-this-plot-9" class="slide level2" data-visibility="visible">
<h2>Your Turn: Create this plot</h2>
<ul>
<li>A scatter plot: Flipper Length by Body Mass grouped by Species</li>
<li>With <em>a single regression line for the overall trend</em></li>
</ul>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb45"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb45-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> flipper_length_mm, <span class="at">colour =</span> species)) <span class="sc">+</span></span>
<span id="cb45-2"><a href=""></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb45-3"><a href=""></a> <span class="fu">stat_smooth</span>(<span class="at">method =</span> <span class="st">"lm"</span>, <span class="at">se =</span> <span class="cn">FALSE</span>, <span class="at">colour =</span> <span class="st">"black"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-47-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="your-turn-create-this-plot-10" class="slide level2" data-visibility="visible">
<h2>Your Turn: Create this plot</h2>
<p><strong>Too Easy?</strong></p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb46"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb46-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> flipper_length_mm, <span class="at">colour =</span> species)) <span class="sc">+</span></span>
<span id="cb46-2"><a href=""></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb46-3"><a href=""></a> <span class="fu">stat_smooth</span>(<span class="at">method =</span> <span class="st">"lm"</span>, <span class="at">se =</span> <span class="cn">FALSE</span>) <span class="sc">+</span></span>
<span id="cb46-4"><a href=""></a> <span class="fu">stat_smooth</span>(<span class="at">method =</span> <span class="st">"lm"</span>, <span class="at">se =</span> <span class="cn">FALSE</span>, <span class="at">colour =</span> <span class="st">"black"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-48-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="your-turn-create-this-plot-11" class="slide level2" data-visibility="visible">
<h2>Your Turn: Create this plot</h2>
<p><strong>Too Easy?</strong></p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb47"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb47-1"><a href=""></a><span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> flipper_length_mm, </span>
<span id="cb47-2"><a href=""></a> <span class="at">colour =</span> species)) <span class="sc">+</span></span>
<span id="cb47-3"><a href=""></a> <span class="fu">geom_point</span>(<span class="fu">aes</span>(<span class="at">shape =</span> sex), <span class="at">size =</span> <span class="dv">2</span>, <span class="at">fill =</span> <span class="st">"white"</span>) <span class="sc">+</span></span>
<span id="cb47-4"><a href=""></a> <span class="fu">stat_smooth</span>(<span class="at">method =</span> <span class="st">"lm"</span>, <span class="at">se =</span> <span class="cn">FALSE</span>, <span class="at">linewidth =</span> <span class="dv">2</span>) <span class="sc">+</span></span>
<span id="cb47-5"><a href=""></a> <span class="fu">stat_smooth</span>(<span class="at">method =</span> <span class="st">"lm"</span>, <span class="at">se =</span> <span class="cn">FALSE</span>, <span class="at">colour =</span> <span class="st">"black"</span>) <span class="sc">+</span></span>
<span id="cb47-6"><a href=""></a> <span class="fu">scale_shape_manual</span>(<span class="at">values =</span> <span class="fu">c</span>(<span class="dv">20</span>, <span class="dv">21</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-49-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section></section>
<section>
<section id="customizing-plots" class="title-slide slide level1 center">
<h1>Customizing plots</h1>
</section>
<section id="customizing-starting-plot" class="slide level2">
<h2>Customizing: Starting plot</h2>
<h3 id="lets-work-with-this-plot">Let’s work with this plot</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb48"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb48-1"><a href=""></a>g <span class="ot"><-</span> <span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm, <span class="at">colour =</span> species)) <span class="sc">+</span></span>
<span id="cb48-2"><a href=""></a> <span class="fu">geom_point</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-51-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="customizing-labels" class="slide level2">
<h2>Customizing: Labels</h2>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb49"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb49-1"><a href=""></a>g <span class="sc">+</span> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Bill Length vs. Body Mass"</span>,</span>
<span id="cb49-2"><a href=""></a> <span class="at">x =</span> <span class="st">"Body Mass (g)"</span>,</span>
<span id="cb49-3"><a href=""></a> <span class="at">y =</span> <span class="st">"Bill Length (mm)"</span>,</span>
<span id="cb49-4"><a href=""></a> <span class="at">colour =</span> <span class="st">"Species"</span>, <span class="at">tag =</span> <span class="st">"A"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-52-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"><p><span class="note fragment absolute" style="left: 80%; bottom: 60%; width: 30%; "><strong>Your Turn:</strong> Add proper labels to some of your previous plots</span></p>
</section>
<section id="customizing-built-in-themes" class="slide level2">
<h2>Customizing: Built-in themes</h2>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-53-1.png" style="width:100.0%" class="r-stretch"></section>
<section id="customizing-axes" class="slide level2">
<h2>Customizing: Axes</h2>
<p><code>scale_</code> + (<code>x</code> or <code>y</code>) + type (<code>continuous</code>, <code>discrete</code>, <code>date</code>, <code>datetime</code>)</p>
<ul>
<li><code>scale_x_continuous()</code></li>
<li><code>scale_y_discrete()</code></li>
<li>etc.</li>
</ul>
<h3 id="common-arguments">Common arguments</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb50"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb50-1"><a href=""></a>g <span class="sc">+</span> <span class="fu">scale_x_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">10</span>)) <span class="co"># Tick breaks</span></span>
<span id="cb50-2"><a href=""></a>g <span class="sc">+</span> <span class="fu">scale_x_continuous</span>(<span class="at">limits =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="dv">15</span>)) <span class="co"># xlim() is a shortcut for this</span></span>
<span id="cb50-3"><a href=""></a>g <span class="sc">+</span> <span class="fu">scale_x_continuous</span>(<span class="at">expand =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="dv">0</span>)) <span class="co"># Space between axis and data</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="spacer">
<p>Let’s take a look…</p>
</div>
</section>
<section id="customizing-axes-1" class="slide level2">
<h2>Customizing: Axes</h2>
<h3 id="breaks">Breaks</h3>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb51"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb51-1"><a href=""></a>g <span class="sc">+</span> <span class="fu">scale_x_continuous</span>(<span class="at">breaks =</span> <span class="fu">seq</span>(<span class="dv">2500</span>, <span class="dv">6500</span>, <span class="dv">500</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-55-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="customizing-axes-2" class="slide level2">
<h2>Customizing: Axes</h2>
<h3 id="limits">Limits</h3>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb52"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb52-1"><a href=""></a>g <span class="sc">+</span> <span class="fu">scale_x_continuous</span>(<span class="at">limits =</span> <span class="fu">c</span>(<span class="dv">3000</span>, <span class="dv">4000</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-56-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="customizing-axes-3" class="slide level2">
<h2>Customizing: Axes</h2>
<h3 id="space-between-origin-and-axis-start">Space between origin and axis start</h3>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb53"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb53-1"><a href=""></a>g <span class="sc">+</span> <span class="fu">scale_x_continuous</span>(<span class="at">expand =</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="dv">0</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-57-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="customizing-aesthetics" class="slide level2">
<h2>Customizing: Aesthetics</h2>
<h3 id="using-scales">Using scales</h3>
<p><code>scale_</code> + aesthetic <span class="small">(<code>colour</code>, <code>fill</code>, <code>size</code>, etc.)</span> + type <span class="small">(<code>manual</code>, <code>continuous</code>, <code>datetime</code>, etc.)</span></p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb54"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb54-1"><a href=""></a>g <span class="sc">+</span> <span class="fu">scale_colour_manual</span>(<span class="at">name =</span> <span class="st">"Type"</span>, <span class="at">values =</span> <span class="fu">c</span>(<span class="st">"green4"</span>, <span class="st">"blue4"</span>, <span class="st">"gold"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<img data-src="2_visualizations_files/figure-revealjs/unnamed-chunk-58-1.png" class="quarto-figure quarto-figure-center r-stretch" width="1400"></section>
<section id="customizing-aesthetics-1" class="slide level2">
<h2>Customizing: Aesthetics</h2>
<h3 id="using-scales-1">Using scales</h3>
<p>Or be very explicit:</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb55"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb55-1"><a href=""></a>g <span class="sc">+</span> <span class="fu">scale_colour_manual</span>(</span>
<span id="cb55-2"><a href=""></a> <span class="at">name =</span> <span class="st">"Type"</span>,</span>
<span id="cb55-3"><a href=""></a> <span class="at">values =</span> <span class="fu">c</span>(<span class="st">"Adelie"</span> <span class="ot">=</span> <span class="st">"green4"</span>, <span class="st">"Gentoo"</span> <span class="ot">=</span> <span class="st">"blue4"</span>, <span class="st">"Chinstrap"</span> <span class="ot">=</span> <span class="st">"gold"</span>),</span>
<span id="cb55-4"><a href=""></a> <span class="at">na.value =</span> <span class="st">"black"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>