-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex_GEOG364-22_L1Basics.html
989 lines (896 loc) · 29.6 KB
/
index_GEOG364-22_L1Basics.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="author" content=" ¶ Dr Helen Greatrex ¶ " />
<title>Lab 1: Introduction to R</title>
<script src="site_libs/header-attrs-2.17/header-attrs.js"></script>
<script src="site_libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/flatly.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>
<style>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;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="site_libs/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="site_libs/tocify-1.9.1/jquery.tocify.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<link href="site_libs/highlightjs-9.12.0/textmate.css" rel="stylesheet" />
<script src="site_libs/highlightjs-9.12.0/highlight.js"></script>
<script src="site_libs/kePrint-0.0.1/kePrint.js"></script>
<link href="site_libs/lightable-0.0.1/lightable.css" rel="stylesheet" />
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<style type="text/css">code{white-space: pre;}</style>
<script type="text/javascript">
if (window.hljs) {
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
if (document.readyState && document.readyState === "complete") {
window.setTimeout(function() { hljs.initHighlighting(); }, 0);
}
}
</script>
<link rel="stylesheet" href="styles.css" type="text/css" />
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
details > summary > p:only-child {
display: inline;
}
pre code {
padding: 0;
}
</style>
<style type="text/css">
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #adb5bd;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
border-radius: 6px 0 6px 6px;
}
</style>
<script type="text/javascript">
// 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 the anchor link active (and if it's in a dropdown, also mark that active)
var dropdown = menuAnchor.closest('li.dropdown');
if (window.bootstrap) { // Bootstrap 4+
menuAnchor.addClass('active');
dropdown.find('> .dropdown-toggle').addClass('active');
} else { // Bootstrap 3
menuAnchor.parent().addClass('active');
dropdown.addClass('active');
}
// Navbar adjustments
var navHeight = $(".navbar").first().height() + 15;
var style = document.createElement('style');
var pt = "padding-top: " + navHeight + "px; ";
var mt = "margin-top: -" + navHeight + "px; ";
var css = "";
// offset scroll position for anchor links (for fixed navbar)
for (var i = 1; i <= 6; i++) {
css += ".section h" + i + "{ " + pt + mt + "}\n";
}
style.innerHTML = "body {" + pt + "padding-bottom: 40px; }\n" + css;
document.head.appendChild(style);
});
</script>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "\e259";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "\e258";
font-family: 'Glyphicons Halflings';
border: none;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
@media print {
.toc-content {
/* see https://github.com/w3c/csswg-drafts/issues/4434 */
float: right;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
}
.tocify .list-group-item {
border-radius: 0px;
}
.tocify-subheader {
display: inline;
}
.tocify-subheader .tocify-item {
font-size: 0.95em;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
<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-bs-toggle="collapse" data-target="#navbar" data-bs-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">GEOG-364</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="index.html">Home</a>
</li>
<li>
<a href="index_GEOG364-22_Tutorial_R.html">R-TUTORIAL</a>
</li>
<li>
<a href="ClassExampleMoran.html">CLASS EXAMPLE MORAN'S I LAB 6</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Labs
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="index_GEOG364-22_L1Basics.html">Lab 1: R-Basics</a>
</li>
<li>
<a href="index_GEOG364-22_L2EDA.html">Lab 2: Exploratory Analysis</a>
</li>
<li>
<a href="index_GEOG364-22_L3Data.html">Lab 3: Data Wrangling</a>
</li>
<li>
<a href="index_GEOG364-22_L4Firefly.html">Lab 4: Spatial Wrangling</a>
</li>
<li>
<a href="index_GEOG364-22_L5Census.html">Lab 5: Census Data</a>
</li>
<li>
<a href="index_GEOG364-22_L6SoviMoran.html">Lab 6: Moran SOVI</a>
</li>
<li>
<a href="index_GEOG364-22_L7Point.html">Lab 7: Point Pattern</a>
</li>
<li>
<a href="index_GEOG364-22_Temp.html">TEMPERATURE LAB</a>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div id="header">
<h1 class="title toc-ignore">Lab 1: Introduction to R</h1>
<h3 class="subtitle"><h5 style="font-style:normal"> ¶ GEOG-364 -
Geospatial Analysis ¶ </h4></h3>
<h4 class="author"><h5 style="font-style:normal"> ¶ Dr Helen Greatrex ¶
</h4></h4>
</div>
<style>
p.comment {
background-color: #DBDBDB;
padding: 10px;
border: 1px solid black;
margin-left: 0px;
border-radius: 5px;
font-style: normal;
}
h1.title {
font-weight: bold;
font-family: Arial;
}
h2.title {
font-family: Arial;
}
</style>
<style type="text/css">
#TOC {
font-size: 12px;
font-family: Arial;
}
</style>
<p><br />
</p>
<div id="welcome-to-lab-1" class="section level1" number="1">
<h1><span class="header-section-number">1</span> Welcome to Lab 1!</h1>
<p>By the end of this week’s lab, you will be able to:</p>
<ol style="list-style-type: decimal">
<li>Get comfortable with the lab format & how to work through
them</li>
<li>Know how to get help</li>
<li>Get familiar with the RStudio interface</li>
<li>Run your first programming commands</li>
<li>Put everything together into an interactive markdown website (like
this guide)</li>
<li>Understand the process for submitting assignments</li>
</ol>
<div id="overview" class="section level2" number="1.1">
<h2><span class="header-section-number">1.1</span> Overview</h2>
<p>There are 7 labs in this course. Each one will build on the last one,
with support provided in a series of tutorials (see the tutorials tab).
You should NOT submit the tutorial work. We will work through the
tutorials together and then your job is to submit the requirements on
this page.</p>
<p><strong>If the labs are causing major problems with your computer or
your computer hardware is struggling (or you have any other software
issue), Talk to Dr Greatrex</strong>. We can fix this and there are
other options for “online R” that you can use.</p>
<p><a
href="https://teams.microsoft.com/l/channel/19%3aSt_BHDOZLAgR9dsxgB2ly3-O77CnxyzoGFVYc0fpUTM1%40thread.tacv2/General?groupId=5e74a2d7-3a10-409a-b38d-50875fd02455&tenantId=7cf48d45-3ddb-4389-a9c1-c115526eb52e">CLICK
HERE FOR LAB HELP</a></p>
<p>See canvas for submission dates</p>
<p><br></p>
</div>
<div id="instructions" class="section level2" number="1.2">
<h2><span class="header-section-number">1.2</span> Instructions</h2>
<p><br></p>
<div id="download-or-update-rr-studio" class="section level3"
number="1.2.1">
<h3><span class="header-section-number">1.2.1</span> Download or update
R/R-studio</h3>
<ul>
<li>Read <a
href="https://psu-spatial.github.io/geog364-2022/GEOG364_T1_R_Basics.html#11_What_are_R_and_R-Studio">Tutorial
1.1</a>.<br><br></li>
<li>Install BOTH R and R-Studio, or create an R-Studio Cloud account.
This is covered in <a
href="https://psu-spatial.github.io/geog364-2022/T1_R_Basics.html#12_Accessing_R__R-Studio">Tutorial
1.2</a>.</li>
</ul>
<p><br></p>
</div>
<div id="getting-started-in-r" class="section level3" number="1.2.2">
<h3><span class="header-section-number">1.2.2</span> Getting started in
R</h3>
<p>Here you will learn about the R interface. You do not need to
save/submit this work,</p>
<ul>
<li><p>Work through <a
href="https://psu-spatial.github.io/geog364-2022/T1_R_Basics.html#13_Getting_started">Tutorial1.3</a>
to open R-studio and change your settings.<br><br></p></li>
<li><p>Use <a
href="https://psu-spatial.github.io/geog364-2022/T1_R_Basics.html#2_R-Projects_and_Packages">Tutorial
2.1</a> to make your first R-project called
GEOG364-Lab1-Project<br></p></li>
<li><p>[OPTIONAL BUT RECOMMENDED] Now work through <a
href="https://psu-spatial.github.io/geog364-2022/T1_R_Basics.html#3_Basic_commands">Tutorial
3</a> to get used to the basics<br></p></li>
<li><p>Now go back to <a
href="https://psu-spatial.github.io/geog364-2022/T1_R_Basics.html#22_R-Packages">Tutorial
2B</a> to understand what an R-Package is and to install the code
packages/libraries we will need for this course.<br></p></li>
</ul>
<p><br></p>
</div>
<div id="start-markdown" class="section level3" number="1.2.3">
<h3><span class="header-section-number">1.2.3</span> Start Markdown</h3>
<ul>
<li>[OPTIONAL BUT HIGHLY ENCOURAGED] Work through <a
href="https://psu-spatial.github.io/Geog364-2021/pg_Tut4_markdown.html">Tutorial
4</a> to make your first Markdown document. Save and close - this was
for your reference!</li>
</ul>
<p><br></p>
</div>
<div id="lab-challenge" class="section level3" number="1.2.4">
<h3><span class="header-section-number">1.2.4</span> Lab challenge!</h3>
<p>Everything above was for your own learning - you do not need to
submit any of it. Now we will start the actual lab you will submit.
Consider printing this out and checking off each step one by one.</p>
<p><br></p>
<div id="reopen-r-studio" class="section level4 unnumbered">
<h4 class="unnumbered">1: Reopen R studio</h4>
<p>First, see if you remember how to close and re-open R studio.
<br></p>
<p>Save everything then close down R studio.To re-open, do not reopen R
from the programmes folder or icon!</p>
<p><strong>INSTEAD, GO TO THE LAB 1 FOLDER ON YOUR COMPUTER AND DOUBLE
CLICK THE .RPROJ FILE CALLED GEOG364-Lab1-Project!</strong>.</p>
<p>This will get you straight back into your lab folder for you to carry
on.</p>
<p><br></p>
</div>
<div id="make-lab-markdown" class="section level4 unnumbered">
<h4 class="unnumbered">2: Make lab-Markdown</h4>
<p>Create a new <strong>RMarkdown document</strong> called
<code>GEOG364-Lab1-PSUID.Rmd</code>. e.g. for me
<em>GEOG364-Lab1-hlg5155.Rmd</em>. <br></p>
<p>Delete all the text/code below line 11 (e.g. everything from “R
Markdown onward”)</p>
<p><br></p>
</div>
<div id="adding-paragraphs" class="section level4 unnumbered">
<h4 class="unnumbered">3: Adding paragraphs</h4>
<p>You might find it easier to use the markdown visual text editor. <br>
Click the “A” symbol at the top right to switch (instructions here:<a
href="https://psu-spatial.github.io/geog364-2022/T1_R_Basics.html#46_Formatting_text">Tutorial
4.6</a>)</p>
<ul>
<li><p>In the white text area, create a level 1 heading called
<em>“Introduction to GEOG-364”</em>. For a cheat sheet to help with
this, move your mouse to the top of the page, click the help menu, then
click Markdown Quick reference, or see <a
href="https://psu-spatial.github.io/geog364-2022/T1_R_Basics.html#46_Formatting_text">Tutorial
4.6</a>.</p></li>
<li><p>Leave a blank line, then use the GEOG-364 syllabus to describe
the course late policy in your own words (e.g. you’re writing about this
in the white space).</p></li>
<li><p>Press “knit” at the top of the screen. If you haven’t made a
mistake a pop up should appear with a html file and your edits. If you
have a made a mistake, stop and fix before continuing.</p></li>
</ul>
<p><br></p>
</div>
<div id="code-showcase" class="section level4 unnumbered">
<h4 class="unnumbered">4: Code showcase</h4>
<p><img src="Figures/Lab1_Basics_CodeChunk.png" width="954" />
<br<</p>
<p>Leave another blank line and add a new Level 1 heading called
<em>“Code Showcase”</em>. Add a blank line afterwards too. Create a code
chunk (). Inside use R code to calculate the following <br><br></p>
<ul>
<li><p>103<sup>3</sup> (e.g <code>103*103*103</code>, or
<code>103^3</code>) <br></p></li>
<li><p>The co-sine of your age (google is your friend, google R function
for cosine) <br></p></li>
<li><p>Use R code to work out how many characters are in <a
href="https://www.bbcamerica.com/anglophenia/2015/09/how-to-pronounce-the-longest-place-name-in-the-u-k">the
longest town name in Wales</a>
<em>Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch</em>.
<br></p>
<ul>
<li>Hint 1, remember you can copy paste this into your code. <br></li>
<li>Hint 2.. your tutorials and quote marks!<br></li>
<li>Hint 3.. you can google any R command, try gooling R command for
number of characters in a word.<br><br></li>
</ul></li>
</ul>
<p>Press “knit” at the top of the screen. If you haven’t made a mistake
a pop up should appear with a html file and your edits. If you have a
made a mistake, stop and fix before continuing.</p>
<p><br></p>
</div>
<div id="packages" class="section level4 unnumbered">
<h4 class="unnumbered">5. Packages</h4>
<p>If you have run through the tutorials, you should have installed all
the packages you need for this course.</p>
<p><strong>IF NOT GO AND DO THE BULK INSTALL IN <a
href="https://psu-spatial.github.io/geog364-2022/T1_R_Basics.html#22_R-Packages">Tutorial
2.2</a>]</strong></p>
<p>You only need to <em>download</em> the packages once, but we still
need to load them every time we need a command in that package (in the
same way you only download your banking app once from the app store but
need to press the icon every time you want to use it).</p>
<ul>
<li>Always INSTALL/DOWNLOAD packages using a menu or in the console</li>
<li>Always LOAD packages in a code-chunk in your script (as we need to
do tihs every time)</li>
</ul>
<div id="do-this-part-even-if-you-did-tutorial-2" class="section level5"
number="1.2.4.0.1">
<h5><span class="header-section-number">1.2.4.0.1</span> DO THIS PART
EVEN IF YOU DID TUTORIAL 2!</h5>
<p>Today we will be using commands from the skimr package, the ggplot2
package and the plotly package.</p>
<p>Somewhere near the topc of your script, make a new code chunk and add
this code. Remember to run the code chunk! (pressing the green arrow, or
go to the run button on the top right and press Run All)</p>
<pre class="r"><code>library(tidyverse)
library(skimr)
library(ggplot2)
library(plotly)
library(ggpubr)</code></pre>
<p><br></p>
</div>
</div>
<div id="data-summary" class="section level4 unnumbered">
<h4 class="unnumbered">6: Data summary</h4>
<p>Part 6 is taken from this tutorial (<a
href="https://r4ds.had.co.nz/data-visualisation.html"
class="uri">https://r4ds.had.co.nz/data-visualisation.html</a>).</p>
<p>Leave a blank line, and create a new heading called <em>Car
Analysis</em>. Leave a blank line afterwards too.</p>
<p>We’re going to work with another table of data that’s already
pre-loaded into R, this time inside the ggplot2 package. Make sure you
have run the library code chunk. Now, type the <code>?mpg</code> command
in the console. This will bring up the help file. If it can’t find the
dataset, you need to load the ggplot2 package using the library command
or install ggplot2.</p>
<p>Now look at the data itself. In the <strong>CONSOLE</strong>, type
<code>View(mpg)</code>. This will open a new tab with the spreadsheet
itself. DO NOT PUT THE VIEW COMMAND IN A CODE CHUNK (it messes up you
making your final file)</p>
<p>Also look at the summary statistics. Leave a blank line and create a
new code chunk containing the following code</p>
<pre class="r"><code># mpg comes from the ggplot2 package
# skim comes from the skimr package
skim(mpg)</code></pre>
<p>and finally, let’s make your first plot.</p>
<p>Among the variables in the mpg dataset are:</p>
<ul>
<li><p><code>displ</code>, a car’s engine size, in litres.</p></li>
<li><p><code>hwy</code>, a car’s fuel efficiency on the highway, in
miles per gallon (mpg). A car with a low fuel efficiency consumes more
fuel than a car with a high fuel efficiency when they travel the same
distance.</p></li>
<li><p><code>class</code>, the class of car e.g. mini, SUV, pick
up..</p></li>
</ul>
<p>To make a nice looking plot, let’s use the ggplot package rather than
the basic r commands.</p>
<pre class="r"><code># ggplotly comes from the plotly package
# Choose the dataset and tell R the columns to plot
p <- ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, color = class))
ggplotly(p) # Plot interactively</code></pre>
<p>Now below your code, answer the following questions. Make your
answers neat using things like, ysub headings, or bold/italic text or
bullet points (see that R cheatsheet).</p>
<p>Press knit a lot! Check you haven’t made a mistake, check it all
works.</p>
<p><strong>QUESTION 6A</strong></p>
<p>Based on this dataset, design me a study of your choice - completing
this template. There are lots of possible studies, so choose your own!
You do not have to do any analysis, I’m asking you to do this so you can
prove you understand the concepts.</p>
<ol style="list-style-type: decimal">
<li>The object of observation:</li>
<li>The object of analysis for your particular study:</li>
<li>The population:</li>
<li>List the available variables:</li>
<li>Your response variable:</li>
<li>What are you hoping to find out?</li>
</ol>
<p><strong>QUESTION 6B</strong></p>
<p>What is the mean/average manufacturing year of the car models in the
dataset?</p>
<p><strong>QUESTION 6C</strong></p>
<p>As fully as possible, describe the relationship between car’s engine
size and its fuel efficiency on the highway</p>
<p><br></p>
</div>
<div id="above-beyond" class="section level4 unnumbered">
<h4 class="unnumbered">7. Above & beyond</h4>
<p>Remember that an A is 94%, so you can ignore this section and still
easily get an A.</p>
<p>But here is your time to shine. Also, if you are struggling in
another part of the lab, you can use this to gain back points.</p>
<p><strong>To get the final 4 marks in the lab, you need to show me
something new, e.g. you need to go above and beyond the lab questions in
some way.</strong></p>
<ul>
<li>You get 2/4 for doing something new in any way</li>
<li>You get 4/4 for something really impressive or multiple small
things.</li>
</ul>
<p><strong>Tell us at the end of your R script what you did or you do
not get the marks!</strong></p>
<p>Here in lab 1, maybe you added in different text formats to make your
lab script more clear (bold/italic etc). Maybe you worked out how to add
axis labels to ggplot (note, it’s a pain), maybe you used nested
headings or sub-headings, or worked out how to add a table of
contents.</p>
<p>Or here are some ideas…</p>
<ul>
<li><a
href="https://cran.r-project.org/web/packages/dplyr/vignettes/dplyr.html"
class="uri">https://cran.r-project.org/web/packages/dplyr/vignettes/dplyr.html</a></li>
</ul>
<p><br> <br></p>
</div>
</div>
</div>
<div id="submitting-your-lab" class="section level2" number="1.3">
<h2><span class="header-section-number">1.3</span> Submitting your
Lab</h2>
<p>Remember to save your work throughout and to spell check your writing
(next to the save button). Now, press the knit button again. If you have
not made any mistakes in the code then R should create a html file in
your lab 1 folder which includes your answers. If you look at your lab 1
folder, you should see this there - complete with a very recent
time-stamp.</p>
<p>In that folder, double click on the html file. This will open it in
your browser. CHECK THAT THIS IS WHAT YOU WANT TO SUBMIT.</p>
<p>If you are on R studio cloud, see Tutorial 1 for how to download your
files</p>
<p>Now go to Canvas and submit BOTH your html and your .Rmd file in Lab
1.</p>
<p><img src="Figures/Lab_ToSubmit.png" width="1673" /></p>
<p><br></p>
</div>
<div id="lab-1-submission-check-list" class="section level2"
number="1.4">
<h2><span class="header-section-number">1.4</span> Lab 1 submission
check-list</h2>
<p>See the table below for what this means - 100% is hard to get!</p>
<p><strong>HTML FILE SUBMISSION - 8 marks</strong></p>
<p><strong>RMD CODE SUBMISSION - 8 marks</strong></p>
<p><strong>MARKDOWN/CODE STYLE - 10 MARKS</strong></p>
<p>Your code and document is neat and easy to read. LOOK AT YOUR HTML
FILE IN YOUR WEB-BROWSER BEFORE YOU SUBMIT. There is also a spell check
next to the save button. You have written your answers below the
relevant code chunk in full sentences in a way that is easy to find and
grade. For example, you have written in full sentences, it is clear what
your answers are referring to.</p>
<p><strong>Introduction to GEOG-364: 10 MARKS</strong></p>
<p>You have described the lab late policy clearly in a way I could share
with a new student.</p>
<p><strong>Code Showcase: 20 MARKS</strong></p>
<p>You have managed to successfully complete all the code challenges</p>
<p><strong>Car analysis: 30 MARKS</strong></p>
<p>You included all the code and successfully answered the 3 questions,
providing reasoning where appropriate</p>
<p><strong>Above and beyond: 4 MARKS</strong></p>
<p>Here you need to go above and beyond the lab questions in some way.
Here in lab 1, maybe you added in different text formats to make your
lab script more clear (bold/italic etc). Maybe you worked out how to add
axis labels to ggplot (note, it’s a pain), maybe you used nested
headings or sub-headings, or worked out how to add a table of
contents.</p>
<p>You get 2/4 for doing something new in any way and 4/4 for something
really impressive or multiple small things.</p>
<p>[100 marks total]</p>
<p>Overall, here is what your lab should correspond to:</p>
<table class=" lightable-classic-2 table table-striped table-hover table-responsive" style="font-family: "Arial Narrow", "Source Sans Pro", sans-serif; margin-left: auto; margin-right: auto; margin-left: auto; margin-right: auto;">
<thead>
<tr>
<th style="text-align:left;">
Grade
</th>
<th style="text-align:left;">
% Mark
</th>
<th style="text-align:left;">
Rubric
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
A*
</td>
<td style="text-align:left;">
98-100
</td>
<td style="text-align:left;">
Exceptional. Not only was it near perfect, but the graders learned
something. THIS IS HARD TO GET.
</td>
</tr>
<tr>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
96+
</td>
<td style="text-align:left;">
You went above and beyond
</td>
</tr>
<tr>
<td style="text-align:left;">
A
</td>
<td style="text-align:left;">
94+:
</td>
<td style="text-align:left;">
Everything asked for with high quality. Class example
</td>
</tr>
<tr>
<td style="text-align:left;">
A-
</td>
<td style="text-align:left;">
90+
</td>
<td style="text-align:left;">
The odd minor mistake, All code done but not written up in full
sentences etc. A little less care
</td>
</tr>
<tr>
<td style="text-align:left;">
B+
</td>
<td style="text-align:left;">
87+
</td>
<td style="text-align:left;">
More minor mistakes. Things like missing units, getting the odd
question wrong, no workings shown
</td>
</tr>
<tr>
<td style="text-align:left;">
B
</td>
<td style="text-align:left;">
84+
</td>
<td style="text-align:left;">
Solid work but the odd larger mistake or missing answer. Completely
misinterpreted something, that type of thing
</td>
</tr>
<tr>
<td style="text-align:left;">
B-
</td>
<td style="text-align:left;">
80+
</td>
<td style="text-align:left;">
Starting to miss entire/questions sections, or multiple larger mistakes.
Still a solid attempt.
</td>
</tr>
<tr>
<td style="text-align:left;">
C+
</td>
<td style="text-align:left;">
77+
</td>
<td style="text-align:left;">
You made a good effort and did some things well, but there were a lot of
problems. (e.g. you wrote up the text well, but messed up the code)
</td>
</tr>
<tr>
<td style="text-align:left;">
C
</td>
<td style="text-align:left;">
70+
</td>
<td style="text-align:left;">
It’s clear you tried and learned something. Just attending labs will
get you this much as we can help you get to this stage
</td>
</tr>
<tr>
<td style="text-align:left;">
D
</td>
<td style="text-align:left;">
60+
</td>
<td style="text-align:left;">
You attempt the lab and submit something. Not clear you put in much
effort or you had real issues
</td>
</tr>
<tr>
<td style="text-align:left;">
F
</td>
<td style="text-align:left;">
0+
</td>
<td style="text-align:left;">
Didn’t submit, or incredibly limited attempt.
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.odd').parent('tbody').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open');
});
});
</script>
<!-- code folding -->
<script>
$(document).ready(function () {
// temporarily add toc-ignore selector to headers for the consistency with Pandoc
$('.unlisted.unnumbered').addClass('toc-ignore')
// move toc-ignore selectors from section div to header
$('div.section.toc-ignore')
.removeClass('toc-ignore')
.children('h1,h2,h3,h4,h5').addClass('toc-ignore');
// establish options
var options = {
selectors: "h1,h2,h3,h4",
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = false;
options.smoothScroll = true;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>