-
Notifications
You must be signed in to change notification settings - Fork 0
/
workshop_1.html
1596 lines (1496 loc) · 153 KB
/
workshop_1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="author" content="KGA320: Our Changing Climate" />
<meta name="progressive" content="false" />
<meta name="allow-skip" content="false" />
<meta name="learnr-version-prerender" content="0.11.5" />
<title>Observations I</title>
<!-- header-includes START -->
<!-- HEAD_CONTENT -->
<!-- header-includes END -->
<!-- HEAD_CONTENT -->
<!-- highlightjs -->
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</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>
<!-- taken from https://github.com/rstudio/rmarkdown/blob/de8a9c38618903627ca509f5401d50a0876079f7/inst/rmd/h/default.html#L293-L343 -->
<!-- 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 {
content: "";
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: "";
border: none;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.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>
<!-- end tabsets -->
</head>
<body>
<a class='sr-only sr-only-focusable visually-hidden-focusable' href='#learnr-tutorial-content'>Skip to Tutorial Content</a>
<div class="pageContent band">
<main class="bandContent page">
<article class="topics" id="learnr-tutorial-content">
<div id="section-introduction-r-and-data-wrangling"
class="section level2">
<h2>Introduction: R and Data Wrangling</h2>
<p>Hey there, <strong>KGA320</strong>! Today, we’re diving into a tool
that’s revolutionised geography and beyond for the past 30 years:
<strong>R</strong>. While creating statistical analyses in a coding
language might seem daunting, you’ll soon see how R makes our lives
easier and more versatile. In fact, we wrote this entire workshop using
R!</p>
<div id="section-what-is-r" class="section level3">
<h3>What is R?</h3>
<p><a href="https://www.r-project.org/about.html">R</a> is a programming
language built especially for statistics. It’s become so ubiquitous that
you’d be hard-pressed to find a statistician or scientist who doesn’t
use it. Why? Because it makes our analysis repeatable. Want someone to
check your work? Just send them your code and dataset. Simple!</p>
<p>Usually, R users interact with the language through <a
href="https://posit.co/download/rstudio-desktop/">RStudio</a>. For
simplicity’s sake, we’re hosting an instance on R over pages for each
workshop. You’ll see neat little coding blocks like this:</p>
<div class="tutorial-exercise" data-label="example" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code># This simple line of code prints out "Hello World!"
print("Hello World!")</code></pre>
<pre><code>[1] "Hello World!"</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<div class="tutorial-exercise-support" data-label="example-hint"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>print("Hello World!")</code></pre>
</div>
<blockquote>
<p>💡 <strong>Pro tip:</strong> Click the “Hint” button if you’re ever
stuck, or click “Start Over” to start from scratch.</p>
</blockquote>
<blockquote>
<p>🔥 <strong>Important:</strong> You cannot save your work on this
webpage. If you create something you want to keep, save it to your
computer!</p>
</blockquote>
<p>Now, you might be wondering…</p>
<blockquote>
<p>🤔 <strong>Why aren’t we using RStudio this semester?</strong></p>
<ul>
<li>We want to ensure everyone has the same experience with R,
regardless of their computer setup.</li>
<li>Different laptops and operating systems can introduce complications
that might distract from learning to code.</li>
<li>Our goal is to keep things simple and focus on the joy of
coding!</li>
</ul>
</blockquote>
<p>Don’t worry, though - if you’re curious about RStudio:</p>
<ol style="list-style-type: decimal">
<li>UTAS computers have RStudio installed.</li>
<li>We’ve shared the source code for these workshops on MyLo.</li>
<li>Feel free to explore RStudio in your own time!</li>
</ol>
</div>
<div id="section-data-wrangling" class="section level3">
<h3>Data Wrangling</h3>
<p>Before we can make pretty graphs, we need data! Climate scientists
have a wealth of information at their fingertips, from paleoclimatology
to modern measurements. For this workshop, we’ll focus on drought
measures and historical daily temperature data for the Barossa Valley,
northeast of Adelaide.</p>
<p><strong>Data wrangling</strong> is the process of preparing our
various data sources for analysis. In creating this workshop, Ben has
already done some wrangling to get this data into a format you will
probably be familiar with: a CSV file. This pre-wrangling saves us some
time, but it’s still crucial to familiarise yourself with the data:</p>
<blockquote>
<p>💡 <strong>Pro Tip:</strong> Download the CSV files from the MyLo
workshop page and open them in Excel or another spreadsheet app. This
allows you to:</p>
<ul>
<li>Scroll through the file to spot missing data or obvious
problems.</li>
<li>Check headers for available variables and units of measurement.</li>
<li>Get a general feel for your dataset.</li>
</ul>
</blockquote>
<p>Viewing our data in Excel is convenient for these initial checks.
Once you’re satisfied with your data overview, it’s time to load it into
R:</p>
<div class="tutorial-exercise" data-label="load_data"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code> # Load Barossa historical climate data
barossa_data <- read.csv("data/barossa_1951-2014.csv")</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<p>Let’s break this down:</p>
<ul>
<li><code>read.csv()</code> is a <strong>function</strong> that reads
our CSV files.</li>
<li>We’re saving the data into a variable <code>barossa_data</code>
using <code><-</code>.</li>
<li>These variables are now containers we can access throughout our
session.</li>
</ul>
<p>To check if it worked, we can use the <code>str()</code>
function:</p>
<div class="tutorial-exercise" data-label="check_load"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>str(barossa_data) # Show the structure of the data frame.</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<p>Using <code>str(barossa_data)</code>, we have created an output
showing that <code>barossa_data</code> is a <code>data.frame</code>,
basically a table, which has collected 23360 observations over 4
variables. We see each of therse variables listed with a type, and some
example values. When we are making calculations, we always want to be
working with variables classed as <code>num</code>, R has recognised
them as numbers that can be manipulated.</p>
<p>It can be hard to guess what a variable is based just on it’s name,
usually we pair a data set with a dictionary or documentation to explain
what a variable is measuring, the units of measurement or type of
variable, and any context we might need. For example, here’s the data
dictionary for <code>barossa_data</code>:</p>
<ul>
<li><p><code>time</code> (<strong>unit</strong>: date,
<strong>type</strong>: <code>char</code>): Date of measurement for
weather data, stored as a string of format “YYYY-MM-DD”.</p></li>
<li><p><code>tasmin</code> (<strong>unit</strong>: °C,
<strong>type</strong>: <code>num</code>): Daily minimum near-surface air
temperature.</p></li>
<li><p><code>tasmax</code> (<strong>unit</strong>: °C,
<strong>type</strong>: <code>num</code>): Daily maximum near-surface air
temperature.</p></li>
<li><p><code>pr</code> (<strong>unit</strong>: mm,
<strong>type</strong>: <code>num</code>): Daily precipitation.</p></li>
</ul>
</div>
<div id="section-we-have-wrangled-now-what" class="section level3">
<h3>We have wrangled, now what?</h3>
<div id="section-basic-inferential-statistics" class="section level4">
<h4>Basic Inferential Statistics</h4>
<p>Before diving into R’s statistical prowess, let’s refresh our memory
on some key concepts. We’ll use the example dataset <span
class="math inline">\([1, 2, 3, 5]\)</span> to illustrate:</p>
<ul>
<li><strong>Mean:</strong> The average. Sum everything up and divide by
the number of items. <span class="math inline">\(\text{Mean} = \frac{1 +
2 + 3 + 5}{4} = 2.75\)</span>.</li>
<li><strong>Median:</strong> The middle value when data is sorted. With
an even number of items, we average the two middle values. <span
class="math inline">\(\text{Median} = \frac{2 + 3}{2} =
2.5\)</span>.</li>
<li><strong>Standard Deviation:</strong> A measure of spread. It’s a bit
trickier:
<ol style="list-style-type: decimal">
<li>Calculate the difference of each value from the mean and square it:
<span class="math inline">\([3.0625, 0.5625, 0.0625,
5.0625]\)</span>.</li>
<li>Find the average of these squares (the variance): <span
class="math inline">\(\frac{3.0625 + 0.5625 + 0.0625 + 5.0625}{4} =
2.1875\)</span>.</li>
<li>Take the square root of the variance: <span
class="math inline">\(\sqrt{2.1875} \approx 1.48\)</span>.</li>
</ol></li>
</ul>
<p>Whew! That’s a lot of work by hand. It may have been a while since
you’ve seen these definitions.</p>
<p>The good news? R makes these calculations a breeze. Let’s find the
mean, median, and standard deviation of the <code>tasmax</code> column
in our <code>historical_data</code>:</p>
<div class="tutorial-exercise" data-label="inferential_stats"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code># Calculate statistics for tasmax
mean_tasmax <- mean(barossa_data$tasmax, na.rm = TRUE)
median_tasmax <- median(barossa_data$tasmax, na.rm = TRUE)
sd_tasmax <- sd(barossa_data$tasmax, na.rm = TRUE)
# Print results
cat("Mean:", mean_tasmax, "\n")
cat("Median:", median_tasmax, "\n")
cat("Standard Deviation:", sd_tasmax, "\n")</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<p>The function <code>cat</code> merges it’s inputs into a single
<strong>string</strong> (words and characters, <code>"Mean:"</code> is a
string in the above code for example), and sends it to the output.
<code>"\n"</code> is a special command in a string that we use to create
a new line. Also, note the <code>na.rm = TRUE</code> argument. This
tells R to ignore missing values (NAs) in our data. Now is a good time
to start playing with variables. See if you can modify the code above to
find the descriptive statistics for precipitation, <code>pr</code>.</p>
</div>
</div>
<div id="section-deep-breath" class="section level3">
<h3>Deep breath</h3>
<p>Let’s take a quick breather. If you’re new to programming, that was a
lot to take in. Pat yourself on the back for making it this far!</p>
<p>We’ve introduced many new terms and techniques. If any <strong>bolded
terms</strong> are unfamiliar, jot them down with their definitions.
Keep this list handy for revision - we’ll use these words frequently in
upcoming workshops.</p>
<div id="section-why-are-we-so-strict-with-the-language-so-far"
class="section level4">
<h4>Why are we so strict with the language so far?</h4>
<p>We want to ensure we all speak the same language over the following
few workshops, so learning the key terms will be essential. Clear
communication is crucial in a field with constant streams of new
information. When we all use the same terminology, it’s easier to:</p>
<ol style="list-style-type: decimal">
<li>Understand each other’s work.</li>
<li>Build upon existing knowledge.</li>
<li>Avoid misinterpretations that could lead to errors.</li>
</ol>
<p>So, while we might not use much slang, we’ll use plenty of scientific
lingo. Think of it as learning a new language - the language of data
science!</p>
</div>
<div id="section-data-visualisation-with-ggplot2"
class="section level4">
<h4>Data Visualisation with ggplot2</h4>
<p>Now for the fun part: visualisation! We’ll use
<strong>ggplot</strong>, a powerful plotting library built as a part of
the <a href="https://www.tidyverse.org/">tidyverse</a>. First, let’s
load it:</p>
<div class="tutorial-exercise" data-label="call_libraries"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>library(ggplot2)</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<p>ggplot uses the “grammar of graphics” - we build plots layer by
layer. Here’s a box plot of Barossa Valley’s maximum temperature using
the descriptive statistics we calculated previously.</p>
<p>First, we’ll create a summary data frame:</p>
<div class="tutorial-exercise" data-label="summary" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code>summary_data <- data.frame(
ymin = mean_tasmax - 1.5 * sd_tasmax,
lower = mean_tasmax - sd_tasmax,
y = mean_tasmax,
upper = mean_tasmax + sd_tasmax,
ymax = mean_tasmax + 1.5 * sd_tasmax
)</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<blockquote>
<p>❓ <strong>Hint:</strong> Remember earlier we described data frames
as essentially R’s version of tables. Here we are collecting the 5
variables <code>ymin, lower, y, upper, ymax</code>, as variables that
are stored in <code>summary_data</code>. Remember, we can use
<code>str(summary_data)</code> to see what this looks like.</p>
</blockquote>
<p>This data frame contains the key values for our boxplot: the minimum,
lower quartile, median, upper quartile, and maximum. We’ve used our
calculated mean and standard deviation from earlier to calculate these
values.</p>
<p>Now, let’s create the boxplot:</p>
<div class="tutorial-exercise" data-label="plotting" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code># Create a simplified boxplot
ggplot(summary_data, aes(x = "Max Temp", y = y)) +
geom_boxplot(aes(ymin = ymin, lower = lower, middle = y, upper = upper, ymax = ymax),
stat = "identity", fill = "lightblue", width = 0.5) +
geom_point(aes(y = median_tasmax), color = "red", size = 3) +
ggtitle("Distribution of Maximum Temperatures in Barossa Valley (1951-2014)") +
ylab("Maximum Temperature (°C)") +
xlab("") +
theme_minimal()</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<p>This might look dense, but there’s a logic to how the graph is built.
Let’s break it down using the grammar of graphics:</p>
<ul>
<li><code>ggplot(summary_data, aes(x = "Max Temp", y = y))</code>:
<ul>
<li>We start the plot with <code>ggplot</code>, using our
<code>summary_data</code>.</li>
<li>We set a fixed x-value (“Max Temp”) and use our calculated mean for
y.</li>
</ul></li>
<li><code>geom_boxplot(...)</code>:
<ul>
<li>This creates the boxplot using our summary statistics.</li>
<li><code>stat = "identity"</code> tells ggplot to use our provided
values directly.</li>
<li>We set the fill colour to light blue and adjusted the width.</li>
</ul></li>
<li><code>geom_point(...)</code>:
<ul>
<li>This adds a red point to represent the median temperature.</li>
</ul></li>
<li><code>ggtitle(...)</code>:
<ul>
<li>We give our figure a descriptive title.</li>
<li><strong>Always do this!</strong> It helps others (and future you)
understand the plot.</li>
</ul></li>
<li><code>ylab(...)</code> and <code>xlab("")</code>:
<ul>
<li>We label the y-axis with the variable name and units.</li>
<li>We leave the x-axis label blank as we only have one category.</li>
<li><strong>Always label your axes!</strong> It’s crucial for
interpretation and accessibility.</li>
</ul></li>
<li><code>theme_minimal()</code>:
<ul>
<li>This applies a clean, minimal theme to our plot.</li>
</ul></li>
</ul>
<p>This approach gives us a representative boxplot without needing the
full dataset, which is great for quick visualisations or when working
with large datasets.</p>
<p>Want to modify this plot? Try changing the colours, adding more
points, or adjusting the theme. For example, you could add a point for
the mean:</p>
<pre class="r"><code>geom_point(aes(y = mean_tasmax), color = "blue", size = 3, shape = "diamond")</code></pre>
<blockquote>
<p>💡 <strong>Pro Tip:</strong> Check out this <a
href="https://github.com/rstudio/cheatsheets/blob/main/data-visualization.pdf">ggplot
cheat sheet</a>. Save it somewhere handy and refer to it often!</p>
</blockquote>
<p>Remember, the grammar of graphics is great for goofballs like us!
With a few tweaks, you can create all sorts of unique visualisations.
Keep practising, and soon you’ll be a ggplot pro!</p>
</div>
</div>
</div>
<div id="section-workshop-data-visualization-and-basic-statistics"
class="section level2">
<h2>Workshop: Data Visualization and Basic Statistics</h2>
<div id="section-testing-your-knowledge" class="section level3">
<h3>Testing your knowledge</h3>
<p>Before we start coding, let’s test your knowledge of R and some basic
commands with some multiple-choice questions:</p>
<div class="panel panel-default tutorial-question-container">
<div data-label="q_variables" class="tutorial-question panel-body">
<div id="q_variables-answer_container" class="shiny-html-output"></div>
<div id="q_variables-message_container" class="shiny-html-output"></div>
<div id="q_variables-action_button_container" class="shiny-html-output"></div>
<script>if (Tutorial.triggerMathJax) Tutorial.triggerMathJax()</script>
</div>
</div>
<div class="panel panel-default tutorial-question-container">
<div data-label="q_dataframes" class="tutorial-question panel-body">
<div id="q_dataframes-answer_container" class="shiny-html-output"></div>
<div id="q_dataframes-message_container" class="shiny-html-output"></div>
<div id="q_dataframes-action_button_container" class="shiny-html-output"></div>
<script>if (Tutorial.triggerMathJax) Tutorial.triggerMathJax()</script>
</div>
</div>
<div class="panel panel-default tutorial-question-container">
<div data-label="q_tasmin" class="tutorial-question panel-body">
<div id="q_tasmin-answer_container" class="shiny-html-output"></div>
<div id="q_tasmin-message_container" class="shiny-html-output"></div>
<div id="q_tasmin-action_button_container" class="shiny-html-output"></div>
<script>if (Tutorial.triggerMathJax) Tutorial.triggerMathJax()</script>
</div>
</div>
<div class="panel panel-default tutorial-question-container">
<div data-label="q_stats" class="tutorial-question panel-body">
<div id="q_stats-answer_container" class="shiny-html-output"></div>
<div id="q_stats-message_container" class="shiny-html-output"></div>
<div id="q_stats-action_button_container" class="shiny-html-output"></div>
<script>if (Tutorial.triggerMathJax) Tutorial.triggerMathJax()</script>
</div>
</div>
<div class="panel panel-default tutorial-question-container">
<div data-label="q_plot" class="tutorial-question panel-body">
<div id="q_plot-answer_container" class="shiny-html-output"></div>
<div id="q_plot-message_container" class="shiny-html-output"></div>
<div id="q_plot-action_button_container" class="shiny-html-output"></div>
<script>if (Tutorial.triggerMathJax) Tutorial.triggerMathJax()</script>
</div>
</div>
<p>Great job! If you struggled with these questions, I highly suggest
you reread the introduction. It will take some time to build up your R
knowledge, but repeated exposure is the best way to get there! Don’t
forget that the internet is packed with useful resources in addition to
the content we provide, including very helpful YouTube videos and free
textbooks. The more you explore, the more comfortable you will get with
R!</p>
</div>
<div id="section-now-we-code" class="section level3">
<h3>Now we code!</h3>
<p>Now, it’s finally time for you to code from scratch! You’ve got this.
Remember, you can ask for help in the workshops or through MyLo.
Remember, assessment task 2 is associated with these workshops. Consider
how the work you do here can feed into your reports.</p>
<blockquote>
<p>🔥 <strong>Important:</strong> You cannot save your work on this
webpage. If you create something you want to keep, save it to your
computer!</p>
</blockquote>
<div id="section-data-wrangling-1" class="section level4">
<h4>Data wrangling</h4>
<p>You will need a region to focus on for your workshop portfolio, and
data from that region. We have four options:</p>
<ol style="list-style-type: decimal">
<li>Monsoonal North, Queensland</li>
<li>East Coast, New South Wales and Queensland</li>
<li>Murray Basin, Victoria and South Australia</li>
<li>Southern Slopes, Tasmania</li>
</ol>
<p>You have been allocated a region in MyLo. Consider research into the
news and history of your region to develop context and understanding.
<strong>You cannot pick the Barossa Valley!</strong> We use the Barossa
Valley as an example data set, not for the reports.</p>
<p>We can use the function <a
href="https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/list.files"><code>list.files</code></a>
to see the data we have available in this workshop.
<code>list.files</code> works like many of the functions we used in the
introduction. We want to see the data available in the <code>data</code>
folder, so that folder will be the input for the <code>list.files</code>
function as a string. Let’s try it now:</p>
<div class="tutorial-exercise" data-label="list_files"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code># Use list.files() to find the data to use in this workshop.</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<div class="tutorial-exercise-support" data-label="list_files-hint-1"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>list.files("...")</code></pre>
</div>
<div class="tutorial-exercise-support" data-label="list_files-hint-2"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>list.files("./data")</code></pre>
</div>
<blockquote>
<p>💡 <strong>Pro tip:</strong> Click the “Hint” button if you’re ever
stuck, or click “Start Over” to start from scratch.</p>
</blockquote>
<p>We can see a data file is available for each region and one for the
Barossa Valley that we used in the introduction. Try loading one of
these data sets and checking its structure here. Use the variable names
we have designated below.</p>
<p><strong>Monsoonal North</strong> - <code>north_data</code></p>
<p><strong>East Coast</strong> - <code>eastcoast_data</code></p>
<p><strong>Murray Basin</strong> - <code>murray_data</code></p>
<p><strong>Southern Slopes</strong> - <code>tas_data</code></p>
<div class="tutorial-exercise" data-label="load_data_ex"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code># Read in a CSV file from the list chosen above.</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<div class="tutorial-exercise-support" data-label="load_data_ex-hint-1"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>read.csv()</code></pre>
</div>
<div class="tutorial-exercise-support" data-label="load_data_ex-hint-2"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>read.csv("data/")</code></pre>
</div>
<div class="tutorial-exercise-support" data-label="load_data_ex-hint-3"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>north_data <- read.csv("data/monsoonal_north_burdekin_1951-2014.csv")
eastcoast_data <- read.csv("data/east_coast_north_coast_1951-2014.csv")
murray_data <- read.csv("data/murray_basin_riverina_1951-2014.csv")
tas_data <- read.csv("data/southern_slopes_south_1951-2014.csv")</code></pre>
</div>
<p>The dataset you have loaded is now ready for analysis, as we did in
the introduction. In the next code section, calculate the mean, median,
and standard deviation of maximum and minimum daily temperature, and
precipitation. Use <code>cat</code> to print these results together as
output from the code box.</p>
<div class="tutorial-exercise" data-label="basic_stats"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code># Calculate and print some basic statistics for your data set.</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<div class="tutorial-exercise-support" data-label="basic_stats-hint-1"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>mean()
median()
sd()</code></pre>
</div>
<div class="tutorial-exercise-support" data-label="basic_stats-hint-2"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>mean(..., na.rm = TRUE)</code></pre>
</div>
<div class="tutorial-exercise-support" data-label="basic_stats-hint-3"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>cat("Mean:", ..., "\n")</code></pre>
</div>
<blockquote>
<p>🔎 <strong>Questions to consider for your report</strong>: Use the
answers to these questions as the formative thinking for your report.
Don’t rely on them. Think for yourself!</p>
<ul>
<li>Can we infer anything from these initial statistics?</li>
<li>Could we do something differently to increase the amount of
information we receive from these basic statistics?</li>
</ul>
</blockquote>
<p>Now, we should create some visualisations of our data. In the
introduction, we created box plots. Box plots are interesting but are
not the best we can do to visualise this data. Even changing to a violin
plot or overlaying a jittered strip plot can be an easy improvement. In
the next exercise, you will create a histogram for each variable.
Remember to use the <a
href="https://github.com/rstudio/cheatsheets/blob/main/data-visualization.pdf">ggplot
cheat sheet</a> to find the right function to fit the grammar of
graphics. Google is your friend! Does a histogram provide insight that
is different from the boxplot? Are there other histograms that could be
made to visualise aspects of the data?</p>
<div class="tutorial-exercise" data-label="plot_histogram"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code># Plot a labelled and titled histogram of a variable in your data set. </code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<div class="tutorial-exercise-support"
data-label="plot_histogram-hint-1" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code>geom_histogram(binwidth = 1)</code></pre>
</div>
<div class="tutorial-exercise-support"
data-label="plot_histogram-hint-2" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code>ggplot(..., aes(x=...)) +
geom_histogram()</code></pre>
</div>
<p>Through these different plots we are beginning to build up a picture
of the climate of your chosen region. So far, we’ve used the simple
inferential statistics of mean, median, and standard deviation. As we go
on, we will start using more complicated statistics. One measure of
interest is <strong>anomalies</strong>, how much a measurement deviates
from the mean. We can calculate an anomaly by applying a calculation
across a column in a data frame. For example, for a data frame
<code>df</code> with column <code>temp</code> that has mean stored in
<code>mean_temp</code>, we can calculate the anomaly for each
<code>temp</code> measurement and store it in the data frame with
<code>df$temp_anomaly <- df$temp - mean_temp</code>. Using this
formula, calculate the anomalies for your variables in the code box
below. <em>NOTE: You will have to recalculate the means even if you
calculated it in the previous exercise, each code box is running a
seperate instance of R</em>. Once you have calculated some anomalies,
try visualising them with plots we have learned so far.</p>
<div class="tutorial-exercise" data-label="calculate_anomaly"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="8" data-pipe="|>">
<pre class="text"><code># Calculate the anomalies of variables in your data set.
df$temp_anomaly <- df$temp - mean_temp
# Visualise the anomaly using ggplot.
ggplot2()</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<blockquote>
<p>🔎 <strong>Questions to consider for your report</strong>:</p>
<ul>
<li>How would you identify heatwaves in the provided data? What about
droughts?</li>
<li>What background knowledge can you collect about your region to
inform your statistical analysis?</li>
</ul>
</blockquote>
<p>We’ve reached the end. Great job on making it through our first R
workshops for KGA320. This has been a big first step; we still have a
lot of ground to cover, but now that we’ve introduced the basics, things
will get easier! Remember that we’re here to help; there’s a wealth of
resources available, and take the time to build up an understanding of
the parts of this workshop you may have found tricky. We have one last
exercise, to lead into next week.</p>
<p>So far, our plots have completely ignored a key aspect of our data -
the progression of time. The study of climate revolves around how
Earth’s systems change over time, so we need to learn how to conduct
<strong>time-series analysis</strong>. In the following exercise box,
try building a plot with time on the x-axis and one of the available
variables on the y-axis. Try using <code>geom_point</code>!</p>
<div class="tutorial-exercise" data-label="time_series"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code># Create a time series plot.</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<div class="tutorial-exercise-support" data-label="time_series-hint-1"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code># An example using barossa_data
ggplot(barossa_data, aes(x = time, y = tasmax)) + # Specify the data and mapping of aesthetics
geom_point() + # Add a line plot layer
ggtitle("trend of maximum temperature (1951-2014)") + # add a title to the plot
xlab("Year") + # Label the x-axis
ylab("maximum temperature (°c)") # label the y-axis</code></pre>
</div>
<p>If you’ve done things right, this plot will look… uninformative. It
will be very noisy, and not show any clear trends. How could we improve
this? Find out next week!</p>
</div>
</div>
<div id="section-playground" class="section level3">
<h3>Playground</h3>
<p>If you have extra time, or want to build on the work you’ve done so
far, use the code box below.</p>
<div class="tutorial-exercise" data-label="playground"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="10" data-pipe="|>">
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<p>
<script type="application/shiny-prerendered" data-context="server-start">
library(learnr)
library(ggplot2)
library(rlang)
source_files_directory <- './data'
setwd('.')
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::register_http_handlers(session, metadata = NULL)
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::prepare_tutorial_state(session)
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::i18n_observe_tutorial_language(input, session)
</script>
<script type="application/shiny-prerendered" data-context="server">
session$onSessionEnded(function() {
learnr:::event_trigger(session, "session_stop")
})
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-example-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-example-code-editor`)), session)
output$`tutorial-exercise-example-output` <- renderUI({
`tutorial-exercise-example-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "example", global_setup = structure(c("library(learnr)",
"library(ggplot2)", "library(rlang)", "", "source_files_directory <- './data'",
"setwd('.')"), chunk_opts = list(label = "setup", include = FALSE)),
setup = NULL, chunks = list(list(label = "example", code = "# This simple line of code prints out \"Hello World!\"\nprint(\"Hello World!\")",
opts = list(label = "\"example\"", exercise = "TRUE",
exercise.eval = "TRUE"), engine = "r")), code_check = NULL,
error_check = NULL, check = NULL, solution = NULL, tests = NULL,
options = list(eval = TRUE, echo = TRUE, results = "markup",
tidy = FALSE, tidy.opts = NULL, collapse = FALSE, prompt = FALSE,
comment = NA, highlight = FALSE, size = "normalsize",
background = "#F7F7F7", strip.white = TRUE, cache = 0,
cache.path = "workshop_1_cache/html/", cache.vars = NULL,
cache.lazy = TRUE, dependson = NULL, autodep = FALSE,
cache.rebuild = FALSE, fig.keep = "high", fig.show = "asis",
fig.align = "default", fig.path = "workshop_1_files/figure-html/",
dev = "png", dev.args = NULL, dpi = 192, fig.ext = "png",
fig.width = 6.5, fig.height = 4, fig.env = "figure",
fig.cap = NULL, fig.scap = NULL, fig.lp = "fig:", fig.subcap = NULL,
fig.pos = "", out.width = 624, out.height = NULL, out.extra = NULL,
fig.retina = 2, external = TRUE, sanitize = FALSE, interval = 1,
aniopts = "controls,loop", warning = TRUE, error = FALSE,
message = TRUE, render = NULL, ref.label = NULL, child = NULL,
engine = "r", split = FALSE, include = TRUE, purl = TRUE,
max.print = 1000, label = "example", exercise = TRUE,
exercise.eval = TRUE, code = c("# This simple line of code prints out \"Hello World!\"",
"print(\"Hello World!\")"), out.width.px = 624, out.height.px = 384,
params.src = "example, exercise=TRUE, exercise.eval=TRUE",
fig.alt = NULL, fig.num = 0, exercise.df_print = "paged",
exercise.checker = "NULL"), engine = "r", version = "4"), class = c("r",
"tutorial_exercise")))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-load_data-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-load_data-code-editor`)), session)
output$`tutorial-exercise-load_data-output` <- renderUI({
`tutorial-exercise-load_data-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "load_data", global_setup = structure(c("library(learnr)",
"library(ggplot2)", "library(rlang)", "", "source_files_directory <- './data'",
"setwd('.')"), chunk_opts = list(label = "setup", include = FALSE)),
setup = NULL, chunks = list(list(label = "load_data", code = " # Load Barossa historical climate data\nbarossa_data <- read.csv(\"data/barossa_1951-2014.csv\")",
opts = list(label = "\"load_data\"", exercise = "TRUE"),
engine = "r")), code_check = NULL, error_check = NULL,
check = NULL, solution = NULL, tests = NULL, options = list(
eval = FALSE, echo = TRUE, results = "markup", tidy = FALSE,
tidy.opts = NULL, collapse = FALSE, prompt = FALSE, comment = NA,
highlight = FALSE, size = "normalsize", background = "#F7F7F7",
strip.white = TRUE, cache = 0, cache.path = "workshop_1_cache/html/",
cache.vars = NULL, cache.lazy = TRUE, dependson = NULL,
autodep = FALSE, cache.rebuild = FALSE, fig.keep = "high",
fig.show = "asis", fig.align = "default", fig.path = "workshop_1_files/figure-html/",
dev = "png", dev.args = NULL, dpi = 192, fig.ext = "png",
fig.width = 6.5, fig.height = 4, fig.env = "figure",
fig.cap = NULL, fig.scap = NULL, fig.lp = "fig:", fig.subcap = NULL,
fig.pos = "", out.width = 624, out.height = NULL, out.extra = NULL,
fig.retina = 2, external = TRUE, sanitize = FALSE, interval = 1,
aniopts = "controls,loop", warning = TRUE, error = FALSE,
message = TRUE, render = NULL, ref.label = NULL, child = NULL,
engine = "r", split = FALSE, include = TRUE, purl = TRUE,
max.print = 1000, label = "load_data", exercise = TRUE,
code = c(" # Load Barossa historical climate data", "barossa_data <- read.csv(\"data/barossa_1951-2014.csv\")"
), out.width.px = 624, out.height.px = 384, params.src = "load_data, exercise=TRUE",
fig.num = 0, exercise.df_print = "paged", exercise.checker = "NULL"),
engine = "r", version = "4"), class = c("r", "tutorial_exercise"
)))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-check_load-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-check_load-code-editor`)), session)
output$`tutorial-exercise-check_load-output` <- renderUI({
`tutorial-exercise-check_load-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "check_load", global_setup = structure(c("library(learnr)",
"library(ggplot2)", "library(rlang)", "", "source_files_directory <- './data'",
"setwd('.')"), chunk_opts = list(label = "setup", include = FALSE)),
setup = " # Load Barossa historical climate data\nbarossa_data <- read.csv(\"data/barossa_1951-2014.csv\")",
chunks = list(list(label = "load_data", code = " # Load Barossa historical climate data\nbarossa_data <- read.csv(\"data/barossa_1951-2014.csv\")",
opts = list(label = "\"load_data\"", exercise = "TRUE"),
engine = "r"), list(label = "check_load", code = "str(barossa_data) # Show the structure of the data frame.",
opts = list(label = "\"check_load\"", exercise = "TRUE",
exercise.setup = "\"load_data\""), engine = "r")),
code_check = NULL, error_check = NULL, check = NULL, solution = NULL,
tests = NULL, options = list(eval = FALSE, echo = TRUE, results = "markup",
tidy = FALSE, tidy.opts = NULL, collapse = FALSE, prompt = FALSE,
comment = NA, highlight = FALSE, size = "normalsize",
background = "#F7F7F7", strip.white = TRUE, cache = 0,
cache.path = "workshop_1_cache/html/", cache.vars = NULL,
cache.lazy = TRUE, dependson = NULL, autodep = FALSE,
cache.rebuild = FALSE, fig.keep = "high", fig.show = "asis",
fig.align = "default", fig.path = "workshop_1_files/figure-html/",
dev = "png", dev.args = NULL, dpi = 192, fig.ext = "png",
fig.width = 6.5, fig.height = 4, fig.env = "figure",
fig.cap = NULL, fig.scap = NULL, fig.lp = "fig:", fig.subcap = NULL,
fig.pos = "", out.width = 624, out.height = NULL, out.extra = NULL,
fig.retina = 2, external = TRUE, sanitize = FALSE, interval = 1,
aniopts = "controls,loop", warning = TRUE, error = FALSE,
message = TRUE, render = NULL, ref.label = NULL, child = NULL,
engine = "r", split = FALSE, include = TRUE, purl = TRUE,
max.print = 1000, label = "check_load", exercise = TRUE,
exercise.setup = "load_data", code = "str(barossa_data) # Show the structure of the data frame.",
out.width.px = 624, out.height.px = 384, params.src = "check_load, exercise=TRUE, exercise.setup=\"load_data\"",
fig.num = 0, exercise.df_print = "paged", exercise.checker = "NULL"),
engine = "r", version = "4"), class = c("r", "tutorial_exercise"
)))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-inferential_stats-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-inferential_stats-code-editor`)), session)
output$`tutorial-exercise-inferential_stats-output` <- renderUI({
`tutorial-exercise-inferential_stats-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "inferential_stats", global_setup = structure(c("library(learnr)",
"library(ggplot2)", "library(rlang)", "", "source_files_directory <- './data'",
"setwd('.')"), chunk_opts = list(label = "setup", include = FALSE)),
setup = " # Load Barossa historical climate data\nbarossa_data <- read.csv(\"data/barossa_1951-2014.csv\")",
chunks = list(list(label = "load_data", code = " # Load Barossa historical climate data\nbarossa_data <- read.csv(\"data/barossa_1951-2014.csv\")",
opts = list(label = "\"load_data\"", exercise = "TRUE"),
engine = "r"), list(label = "inferential_stats", code = "# Calculate statistics for tasmax\nmean_tasmax <- mean(barossa_data$tasmax, na.rm = TRUE)\nmedian_tasmax <- median(barossa_data$tasmax, na.rm = TRUE)\nsd_tasmax <- sd(barossa_data$tasmax, na.rm = TRUE)\n\n# Print results\ncat(\"Mean:\", mean_tasmax, \"\\n\")\ncat(\"Median:\", median_tasmax, \"\\n\")\ncat(\"Standard Deviation:\", sd_tasmax, \"\\n\")",
opts = list(label = "\"inferential_stats\"", exercise = "TRUE",
exercise.setup = "\"load_data\""), engine = "r")),
code_check = NULL, error_check = NULL, check = NULL, solution = NULL,
tests = NULL, options = list(eval = FALSE, echo = TRUE, results = "markup",
tidy = FALSE, tidy.opts = NULL, collapse = FALSE, prompt = FALSE,
comment = NA, highlight = FALSE, size = "normalsize",
background = "#F7F7F7", strip.white = TRUE, cache = 0,
cache.path = "workshop_1_cache/html/", cache.vars = NULL,
cache.lazy = TRUE, dependson = NULL, autodep = FALSE,
cache.rebuild = FALSE, fig.keep = "high", fig.show = "asis",
fig.align = "default", fig.path = "workshop_1_files/figure-html/",
dev = "png", dev.args = NULL, dpi = 192, fig.ext = "png",
fig.width = 6.5, fig.height = 4, fig.env = "figure",
fig.cap = NULL, fig.scap = NULL, fig.lp = "fig:", fig.subcap = NULL,
fig.pos = "", out.width = 624, out.height = NULL, out.extra = NULL,
fig.retina = 2, external = TRUE, sanitize = FALSE, interval = 1,
aniopts = "controls,loop", warning = TRUE, error = FALSE,
message = TRUE, render = NULL, ref.label = NULL, child = NULL,
engine = "r", split = FALSE, include = TRUE, purl = TRUE,
max.print = 1000, label = "inferential_stats", exercise = TRUE,
exercise.setup = "load_data", code = c("# Calculate statistics for tasmax",
"mean_tasmax <- mean(barossa_data$tasmax, na.rm = TRUE)",
"median_tasmax <- median(barossa_data$tasmax, na.rm = TRUE)",
"sd_tasmax <- sd(barossa_data$tasmax, na.rm = TRUE)",
"", "# Print results", "cat(\"Mean:\", mean_tasmax, \"\\n\")",
"cat(\"Median:\", median_tasmax, \"\\n\")", "cat(\"Standard Deviation:\", sd_tasmax, \"\\n\")"
), out.width.px = 624, out.height.px = 384, params.src = "inferential_stats, exercise=TRUE, exercise.setup=\"load_data\"",
fig.num = 0, exercise.df_print = "paged", exercise.checker = "NULL"),
engine = "r", version = "4"), class = c("r", "tutorial_exercise"
)))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-call_libraries-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-call_libraries-code-editor`)), session)
output$`tutorial-exercise-call_libraries-output` <- renderUI({
`tutorial-exercise-call_libraries-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "call_libraries", global_setup = structure(c("library(learnr)",
"library(ggplot2)", "library(rlang)", "", "source_files_directory <- './data'",
"setwd('.')"), chunk_opts = list(label = "setup", include = FALSE)),
setup = " # Load Barossa historical climate data\nbarossa_data <- read.csv(\"data/barossa_1951-2014.csv\")\n# Calculate statistics for tasmax\nmean_tasmax <- mean(barossa_data$tasmax, na.rm = TRUE)\nmedian_tasmax <- median(barossa_data$tasmax, na.rm = TRUE)\nsd_tasmax <- sd(barossa_data$tasmax, na.rm = TRUE)\n\n# Print results\ncat(\"Mean:\", mean_tasmax, \"\\n\")\ncat(\"Median:\", median_tasmax, \"\\n\")\ncat(\"Standard Deviation:\", sd_tasmax, \"\\n\")",
chunks = list(list(label = "load_data", code = " # Load Barossa historical climate data\nbarossa_data <- read.csv(\"data/barossa_1951-2014.csv\")",
opts = list(label = "\"load_data\"", exercise = "TRUE"),
engine = "r"), list(label = "inferential_stats", code = "# Calculate statistics for tasmax\nmean_tasmax <- mean(barossa_data$tasmax, na.rm = TRUE)\nmedian_tasmax <- median(barossa_data$tasmax, na.rm = TRUE)\nsd_tasmax <- sd(barossa_data$tasmax, na.rm = TRUE)\n\n# Print results\ncat(\"Mean:\", mean_tasmax, \"\\n\")\ncat(\"Median:\", median_tasmax, \"\\n\")\ncat(\"Standard Deviation:\", sd_tasmax, \"\\n\")",
opts = list(label = "\"inferential_stats\"", exercise = "TRUE",
exercise.setup = "\"load_data\""), engine = "r"),
list(label = "call_libraries", code = "library(ggplot2)",
opts = list(label = "\"call_libraries\"", exercise = "TRUE",
exercise.setup = "\"inferential_stats\""), engine = "r")),
code_check = NULL, error_check = NULL, check = NULL, solution = NULL,
tests = NULL, options = list(eval = FALSE, echo = TRUE, results = "markup",
tidy = FALSE, tidy.opts = NULL, collapse = FALSE, prompt = FALSE,
comment = NA, highlight = FALSE, size = "normalsize",
background = "#F7F7F7", strip.white = TRUE, cache = 0,
cache.path = "workshop_1_cache/html/", cache.vars = NULL,
cache.lazy = TRUE, dependson = NULL, autodep = FALSE,
cache.rebuild = FALSE, fig.keep = "high", fig.show = "asis",
fig.align = "default", fig.path = "workshop_1_files/figure-html/",
dev = "png", dev.args = NULL, dpi = 192, fig.ext = "png",
fig.width = 6.5, fig.height = 4, fig.env = "figure",
fig.cap = NULL, fig.scap = NULL, fig.lp = "fig:", fig.subcap = NULL,
fig.pos = "", out.width = 624, out.height = NULL, out.extra = NULL,
fig.retina = 2, external = TRUE, sanitize = FALSE, interval = 1,
aniopts = "controls,loop", warning = TRUE, error = FALSE,
message = TRUE, render = NULL, ref.label = NULL, child = NULL,
engine = "r", split = FALSE, include = TRUE, purl = TRUE,
max.print = 1000, label = "call_libraries", exercise = TRUE,
exercise.setup = "inferential_stats", code = "library(ggplot2)",
out.width.px = 624, out.height.px = 384, params.src = "call_libraries, exercise=TRUE, exercise.setup=\"inferential_stats\"",
fig.num = 0, exercise.df_print = "paged", exercise.checker = "NULL"),
engine = "r", version = "4"), class = c("r", "tutorial_exercise"
)))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-summary-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-summary-code-editor`)), session)
output$`tutorial-exercise-summary-output` <- renderUI({
`tutorial-exercise-summary-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "summary", global_setup = structure(c("library(learnr)",
"library(ggplot2)", "library(rlang)", "", "source_files_directory <- './data'",
"setwd('.')"), chunk_opts = list(label = "setup", include = FALSE)),
setup = " # Load Barossa historical climate data\nbarossa_data <- read.csv(\"data/barossa_1951-2014.csv\")\n# Calculate statistics for tasmax\nmean_tasmax <- mean(barossa_data$tasmax, na.rm = TRUE)\nmedian_tasmax <- median(barossa_data$tasmax, na.rm = TRUE)\nsd_tasmax <- sd(barossa_data$tasmax, na.rm = TRUE)\n\n# Print results\ncat(\"Mean:\", mean_tasmax, \"\\n\")\ncat(\"Median:\", median_tasmax, \"\\n\")\ncat(\"Standard Deviation:\", sd_tasmax, \"\\n\")\nlibrary(ggplot2)",
chunks = list(list(label = "load_data", code = " # Load Barossa historical climate data\nbarossa_data <- read.csv(\"data/barossa_1951-2014.csv\")",
opts = list(label = "\"load_data\"", exercise = "TRUE"),
engine = "r"), list(label = "inferential_stats", code = "# Calculate statistics for tasmax\nmean_tasmax <- mean(barossa_data$tasmax, na.rm = TRUE)\nmedian_tasmax <- median(barossa_data$tasmax, na.rm = TRUE)\nsd_tasmax <- sd(barossa_data$tasmax, na.rm = TRUE)\n\n# Print results\ncat(\"Mean:\", mean_tasmax, \"\\n\")\ncat(\"Median:\", median_tasmax, \"\\n\")\ncat(\"Standard Deviation:\", sd_tasmax, \"\\n\")",
opts = list(label = "\"inferential_stats\"", exercise = "TRUE",
exercise.setup = "\"load_data\""), engine = "r"),
list(label = "call_libraries", code = "library(ggplot2)",
opts = list(label = "\"call_libraries\"", exercise = "TRUE",
exercise.setup = "\"inferential_stats\""), engine = "r"),
list(label = "summary", code = "summary_data <- data.frame(\n ymin = mean_tasmax - 1.5 * sd_tasmax,\n lower = mean_tasmax - sd_tasmax,\n y = mean_tasmax,\n upper = mean_tasmax + sd_tasmax,\n ymax = mean_tasmax + 1.5 * sd_tasmax\n)",
opts = list(label = "\"summary\"", exercise = "TRUE",
exercise.setup = "\"call_libraries\""), engine = "r")),
code_check = NULL, error_check = NULL, check = NULL, solution = NULL,
tests = NULL, options = list(eval = FALSE, echo = TRUE, results = "markup",