forked from saundersg/Statistics-Notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphicalSummaries.html
executable file
·1287 lines (1232 loc) · 127 KB
/
GraphicalSummaries.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">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<title>Graphical Summaries</title>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cerulean.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<script src="site_libs/htmlwidgets-1.2/htmlwidgets.js"></script>
<script src="site_libs/plotly-binding-4.8.0/plotly.js"></script>
<script src="site_libs/typedarray-0.1/typedarray.min.js"></script>
<link href="site_libs/crosstalk-1.0.0/css/crosstalk.css" rel="stylesheet" />
<script src="site_libs/crosstalk-1.0.0/js/crosstalk.min.js"></script>
<link href="site_libs/plotly-htmlwidgets-css-1.39.2/plotly-htmlwidgets.css" rel="stylesheet" />
<script src="site_libs/plotly-main-1.39.2/plotly-latest.min.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; background-color: #f8f8f8; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
pre, code { background-color: #f8f8f8; }
code > span.kw { color: #204a87; font-weight: bold; } /* Keyword */
code > span.dt { color: #204a87; } /* DataType */
code > span.dv { color: #0000cf; } /* DecVal */
code > span.bn { color: #0000cf; } /* BaseN */
code > span.fl { color: #0000cf; } /* Float */
code > span.ch { color: #4e9a06; } /* Char */
code > span.st { color: #4e9a06; } /* String */
code > span.co { color: #8f5902; font-style: italic; } /* Comment */
code > span.ot { color: #8f5902; } /* Other */
code > span.al { color: #ef2929; } /* Alert */
code > span.fu { color: #000000; } /* Function */
code > span.er { color: #a40000; font-weight: bold; } /* Error */
code > span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #000000; } /* Constant */
code > span.sc { color: #000000; } /* SpecialChar */
code > span.vs { color: #4e9a06; } /* VerbatimString */
code > span.ss { color: #4e9a06; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #000000; } /* Variable */
code > span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */
code > span.op { color: #ce5c00; font-weight: bold; } /* Operator */
code > span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */
code > span.ex { } /* Extension */
code > span.at { color: #c4a000; } /* Attribute */
code > span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */
code > span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>
<body>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
</style>
<style type="text/css">
/* padding for bootstrap navbar */
body {
padding-top: 51px;
padding-bottom: 40px;
}
/* offset scroll position for anchor links (for fixed navbar) */
.section h1 {
padding-top: 56px;
margin-top: -56px;
}
.section h2 {
padding-top: 56px;
margin-top: -56px;
}
.section h3 {
padding-top: 56px;
margin-top: -56px;
}
.section h4 {
padding-top: 56px;
margin-top: -56px;
}
.section h5 {
padding-top: 56px;
margin-top: -56px;
}
.section h6 {
padding-top: 56px;
margin-top: -56px;
}
</style>
<script>
// manage active state of menu based on current page
$(document).ready(function () {
// active menu anchor
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
if (href === "")
href = "index.html";
var menuAnchor = $('a[href="' + href + '"]');
// mark it active
menuAnchor.parent().addClass('active');
// if it's got a parent navbar menu mark it active as well
menuAnchor.closest('li.dropdown').addClass('active');
});
</script>
<div class="container-fluid main-container">
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
</script>
<!-- code folding -->
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Math 325 Notebook</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="index.html">Table of Contents</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Describing Data
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="GraphicalSummaries.html">Graphical Summaries</a>
</li>
<li>
<a href="NumericalSummaries.html">Numerical Summaries</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
R Help
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="RCommands.html">R Commands</a>
</li>
<li>
<a href="RMarkdownHints.html">R Markdown Hints</a>
</li>
<li>
<a href="RCheatSheetsAndNotes.html">R Cheatsheets & Notes</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Analyses
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="./Analyses/AnalysisRubric.html">Analysis Rubric</a>
</li>
<li>
<a href="./Analyses/StudentHousing.html">Good Example Analysis</a>
</li>
<li>
<a href="./Analyses/StudentHousingPOOR.html">Poor Example Analysis</a>
</li>
<li>
<a href="./Analyses/Stephanie.html">Stephanie Analysis</a>
</li>
<li>
<a href="./Analyses/Olympics.html">Olympics Analysis</a>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div class="fluid-row" id="header">
<h1 class="title toc-ignore">Graphical Summaries</h1>
</div>
<script type="text/javascript">
function showhide(id) {
var e = document.getElementById(id);
e.style.display = (e.style.display == 'block') ? 'none' : 'block';
}
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
</script>
<hr />
<p>There are many ways to display data. The fundamental idea is that the graphical depiction of data should communicate the truth the data has to offer about the situation of interest.</p>
<hr />
<div id="histograms" class="section level3 tabset tabset-fade tabset-pills">
<h3>Histograms</h3>
<div style="float:left;width:125px;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-2-1.png" width="96" /></p>
</div>
<p><strong>1 Quantitative Variable</strong></p>
<div id="overview" class="section level4">
<h4>Overview</h4>
<div style="padding-left:125px;">
<p>Great for showing the distribution of data for a single quantitative variable when the sample size is large. Dotplots are a good alternative for smaller sample sizes. Gives a good feel for the <a href="NumericalSummaries.html#mean">mean</a> and <a href="NumericalSummaries.html#sd">standard deviation</a> of the data.</p>
</div>
<hr />
</div>
<div id="r-instructions" class="section level4">
<h4>R Instructions</h4>
<div style="padding-left:125px;">
<div class="tab">
<button class="tablinks" onclick="openTab(event, 'BaseHistogram')">
Base R
</button>
<button class="tablinks" onclick="openTab(event, 'ggplot2Histogram')">
ggplot2
</button>
<button class="tablinks" onclick="openTab(event, 'plotlyHistogram')">
plotly
</button>
</div>
<div id="BaseHistogram" class="tabcontent">
<p>
<p>To make a histogram in R use the function:</p>
<p><code>hist(object)</code></p>
<ul>
<li><code>object</code> must be quantitative data. R refers to this as a “numeric vector.”</li>
</ul>
<p>Type <code>?hist</code> in your <strong>R Console</strong> to open the help file in R.</p>
<p><br></p>
<p><strong>Example Code</strong></p>
<p>Hover your mouse over the example codes to learn more.</p>
<p>Click to see what they do.</p>
<a href="javascript:showhide('hist1')">
<div class="hoverchunk">
<p><span class="tooltipr"> hist <span class="tooltiprtext">An R function “hist” used to create a histogram.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> $ <span class="tooltiprtext">The $ allows us to access any variable from the airquality dataset.</span> </span><span class="tooltipr"> Temp <span class="tooltiprtext">“Temp” is a quantitative variable (numeric vector) from the “airquality” dataset.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the hist function.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="hist1" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-3-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('hist3')">
<div class="hoverchunk">
<p><span class="tooltipr"> hist(airquality$Temp, <span class="tooltiprtext">This code was explained in the first example code.</span> </span><span class="tooltipr"> col=“skyblue” <span class="tooltiprtext">col= allows us to specify the color of the plot using a named color. The name of the color must be placed in quotations. Type “colors()” in R to see color options.</span> </span><span class="tooltipr"> ) <span class="tooltiprtext">Functions always end with a closing parenthesis.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="hist3" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-4-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('hist2')">
<div class="hoverchunk">
<p><span class="tooltipr"> hist(airquality$Temp <span class="tooltiprtext">This part was explained in the first example code.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> col=“skyblue”<span class="tooltiprtext">col= allows us to specify the color of the plot using a named color. The name of the color must be placed in quotations. Type “colors()” in R to see color options.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">A comma must always be used to separate additional commands.</span> </span><span class="tooltipr"> xlab=“Temperature” <span class="tooltiprtext">xlab= stands for “x label.” Use it to specify the text to print on the plot under the x-axis. The desired text must always be in quotations.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">A comma must always be used to separate additional commands.</span> </span><span class="tooltipr"> main=“La Guardia Airport Daily Mean Temperatures” <span class="tooltiprtext">main= lets us specify the “main” title to be placed above the plot. The desired text must always be placed in quotations.</span> </span><span class="tooltipr"> ) <span class="tooltiprtext">Functions must always end with a closing parenthesis.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="hist2" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-5-1.png" width="672" /></p>
</div>
</p>
</div>
<div id="ggplot2Histogram" class="tabcontent">
<p>
<p>To make a histogram in R using the ggplot approach, first ensure</p>
<p><code>library(ggplot2)</code></p>
<p>is loaded. Then,</p>
<p><code>ggplot(data, aes(x=column)) +</code></p>
<p> <code>geom_histogram()</code></p>
<ul>
<li><code>data</code> is the name of your dataset.</li>
<li><code>column</code> is a column of data from your dataset that is quantitative.</li>
<li>The aesthetic helper function <code>aes(x= )</code> is how you tell the gpplot to make the x-axis become your <code>column</code> of data.</li>
<li>The geometry helper function <code>geom_histogram()</code> causes the ggplot to become a histogram.</li>
</ul>
<p><br></p>
<p><strong>Example Code</strong></p>
<p>Hover your mouse over the example codes to learn more.</p>
<p>Click to see what they do.</p>
<a href="javascript:showhide('hist1ggplot')">
<div class="hoverchunk">
<p><span class="tooltipr"> ggplot <span class="tooltiprtext">An R function “ggplot” used to create a framework for a graphic that will have elements added to it with the <code>+</code> sign.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> aes( <span class="tooltiprtext">The <code>aes</code> or “aesthetics” function allows you to tell the ggplot how it should appear. This includes things like what the x-axis or y-axis should become.</span> </span><span class="tooltipr"> x=Temp <span class="tooltiprtext">“x=” declares which variable will become the x-axis of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the aes function.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the ggplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> geom_histogram() <span class="tooltiprtext">The “geom_histogram()” function causes the ggplot to become a histogram. There are many other “geom_” functions that could be used.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="hist1ggplot" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-6-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('hist2ggplot')">
<div class="hoverchunk">
<p><span class="tooltipr"> ggplot <span class="tooltiprtext">An R function “ggplot” used to create a framework for a graphic that will have elements added to it with the <code>+</code> sign.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> aes( <span class="tooltiprtext">The <code>aes</code> or “aesthetics” function allows you to tell the ggplot how it should appear. This includes things like what the x-axis or y-axis should become.</span> </span><span class="tooltipr"> x=Temp <span class="tooltiprtext">“x=” declares which variable will become the x-axis of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the aes function.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the ggplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> geom_histogram( <span class="tooltiprtext">The “geom_histogram()” function causes the ggplot to become a histogram. There are many other “geom_” functions that could be used.</span> </span><span class="tooltipr"> binwidth=5, <span class="tooltiprtext">The “binwidth” command controls the width of the bars in the histogram.</span> </span><span class="tooltipr"> fill=“skyblue”, <span class="tooltiprtext">The “fill” command controls the color of the insides of each bar.</span> </span><span class="tooltipr"> color=“black” <span class="tooltiprtext">The “color” command controls the color of the edges of each bar.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the geom_histogram function.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="hist2ggplot" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-7-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('hist3ggplot')">
<div class="hoverchunk">
<p><span class="tooltipr"> ggplot <span class="tooltiprtext">An R function “ggplot” used to create a framework for a graphic that will have elements added to it with the <code>+</code> sign.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> aes( <span class="tooltiprtext">The <code>aes</code> or “aesthetics” function allows you to tell the ggplot how it should appear. This includes things like what the x-axis or y-axis should become.</span> </span><span class="tooltipr"> x=Temp <span class="tooltiprtext">“x=” declares which variable will become the x-axis of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the aes function.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the ggplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> geom_histogram( <span class="tooltiprtext">The “geom_histogram()” function causes the ggplot to become a histogram. There are many other “geom_” functions that could be used.</span> </span><span class="tooltipr"> binwidth=5, <span class="tooltiprtext">The “binwidth” command controls the width of the bars in the histogram.</span> </span><span class="tooltipr"> fill=“skyblue”, <span class="tooltiprtext">The “fill” command controls the color of the insides of each bar.</span> </span><span class="tooltipr"> color=“black” <span class="tooltiprtext">The “color” command controls the color of the edges of each bar.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the geom_histogram function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> labs( <span class="tooltiprtext">The “labs” function is used to add labels to the plot, like a main title, x-label and y-label.</span> </span><span class="tooltipr"> title=“La Guardia Airport Daily Mean Temperature”, <span class="tooltiprtext">The “title=” command allows you to control the main title at the top of the graphic.</span> </span><span class="tooltipr"> x=“Temperature”, <span class="tooltiprtext">The “x=” command allows you to control the x-label of the graphic.</span> </span><span class="tooltipr"> y=“Number of Days” <span class="tooltiprtext">The “y=” command allows you to control the y-label of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the labs function.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="hist3ggplot" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-8-1.png" width="672" /></p>
</div>
</p>
</div>
<div id="plotlyHistogram" class="tabcontent">
<p>
Not yet available.
</p>
</div>
</div>
<hr />
</div>
<div id="explanation" class="section level4">
<h4>Explanation</h4>
<div style="padding-left:125px;">
<p>Histograms group data that are close to each other into “bins” (the vertical bars in the plot). The height of a bin is determined by the number of data points that are contained within the bin. For example, if we group together all the sections of the book of scripture known as the <a href="https://www.lds.org/scriptures/dc-testament/chron-order?lang=eng">Doctrine and Covenants</a> that occurred in a given year (Jan. 1st - Dec. 31st) then we get the following counts.</p>
<table>
<thead>
<tr class="header">
<th>Year</th>
<th>Number of Sections</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>1823</td>
<td>1</td>
</tr>
<tr class="even">
<td>1824</td>
<td>0</td>
</tr>
<tr class="odd">
<td>1825</td>
<td>0</td>
</tr>
<tr class="even">
<td>1826</td>
<td>0</td>
</tr>
<tr class="odd">
<td>1827</td>
<td>0</td>
</tr>
<tr class="even">
<td>1828</td>
<td>1</td>
</tr>
<tr class="odd">
<td>1829</td>
<td>16</td>
</tr>
<tr class="even">
<td>1830</td>
<td>19</td>
</tr>
<tr class="odd">
<td>1831</td>
<td>37</td>
</tr>
<tr class="even">
<td>1832</td>
<td>16</td>
</tr>
<tr class="odd">
<td>1833</td>
<td>12</td>
</tr>
<tr class="even">
<td>1834</td>
<td>5</td>
</tr>
<tr class="odd">
<td>1835</td>
<td>3</td>
</tr>
<tr class="even">
<td>1836</td>
<td>4</td>
</tr>
<tr class="odd">
<td>1837</td>
<td>1</td>
</tr>
<tr class="even">
<td>1838</td>
<td>8</td>
</tr>
<tr class="odd">
<td>1839</td>
<td>3</td>
</tr>
<tr class="even">
<td>1840</td>
<td>0</td>
</tr>
<tr class="odd">
<td>1841</td>
<td>3</td>
</tr>
<tr class="even">
<td>1842</td>
<td>2</td>
</tr>
<tr class="odd">
<td>1843</td>
<td>4</td>
</tr>
<tr class="even">
<td>1844</td>
<td>1</td>
</tr>
<tr class="odd">
<td>1845</td>
<td>0</td>
</tr>
<tr class="even">
<td>1846</td>
<td>0</td>
</tr>
<tr class="odd">
<td>1847</td>
<td>1</td>
</tr>
</tbody>
</table>
<p><span style="padding-left:30px; color:#a8a8a8; font-size:.8em;"> *Note that Section 138 occurred in 1918 and is removed from this example. </span></p>
<p>In this example, each “bin” spans 365 days (Jan. 1 - Dec. 31 of each year). Since “dates” can be used as quantitative data, it makes sense to make a histogram of these data. (Remember, histograms are only for quantitative data.)</p>
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-9-1.png" width="672" /></p>
<p>Notice in the bins above that the left edge of the bin is on the year the data corresponds with. The right edge of the bin lands on the following year. For example, the first bin has left edge on 1823 and right edge on 1824. Since there was one revelation in 1823, this bin has a height of 1. The bin that has 1831 on the left and 1832 on the right shows that 37 revelations occurred in 1831. It is powerful to notice the amount of revelations occurring around 1830, the year the <a href="https://www.lds.org/?lang=eng">Church of Jesus Christ of Latter-day Saints</a> was organized.</p>
</div>
<hr />
</div>
</div>
<div id="boxplots" class="section level3 tabset tabset-fade tabset-pills">
<h3>Boxplots</h3>
<div style="float:left;width:125px;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-10-1.png" width="96" /></p>
</div>
<p><strong>1 Quantitative Variable | 2+ Groups</strong></p>
<div id="overview-1" class="section level4">
<h4>Overview</h4>
<div style="padding-left:125px;">
<p>Graphical depiction of the <a href="NumericalSummaries.html#quartiles">five-number summary</a>. Great for comparing the distributions of data across several groups or categories. Provides a quick visual understanding of the location of the median as well as the range of the data. Can be useful in showing outliers. Sample size should be larger than at least five, or computing the <em>five</em>-number summary is not very meaningful. Side-by-side dotplots are a good alternative for smaller sample sizes.</p>
</div>
<hr />
</div>
<div id="r-instructions-1" class="section level4">
<h4>R Instructions</h4>
<div style="padding-left:125px;">
<div class="tab">
<button class="tablinks" onclick="openTab(event, 'BaseBoxplot')">
Base R
</button>
<button class="tablinks" onclick="openTab(event, 'ggplot2Boxplot')">
ggplot2
</button>
<button class="tablinks" onclick="openTab(event, 'plotlyBoxplot')">
plotly
</button>
</div>
<div id="BaseBoxplot" class="tabcontent">
<p>
<p>To make a boxplot in R use the function:</p>
<p><code>boxplot(object)</code></p>
<p>To make side-by-side boxplots:</p>
<p><code>boxplot(object ~ group, data=NameOfYourData, ...)</code></p>
<ul>
<li><code>object</code> must be quantitative data. R refers to this as a “numeric vector.”</li>
<li><code>group</code> must be qualitative data. R refers to this as either a “character vector” or a “factor.” However, a “numeric vector” can also act as a qualitative variable.</li>
<li><code>NameOfYourData</code> is the name of the dataset containing <code>object</code> and <code>group</code>.</li>
<li><code>...</code> implies there are many other options that can be given to the <code>boxplot()</code> function. Type <code>?boxplot</code> in your <strong>R Console</strong> for more details.</li>
</ul>
<p><strong>Example Code</strong></p>
<a href="javascript:showhide('boxplot0')">
<div class="hoverchunk">
<p><span class="tooltipr"> boxplot <span class="tooltiprtext">An R function “boxplot” used to create boxplots.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> $ <span class="tooltiprtext">The $ allows us to access any variable from the airquality dataset.</span> </span><span class="tooltipr"> Temp <span class="tooltiprtext">“Temp” is a quantitative variable (numeric vector) from the “airquality” dataset.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the function.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="boxplot0" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-11-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('boxplot1')">
<div class="hoverchunk">
<p><span class="tooltipr"> boxplot <span class="tooltiprtext">An R function “boxplot” used to create boxplots.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> Temp <span class="tooltiprtext">“Temp” is a quantitative variable (numeric vector) from the “airquality” dataset.</span> </span><span class="tooltipr"> ~ <span class="tooltiprtext">The ~ is used to tell R that you want one boxplot of the quantitative variable (“Temp”) for each group found in the qualitative variable (“Month”).</span> </span><span class="tooltipr"> Month <span class="tooltiprtext">“Month” is a qualitative variable (in this case a “numeric vector” defining months by 5, 6, 7, 8, and 9) from the “airquality” dataset.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the “boxplot()” function.</span> </span><span class="tooltipr"> data=airquality <span class="tooltiprtext">data= is used to tell R that the “Temp” and “Month” variables are located in the <span style="font-weight:bold">airquality</span> dataset. Without this, R will not know where to find “Temp” and “Month” and the command will give an error.</span> </span><span class="tooltipr"> ) <span class="tooltiprtext">Functions always end with a closing parenthesis.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="boxplot1" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-12-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('boxplot2a')">
<div class="hoverchunk">
<p><span class="tooltipr"> boxplot <span class="tooltiprtext">An R function “boxplot” used to create boxplots.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> Temp <span class="tooltiprtext">“Temp” is a quantitative variable (numeric vector) from the “airquality” dataset.</span> </span><span class="tooltipr"> ~ <span class="tooltiprtext">The ~ is used to tell R that you want one boxplot of the quantitative variable (“Temp”) for each group found in the qualitative variable (“Month”).</span> </span><span class="tooltipr"> Month <span class="tooltiprtext">“Month” is a qualitative variable (in this case a “numeric vector” defining months by 5, 6, 7, 8, and 9) from the “airquality” dataset.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the “boxplot()” function.</span> </span><span class="tooltipr"> data=airquality <span class="tooltiprtext">data= is used to tell R that the “Temp” and “Month” variables are located in the <span style="font-weight:bold">airquality</span> dataset. Without this, R will not know where to find “Temp” and “Month” and the command will give an error.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the “boxplot()” function.</span> </span><span class="tooltipr"> names=c(“May”,“June”,“July”,“Aug”,“Sep”) <span class="tooltiprtext">names= is used to tell R what labels to place on the x-axis below each boxplot.</span> </span><span class="tooltipr"> ) <span class="tooltiprtext">Functions always end with a closing parenthesis.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="boxplot2a" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-13-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('boxplot2')">
<div class="hoverchunk">
<p><span class="tooltipr"> boxplot(Temp ~ Month, data=airquality <span class="tooltiprtext">This code was explained in the previous example code.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> xlab=“Month of the Year” <span class="tooltiprtext">xlab= stands for “x label.” Use it to specify the text to print on the plot under the x-axis. The desired text must always be contained in quotes.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> ylab=“Temperature” <span class="tooltiprtext">ylab= stands for “y label.” Use it to specify the text to print on the plot next to the y-axis. The desired text must always be contained in quotes.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> main=“La Guardia Airport Daily Temperatures” <span class="tooltiprtext">main= stands for the “main label” of the plot, which is placed at the top center of the plot. The desired text must always be contained in quotes.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> col=“wheat” <span class="tooltiprtext">col= stands for the “color” of the plot. The color name “wheat” is an available color in R. Type colors() in the R Console to see more options. The color name must always be placed in quotes.</span> </span><span class="tooltipr"> ) <span class="tooltiprtext">Functions always end with a closing parenthesis.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="boxplot2" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-14-1.png" width="672" /></p>
</div>
</p>
</div>
<div id="ggplot2Boxplot" class="tabcontent">
<p>
<p>To make a boxplot in R using the ggplot approach, first ensure</p>
<p><code>library(ggplot2)</code></p>
<p>is loaded. Then,</p>
<p><code>ggplot(data, aes(x=groupsColumn, y=dataColumn) +</code></p>
<p> <code>geom_boxplot()</code></p>
<ul>
<li><code>data</code> is the name of your dataset.</li>
<li><code>groupsColumn</code> is a column of data from your dataset that is qualitative and represents the groups that should each have a boxplot.</li>
<li><code>dataColumn</code> is a column of data from your dataset that is quantitative.</li>
<li>The aesthetic helper function <code>aes(x= , y=)</code> is how you tell the gpplot to make the x-axis have the values in your <code>groupsColumn</code> of data, the y-axis become your <code>dataColumn</code>. <strong>Note</strong> <em>if <code>groupsColumn</code> is not a factor, use <code>factor(groupsColumn)</code> instead.</em></li>
<li>The geometry helper function <code>geom_boxplot()</code> causes the ggplot to become a boxplot.</li>
</ul>
<p><br></p>
<p><strong>Example Code</strong></p>
<p>Hover your mouse over the example codes to learn more.</p>
<p>Click to see what they do.</p>
<a href="javascript:showhide('box1ggplot')">
<div class="hoverchunk">
<p><span class="tooltipr"> ggplot <span class="tooltiprtext">An R function “ggplot” used to create a framework for a graphic that will have elements added to it with the <code>+</code> sign.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> aes( <span class="tooltiprtext">The <code>aes</code> or “aesthetics” function allows you to tell the ggplot how it should appear. This includes things like what the y-axis should become.</span> </span><span class="tooltipr"> y=Temp <span class="tooltiprtext">“y=” declares which variable will become the y-axis of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the aes function.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the ggplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> geom_boxplot() <span class="tooltiprtext">The “geom_boxplot()” function causes the ggplot to become a boxplot. There are many other “geom_” functions that could be used.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="box1ggplot" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-15-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('box2ggplot')">
<div class="hoverchunk">
<p><span class="tooltipr"> ggplot <span class="tooltiprtext">An R function “ggplot” used to create a framework for a graphic that will have elements added to it with the <code>+</code> sign.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> aes( <span class="tooltiprtext">The <code>aes</code> or “aesthetics” function allows you to tell the ggplot how it should appear. This includes things like what the x-axis or y-axis should become.</span> </span><span class="tooltipr"> x=factor(Month), <span class="tooltiprtext">“x=” declares which variable will become the x-axis of the graphic. Since Month is “numeric” we must use “factor(Month)” instead of just “Month”.</span> </span><span class="tooltipr"> y=Temp <span class="tooltiprtext">“y=” declares which variable will become the y-axis of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the aes function.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the ggplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> geom_boxplot( <span class="tooltiprtext">The “geom_boxplot()” function causes the ggplot to become a boxplot. There are many other “geom_” functions that could be used.</span> </span><span class="tooltipr"> fill=“skyblue”, <span class="tooltiprtext">The “fill” command controls the color of the insides of each box in the boxplot.</span> </span><span class="tooltipr"> color=“black” <span class="tooltiprtext">The “color” command controls the color of the edges of each box.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the geom_boxplot function.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="box2ggplot" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-16-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('box3ggplot')">
<div class="hoverchunk">
<p><span class="tooltipr"> ggplot <span class="tooltiprtext">An R function “ggplot” used to create a framework for a graphic that will have elements added to it with the <code>+</code> sign.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> aes( <span class="tooltiprtext">The <code>aes</code> or “aesthetics” function allows you to tell the ggplot how it should appear. This includes things like what the x-axis or y-axis should become.</span> </span><span class="tooltipr"> x=factor(Month), <span class="tooltiprtext">“x=” declares which variable will become the x-axis of the graphic. Since Month is “numeric” we must use “factor(Month)” instead of just “Month”.</span> </span><span class="tooltipr"> y=Temp <span class="tooltiprtext">“y=” declares which variable will become the y-axis of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the aes function.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the ggplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> geom_boxplot( <span class="tooltiprtext">The “geom_histogram()” function causes the ggplot to become a histogram. There are many other “geom_” functions that could be used.</span> </span><span class="tooltipr"> fill=“skyblue”, <span class="tooltiprtext">The “fill” command controls the color of the insides of each box.</span> </span><span class="tooltipr"> color=“black” <span class="tooltiprtext">The “color” command controls the color of the edges of each box.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the geom_boxplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> labs( <span class="tooltiprtext">The “labs” function is used to add labels to the plot, like a main title, x-label and y-label.</span> </span><span class="tooltipr"> title=“La Guardia Airport Daily Mean Temperature”, <span class="tooltiprtext">The “title=” command allows you to control the main title at the top of the graphic.</span> </span><span class="tooltipr"> x=“Month of the Year”, <span class="tooltiprtext">The “x=” command allows you to control the x-label of the graphic.</span> </span><span class="tooltipr"> y=“Daily Mean Temperature” <span class="tooltiprtext">The “y=” command allows you to control the y-label of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the labs function.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="box3ggplot" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-17-1.png" width="672" /></p>
</div>
</p>
</div>
<div id="plotlyBoxplot" class="tabcontent">
<p>
Not yet available.
</p>
</div>
</div>
<hr />
</div>
<div id="explanation-1" class="section level4">
<h4>Explanation</h4>
<div style="padding-left:125px;">
<p>Understanding how a boxplot is created is the best way to understand what the boxplot shows.</p>
<h5 id="how-boxplots-are-made">How Boxplots are Made</h5>
<ol style="list-style-type: decimal">
<li>The five-number summary is computed.</li>
<li>A box is drawn with one edge located at the first quartile and the opposite edge located at the third quartile.</li>
<li>This box is then divided into two boxes by placing another line inside the box at the location of the median.</li>
<li>The maximum value and minimum value are marked on the plot.</li>
<li>Whiskers are drawn from the first quartile out towards the minimum and from the third quartile out towards the maximum.</li>
<li>If the minimum or maximum is too far away, then the whisker is ended early.</li>
<li>Any points beyond the line ending the whisker are marked on the plot as dots. This helps identify possible outliers in the data.</li>
</ol>
</div>
<hr />
</div>
</div>
<div id="dot-plots" class="section level3 tabset tabset-fade tabset-pills">
<h3>Dot Plots</h3>
<div style="float:left;width:125px;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-18-1.png" width="96" /></p>
</div>
<p><strong>1 Quantitative Variable | 2+ Groups</strong></p>
<div id="overview-2" class="section level4">
<h4>Overview</h4>
<div style="padding-left:125px;">
<p>Depicts the actual values of each data point. Best for small sample sizes or for datasets where there are lots of repeated values. Histograms or boxplots are better alternatives for large sample sizes when there are few repeated values. Great for comparing the distribution of data across several groups or categories.</p>
</div>
<hr />
</div>
<div id="r-instructions-2" class="section level4">
<h4>R Instructions</h4>
<div style="padding-left:125px;">
<div class="tab">
<button class="tablinks" onclick="openTab(event, 'BaseDotplot')">
Base R
</button>
<button class="tablinks" onclick="openTab(event, 'ggplot2Dotplot')">
ggplot2
</button>
<button class="tablinks" onclick="openTab(event, 'plotlyDotplot')">
plotly
</button>
</div>
<div id="BaseDotplot" class="tabcontent">
<p>
<p>To make a dot plot in Base R use the code:</p>
<p><code>stripchart(object)</code></p>
<p>For side-by-side dotplots:</p>
<p><code>stripchart(object ~ group, data=NameOfYourData)</code></p>
<ul>
<li><code>object</code> must be a quantitative (or ordinal) variable, what R refers to as a “numeric vector.”</li>
<li><code>group</code> is a qualitative variable, which in R can be either a “character vector” or a “factor.”</li>
<li><code>NameOfYourData</code> is the name of the dataset containing <code>object</code> and <code>group</code>.</li>
</ul>
<p><strong>Example Code</strong></p>
<!-- Example Code 1 -->
<a href="javascript:showhide('dotplot0')">
<div class="hoverchunk">
<p><span class="tooltipr"> stripchart <span class="tooltiprtext">An R function “stripchart” used to create a dot plot.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> $ <span class="tooltiprtext">The $ allows us to access any variable from the airquality dataset.</span> </span><span class="tooltipr"> Temp <span class="tooltiprtext">“Temp” is a quantitative variable (numeric vector) from the “airquality” dataset.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the function.</span> </span><span class="tooltipr"> method=“stack”<br />
<span class="tooltiprtext">method= allows us to choose from the options “overplot”, “jitter”, and “stack”. The “stack” option stacks mutliple points that occur at the same location on top of each other. You can try the code yourself to see what “overplot” and “jitter” do.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the function.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="dotplot0" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-19-1.png" width="672" /></p>
</div>
<!-- Example Code 2 -->
<a href="javascript:showhide('dotplot1')">
<div class="hoverchunk">
<p><span class="tooltipr"> stripchart <span class="tooltiprtext">An R function “stripchart” used to create dot plots.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> Temp <span class="tooltiprtext">“Temp” is a quantitative variable (numeric vector) from the “airquality” dataset.</span> </span><span class="tooltipr"> ~ <span class="tooltiprtext">The ~ is used to tell R that you want a dot plot of the quantitative variable (“Temp”) for each group found in the qualitative variable (“Month”).</span> </span><span class="tooltipr"> Month <span class="tooltiprtext">“Month” is a qualitative variable (in this case a “numeric vector” defining months by 5, 6, 7, 8, and 9) from the “airquality” dataset.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the function.</span> </span><span class="tooltipr"> data=airquality <span class="tooltiprtext">data= is used to tell R that the “Temp” and “Month” variables are located in the <span style="font-weight:bold">airquality</span> dataset. Without this, R will not know where to find “Temp” and “Month” and the command will give an error.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the function.</span> </span><span class="tooltipr"> method=“stack”<br />
<span class="tooltiprtext">method= allows us to choose from the options “overplot”, “jitter”, and “stack”. The “stack” option stacks mutliple points that occur at the same location on top of each other. You can try the code yourself to see what “overplot” and “jitter” do.</span> </span><span class="tooltipr"> ) <span class="tooltiprtext">Functions always end with a closing parenthesis.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="dotplot1" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-20-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('dotplot2')">
<div class="hoverchunk">
<p><span class="tooltipr"> stripchart(Temp ~ Month <span class="tooltiprtext">This part of the code was explained already in the example code directly above this one.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the function.</span> </span><span class="tooltipr"> data=airquality <span class="tooltiprtext">data= is used to tell R that the “Temp” and “Month” variables are located in the <span style="font-weight:bold">airquality</span> dataset. Without this, R will not know where to find “Temp” and “Month” and the command will give an error.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the function.</span> </span><span class="tooltipr"> method=“stack”<br />
<span class="tooltiprtext">method= allows us to choose from the options “overplot”, “jitter”, and “stack”. The “stack” option stacks mutliple points that occur at the same location on top of each other. You can try the code yourself to see what “overplot” and “jitter” do.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> ylab=“Month of the Year” <span class="tooltiprtext">ylab= stands for “y label.” Use it to specify the text to print on the plot next to the y-axis. The desired text must always be contained in quotes.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> xlab=“Temperature” <span class="tooltiprtext">xlab= stands for “x label.” Use it to specify the text to print on the plot below the x-axis. The desired text must always be contained in quotes.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> main=“La Guardia Airport Daily Temperatures” <span class="tooltiprtext">main= stands for the “main label” of the plot, which is placed at the top center of the plot. The desired text must always be contained in quotes.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> col=“sienna” <span class="tooltiprtext">col= stands for the “color” of the plot. The color name “sienna” is an available color in R. Type colors() in the R Console to see more options. The color name must always be placed in quotes.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> pch=16 <span class="tooltiprtext">pch= stands for the “plotting character” of the plot. This plot uses the filled circle (option 16) as the plotting character. The options are 0, 1, 2, …, 25. Type ?pch in the R Console, and scroll down the help file half way to see what each option does.</span> </span><span class="tooltipr"> ) <span class="tooltiprtext">Functions always end with a closing parenthesis.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="dotplot2" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-21-1.png" width="672" /></p>
</div>
</p>
</div>
<div id="ggplot2Dotplot" class="tabcontent">
<p>
<p>To make a dot plot in R using the ggplot approach, first ensure:</p>
<p><code>library(ggplot2)</code></p>
<p>is loaded. Then,</p>
<p><code>ggplot(data, aes(x=groupsColumn, y=dataColumn) +</code></p>
<p> <code>geom_dotplot()</code></p>
<ul>
<li><code>data</code> is the name of your dataset.</li>
<li><code>groupsColumn</code> is a column of data from your dataset that is qualitative and represents the groups that should each have a boxplot.</li>
<li><code>dataColumn</code> is a column of data from your dataset that is quantitative.</li>
<li>The aesthetic helper function <code>aes(x= , y=)</code> is how you tell the gpplot to make the x-axis have the values in your <code>groupsColumn</code> of data, the y-axis become your <code>dataColumn</code>. <strong>Note</strong> <em>if <code>groupsColumn</code> is not a factor, use <code>factor(groupsColumn)</code> instead.</em></li>
<li>The geometry helper function <code>geom_dotplot()</code> causes the ggplot to become a dot plot.</li>
</ul>
<p><br></p>
<p><strong>Example Code</strong></p>
<p>Click to view. Hover to learn.</p>
<a href="javascript:showhide('dot1ggplot')">
<div class="hoverchunk">
<p><span class="tooltipr"> ggplot <span class="tooltiprtext">An R function “ggplot” used to create a framework for a graphic that will have elements added to it with the <code>+</code> sign.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> aes( <span class="tooltiprtext">The <code>aes</code> or “aesthetics” function allows you to tell the ggplot how it should appear. This includes things like what the y-axis should become.</span> </span><span class="tooltipr"> x=Temp <span class="tooltiprtext">“x=” declares which variable will become the x-axis of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the aes function.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the ggplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> geom_dotplot() <span class="tooltiprtext">The “geom_dotplot()” function causes the ggplot to become a dot plot. There are many other “geom_” functions that could be used.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="dot1ggplot" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-22-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('dot2ggplot')">
<div class="hoverchunk">
<p><span class="tooltipr"> ggplot <span class="tooltiprtext">An R function “ggplot” used to create a framework for a graphic that will have elements added to it with the <code>+</code> sign.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> aes( <span class="tooltiprtext">The <code>aes</code> or “aesthetics” function allows you to tell the ggplot how it should appear. This includes things like what the x-axis or y-axis should become.</span> </span><span class="tooltipr"> x=factor(Month), <span class="tooltiprtext">“x=” declares which variable will become the x-axis of the graphic. Use factor(Month) to change “Month”, which is numeric, into categories.</span> </span><span class="tooltipr"> y=Temp <span class="tooltiprtext">“y=” declares which variable will become the y-axis of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the aes function.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the ggplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> geom_dotplot( <span class="tooltiprtext">The “geom_dotplot()” function causes the ggplot to become a dot plot. There are many other “geom_” functions that could be used.</span> </span><span class="tooltipr"> binaxis = “y”, <span class="tooltiprtext">This tells the function that the y=Temp statement should be used as the quantitative data.</span> </span><span class="tooltipr"> stackdir = “up”, <span class="tooltiprtext">This causes the dots to be stacked on top of each other.</span> </span><span class="tooltipr"> position = “dodge”, <span class="tooltiprtext">This causes the dots to not overalap, i.e., “dodge each other.”</span> </span><span class="tooltipr"> dotsize = 0.75, <span class="tooltiprtext">Controls the size of the dots. You can make them larger with numbers greater than 1 and smaller with numbers less than 1.</span> </span><span class="tooltipr"> binwidth = 0.5 <span class="tooltiprtext">Controls how the dots are grouped, similar to the bins in a histogram.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the geom_dotplot function.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="dot2ggplot" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-23-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('dot3ggplot')">
<div class="hoverchunk">
<p><span class="tooltipr"> ggplot <span class="tooltiprtext">An R function “ggplot” used to create a framework for a graphic that will have elements added to it with the <code>+</code> sign.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> aes( <span class="tooltiprtext">The <code>aes</code> or “aesthetics” function allows you to tell the ggplot how it should appear. This includes things like what the x-axis or y-axis should become.</span> </span><span class="tooltipr"> x=factor(Month), <span class="tooltiprtext">“x=” declares which variable will become the x-axis of the graphic. Use factor(Month) to change “Month”, which is numeric, into categories.</span> </span><span class="tooltipr"> y=Temp <span class="tooltiprtext">“y=” declares which variable will become the y-axis of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the aes function.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the ggplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> coord_flip( ) <span class="tooltiprtext">The “coord_flip()” function causes the ggplot to reverse the axes when drawing the plot. However, all commands must be given as if the plot were to be drawn without coord_flip(), then coord_flip() is applied.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> geom_dotplot( <span class="tooltiprtext">The “geom_dotplot()” function causes the ggplot to become a dot plot. There are many other “geom_” functions that could be used.</span> </span><span class="tooltipr"> binaxis = “y”, <span class="tooltiprtext">This tells the function that the y=Temp statement should be used as the quantitative data.</span> </span><span class="tooltipr"> stackdir = “up”, <span class="tooltiprtext">This causes the dots to be stacked on top of each other.</span> </span><span class="tooltipr"> position = “dodge”, <span class="tooltiprtext">This causes the dots to not overalap, i.e., “dodge each other.”</span> </span><span class="tooltipr"> dotsize = 0.75, <span class="tooltiprtext">Controls the size of the dots. You can make them larger with numbers greater than 1 and smaller with numbers less than 1.</span> </span><span class="tooltipr"> binwidth = 0.5 <span class="tooltiprtext">Controls how the dots are grouped, similar to the bins in a histogram.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the geom_dotplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> labs( <span class="tooltiprtext">The “labs” function is used to add labels to the plot, like a main title, x-label and y-label.</span> </span><span class="tooltipr"> title=“La Guardia Airport Daily Mean Temperature”, <span class="tooltiprtext">The “title=” command allows you to control the main title at the top of the graphic.</span> </span><span class="tooltipr"> x=“Month of the Year”, <span class="tooltiprtext">The “x=” command allows you to control the x-label of the graphic.</span> </span><span class="tooltipr"> y=“Daily Mean Temperature” <span class="tooltiprtext">The “y=” command allows you to control the y-label of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the labs function.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="dot3ggplot" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-24-1.png" width="672" /></p>
</div>
</p>
</div>
<div id="plotlyDotplot" class="tabcontent">
<p>
Not yet available.
</p>
</div>
</div>
<hr />
</div>
</div>
<div id="scatterplots" class="section level3 tabset tabset-fade tabset-pills">
<h3>Scatterplots</h3>
<div style="float:left;width:125px;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-25-1.png" width="96" /></p>
</div>
<p><strong>2 Quantitative Variables</strong></p>
<div id="overview-3" class="section level4">
<h4>Overview</h4>
<div style="padding-left:125px;">
<p>Depicts the actual values of the data points, which are <span class="math inline">\((x,y)\)</span> pairs. Works well for small or large sample sizes. Visualizes well the <a href="NumericalSummaries.html#correlation">correlation</a> between the two variables. Should be used in linear regression contexts whenever possible.</p>
</div>
<hr />
</div>
<div id="r-instructions-3" class="section level4">
<h4>R Instructions</h4>
<div style="padding-left:125px;">
<div class="tab">
<button class="tablinks" onclick="openTab(event, 'BaseScatterplot')">
Base R
</button>
<button class="tablinks" onclick="openTab(event, 'ggplotScatterplot')">
ggplot2
</button>
<button class="tablinks" onclick="openTab(event, 'plotlyScatterplot')">
plotly
</button>
</div>
<div id="BaseScatterplot" class="tabcontent">
<p>
<p>To make a scatterplot in R use the code:</p>
<p><code>plot(y ~ x, data=NameOfYourData)</code></p>
<ul>
<li><code>y</code> is the quantitative response variable, i.e., “numeric vector.”</li>
<li><code>x</code> is the quantitative explanatory variable, i.e., “numeric vector.”</li>
<li><code>NameOfYourData</code> is the name of the dataset containing <code>y</code> and <code>x</code>.</li>
</ul>
<p>Note: <code>plot(object)</code> where <code>object</code> is a “numeric vector” will create a time series plot, which is sometimes useful.</p>
<p><strong>Example Code</strong></p>
<!-- Example Code 1 -->
<a href="javascript:showhide('scatterplot1')">
<div class="hoverchunk">
<p><span class="tooltipr"> plot <span class="tooltiprtext">An R function “plot” used to create a scatterplot, or in this case a time series plot because only one quantitative variable is being supplied to the function.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> $ <span class="tooltiprtext">The $ allows us to access any variable from the airquality dataset.</span> </span><span class="tooltipr"> Temp <span class="tooltiprtext">“Temp” is a quantitative variable (numeric vector) from the “airquality” dataset.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the function.</span> </span><span class="tooltipr"> type=“l”<br />
<span class="tooltiprtext">type= allows us to choose from the options “p” for points, “l” for lines, and “b” for both. There are also other options that could be chosen, type ?plot in the R Console to learn about them.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the function.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="scatterplot1" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-26-1.png" width="672" /></p>
</div>
<!-- Example Code 2 -->
<a href="javascript:showhide('scatterplot2')">
<div class="hoverchunk">
<p><span class="tooltipr"> plot <span class="tooltiprtext">An R function “plot” used to create a scatterplot.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> Temp <span class="tooltiprtext">“Temp” is a quantitative variable (numeric vector) from the “airquality” dataset that is being used as the response variable (y-axis) for this plot.</span> </span><span class="tooltipr"> ~ <span class="tooltiprtext">The ~ is used to tell R that you want a scatterplot with the quantitative variable “Temp” on the y-axis and the qauntitative variable “Month” on the x-axis.</span> </span><span class="tooltipr"> Wind <span class="tooltiprtext">“Wind” is a quantitative variable (numeric vector) from the “airquality” dataset that is being used as the explanatory variable (x-axis) for this plot.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the function.</span> </span><span class="tooltipr"> data=airquality <span class="tooltiprtext">data= is used to tell R that the “Temp” and “Month” variables are located in the <span style="font-weight:bold">airquality</span> dataset. Without this, R will not know where to find “Temp” and “Month” and the command will give an error.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the function.</span> </span><span class="tooltipr"> pch=8 <span class="tooltiprtext">pch= stands for the “plotting character” of the plot. This plot uses the star shape (option 8) as the plotting character. The options are 0, 1, 2, …, 25. Type ?pch in the R Console, and scroll down the help file half way to see what each option does.</span> </span><span class="tooltipr"> ) <span class="tooltiprtext">Functions always end with a closing parenthesis.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="scatterplot2" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-27-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('scatterplot3')">
<div class="hoverchunk">
<p><span class="tooltipr"> plot(Temp ~ Wind <span class="tooltiprtext">This part of the code was explained already in the example code directly above this one.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the function.</span> </span><span class="tooltipr"> data=airquality <span class="tooltiprtext">data= is used to tell R that the “Temp” and “Month” variables are located in the <span style="font-weight:bold">airquality</span> dataset. Without this, R will not know where to find “Temp” and “Month” and the command will give an error.</span> </span><span class="tooltipr"> , <br />
<span class="tooltiprtext">The “,” is required to start specifying additional commands for the function.</span> </span><span class="tooltipr"> xlab=“Daily Wind Speed (mph)” <span class="tooltiprtext">xlab= stands for “x label.” Use it to specify the text to print on the plot below the x-axis. The desired text must always be contained in quotes.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> ylab=“Temperature” <span class="tooltiprtext">ylab= stands for “y label.” Use it to specify the text to print on the plot next to the y-axis. The desired text must always be contained in quotes.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> main=“La Guardia Airport (May - Sep)” <span class="tooltiprtext">main= stands for the “main label” of the plot, which is placed at the top center of the plot. The desired text must always be contained in quotes.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> col=“ivory3” <span class="tooltiprtext">col= stands for the “color” of the plot. The color name “ivory3” is an available color in R. Type colors() in the R Console to see more options. The color name must always be placed in quotes.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma is used to separate each additional command to a function.</span> </span><span class="tooltipr"> pch=18 <span class="tooltiprtext">pch= stands for the “plotting character” of the plot. This plot uses the filled diamond (option 18) as the plotting character. The options are 0, 1, 2, …, 25. Type ?pch in the R Console, and scroll down the help file half way to see what each option does.</span> </span><span class="tooltipr"> ) <span class="tooltiprtext">Functions always end with a closing parenthesis.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="scatterplot3" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-28-1.png" width="672" /></p>
</div>
<p><strong>pch Options</strong></p>
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-29-1.png" width="672" /></p>
</p>
</div>
<div id="ggplotScatterplot" class="tabcontent">
<p>
<p>To make a scatterplot in R using the ggplot approach, first ensure:</p>
<p><code>library(ggplot2)</code></p>
<p>is loaded. Then,</p>
<p><code>ggplot(data, aes(x=dataColumn1, y=dataColumn2) +</code></p>
<p> <code>geom_point()</code></p>
<ul>
<li><code>data</code> is the name of your dataset.</li>
<li><code>dataColumn1</code> is a column of data from your dataset that is quantitative and will be used as the explanatory variable.</li>
<li><code>dataColumn2</code> is a column of data from your dataset that is quantitative and will be used as the response variable.</li>
<li>The aesthetic helper function <code>aes(x= , y=)</code> is how you tell the gpplot to make the x-axis have the values in your <code>dataColumn1</code> of data, the y-axis become your <code>dataColumn2</code>.</li>
<li>The geometry helper function <code>geom_point()</code> causes the ggplot to become a scatterplot.</li>
</ul>
<p><br></p>
<p><strong>Example Code</strong></p>
<p>Click to view. Hover to learn.</p>
<a href="javascript:showhide('scatter1ggplot')">
<div class="hoverchunk">
<p><span class="tooltipr"> ggplot <span class="tooltiprtext">An R function “ggplot” used to create a framework for a graphic that will have elements added to it with the <code>+</code> sign.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> aes( <span class="tooltiprtext">The <code>aes</code> or “aesthetics” function allows you to tell the ggplot how it should appear. This includes things like what the x-axis or y-axis should become.</span> </span><span class="tooltipr"> x=Wind, <span class="tooltiprtext">“x=” declares which variable will become the x-axis of the graphic, the explanatory variable.</span> </span><span class="tooltipr"> y=Temp <span class="tooltiprtext">“y=” declares which variable will become the y-axis of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the aes function.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the ggplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> geom_point( <span class="tooltiprtext">The “geom_point()” function causes the ggplot to become a scatterplot. There are many other “geom_” functions that could be used.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the geom_point function.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="scatter1ggplot" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-30-1.png" width="672" /></p>
</div>
<a href="javascript:showhide('scatter2ggplot')">
<div class="hoverchunk">
<p><span class="tooltipr"> ggplot <span class="tooltiprtext">An R function “ggplot” used to create a framework for a graphic that will have elements added to it with the <code>+</code> sign.</span> </span><span class="tooltipr"> ( <span class="tooltiprtext">Parenthesis to begin the function. Must touch the last letter of the function.</span> </span><span class="tooltipr"> airquality <span class="tooltiprtext">“airquality” is a dataset. Type “View(airquality)” in R to see it.</span> </span><span class="tooltipr"> , <span class="tooltiprtext">The comma allows us to specify optional commands to the function. The space after the comma is not required. It just looks nice.</span> </span><span class="tooltipr"> aes( <span class="tooltiprtext">The <code>aes</code> or “aesthetics” function allows you to tell the ggplot how it should appear. This includes things like what the x-axis or y-axis should become.</span> </span><span class="tooltipr"> x=Wind, <span class="tooltiprtext">“x=” declares which variable will become the x-axis of the graphic, the explanatory variable.</span> </span><span class="tooltipr"> y=Temp <span class="tooltiprtext">“y=” declares which variable will become the y-axis of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the aes function.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the ggplot function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> geom_point( <span class="tooltiprtext">The “geom_point()” function causes the ggplot to become a scatterplot. There are many other “geom_” functions that could be used.</span> </span><span class="tooltipr"> color = “ivory3”, <span class="tooltiprtext">Controls the color of the dots.</span> </span><span class="tooltipr"> pch = 18 <span class="tooltiprtext">Controls the type of plotting character to be used in the plot.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the geom_point function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> labs( <span class="tooltiprtext">The “labs” function is used to add labels to the plot, like a main title, x-label and y-label.</span> </span><span class="tooltipr"> title=“La Guardia Airport (May - Sep)”, <span class="tooltiprtext">The “title=” command allows you to control the main title at the top of the graphic.</span> </span><span class="tooltipr"> x=“Daily Average Wind Speed (mph)”, <span class="tooltiprtext">The “x=” command allows you to control the x-label of the graphic.</span> </span><span class="tooltipr"> y=“Daily Mean Temperature” <span class="tooltiprtext">The “y=” command allows you to control the y-label of the graphic.</span> </span><span class="tooltipr"> )<br />
<span class="tooltiprtext">Closing parenthsis for the labs function.</span> </span><span class="tooltipr"> + <span class="tooltiprtext">The addition symbol <code>+</code> is used to add further elements to the ggplot.</span> </span><br/><span class="tooltipr"> theme_bw()<br />
<span class="tooltiprtext">Changes the “theme” or look of the plot to “black” and “white”.</span> </span><span class="tooltipr"> <br />
<span class="tooltiprtext">Press Enter to run the code.</span> </span><span class="tooltipr" style="float:right;"> … <span class="tooltiprtext">Click to View Output.</span> </span></p>
</div>
</a>
<div id="scatter2ggplot" style="display:none;">
<p><img src="GraphicalSummaries_files/figure-html/unnamed-chunk-31-1.png" width="672" /></p>
</div>
</p>