-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntro-to-Data-Science.html
1121 lines (1035 loc) · 119 KB
/
Intro-to-Data-Science.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="progressive" content="false" />
<meta name="allow-skip" content="false" />
<meta name="learnr-version-prerender" content="0.11.5" />
<title>Data Science Introduction Tutorial</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">
<style type="text/css">
.notice {
padding: 15px;
background-color: #f9f9f9;
border-left: 6px solid #ffcc00;
margin-bottom: 15px;
}
</style>
<div id="section-outline" class="section level2">
<h2>Outline</h2>
<p>In this tutorial, we learn about R and help you set up your first
Data Science Trip!!! Are you Ready? Let’s get started!</p>
<ul>
<li>Why R for Data Science?</li>
<li>What can R do?</li>
<li>Data Wrangling</li>
<li>Data Visualization</li>
<li>Be UT men basketball coach!!!</li>
</ul>
</div>
<div id="section-why-r-for-data-science" class="section level2">
<h2>Why R for Data Science?</h2>
<p>R is a <em>free</em> and open-source programming language for
statistical computing and graphics. The R Project for Statistical
Computing (<a href="https://www.r-project.org"
class="uri">https://www.r-project.org</a>) supports and develops R.</p>
<p><strong>Why learn R for Data Science?</strong></p>
<ul>
<li>R is free and open-source. Because it is free, everyone has access
to it! Because it is open-source, anyone can add functionality to R in
the form of packages. Also, statisticians and computer scientist can can
audit the code and edit any bugs (i.e., there is no black box).</li>
<li>R is the <em>lingua franca</em> of statistics. In other words, it is
the most common <em>data analysis tool</em>. Since R is the main
computing environment for statistical analysis, both established and new
methods in statistics, data mining, machine learning, and psychometrics
are often employed using R, so there is no need for specialized
software. Just learn R and you are ready to go.</li>
<li>R has beautiful <em>data visualization</em> capabilities. We will
learn the basics of making graphs in R in this microcredential. R has a
wide variety of packages for data visualization, including
<code>ggplot2</code>, <code>plotly</code>, and
<code>lattice</code>.</li>
<li>R has a great community! There are many talented R programmers that
have contributed helpful R packages. In addition, there are great R
mailing lists and Stack Overflow (<a href="https://stackoverflow.com"
class="uri">https://stackoverflow.com</a>) where you can find help using
R.</li>
</ul>
<p><strong>R you ready?</strong></p>
<p>The R community is made up of people passionate about the
intersection of numbers, data, analysis, and code. It was invented by
scientists for statistical computing and a community of specialized
packages has been built around the language. In this first section, you
will be introduced to some basic R syntax and discuss how R classifies
data types so that it can mathematically process them in analysis.</p>
<p><em>Background Information:</em> Unlike with other programming
languages, most beginners who want to learn R do so because they want to
analyze data. In this way, R is more of a tool to understand data than a
programming language used to build software applications. However, what
we are learning will build the foundation for you to start programming
in R.</p>
</div>
<div id="section-what-can-r-do" class="section level2">
<h2>What Can R do?</h2>
<p><strong>Mathematical calculations.</strong> Let’s start with the
basic syntax for mathematical calculations in R. R performs addition,
subtraction, multiplication, and division with +, -, *, and /
operators.</p>
<p><br> <strong>Comments.</strong> It’s often good practice to annotate
the code you write and not let the computer read it as code. We can
annotate or write text in our coding scripts using comments. Comments
are text written after a # in a program that is not run by the computer.
R interprets anything after a # as a comment. A brief example is
provided below demonstrating the use of comments. Run the following code
using the blue “Run Code” button on the right.</p>
<div class="tutorial-exercise" data-label="math_comment"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code>12 + 21 #this line of code sums 12 and 21</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>As you can see, the sum of 12 and 21 is shown when you run the code,
but the comment is not displayed in the output.</p>
<p><strong>Visualization.</strong> we can use R to make simple plot,
such as a bar plot, line plot, or scatter plot. We will use the
<code>ggplot2</code> package to create these plots. The
<code>ggplot2</code> package is a powerful and flexible package for
creating visualizations in R. We will learn more about data
visualization in the next section. Herw is an example of a simple bar
plot using the <code>ggplot2</code> package. <em>Run the code</em> below
to create a bar plot of the seed rating of the teams!!!</p>
<div class="tutorial-exercise" data-label="barplot" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code># Create a data frame
data <- data.frame(
team = c("Kansas", "Tennessee", "Duke", "Purdue"),
rating = c(98, 95, 92, 90))
# Create a bar plot using ggplot2
ggplot(data, aes(x = team, y = rating)) +
geom_bar(stat = "identity", fill = "orange") +
labs(title = "Seed Rating of Teams", x = "Team", y = "Seed Rating") +
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>
</div>
<div id="section-before-analysisbe-famliar-with-the-dataset-codebook"
class="section level2">
<h2>Before Analysis:Be famliar with the <em>Dataset Codebook</em></h2>
<p>Before we start our analysis, Make sure you are famliar with your
dataset, the Codebook is a good start!!! The codebook is a document that
provides information about the variables in a dataset. It describes each
variable, the possible values it can take, and any other relevant
information. The data set we will be using is the March_Madness Data,
which contains information about the University NCAA Men’s Basketball
team March Madness performance from 2016 to 2023.</p>
<p><strong>March_Madness Codebook</strong></p>
<ul>
<li><strong>YEAR</strong>: sesson year(2016-2023)</li>
<li><strong>TEAM.NO</strong>: university team number</li>
<li><strong>TEAM</strong>: university team name</li>
<li><strong>SEED</strong>: university team seed</li>
<li><strong>ROUND</strong>: university team round</li>
<li><strong>POWER.RATING</strong>: university team power rating</li>
<li><strong>POWER.RATING.RANKING</strong>: university team power rating
ranking</li>
</ul>
</div>
<div id="section-data-wrangling" class="section level2">
<h2>Data Wrangling</h2>
<p>Data wrangling is the process of cleaning and transforming raw data
into a more usable format.In R, the <code>dplyr</code> package is a
powerful tool for data wrangling. It provides a set of functions that
can be used to manipulate data frames. The <code>dplyr</code> package is
part of the <code>tidyverse</code>, a collection of R packages designed
for data science.</p>
<p>Let’s take a look at an example of data wrangling using the
<code>dplyr</code> package.In this case,we will use NCAA men Baketball
data(March_Madness) to demonstrate how to filter and select data using
the <code>dplyr</code> package.</p>
<div id="section-viewing-data" class="section level3">
<h3>Viewing Data</h3>
<p>The first rule of data analysis is to view your data. This is
important to ensure the data were read in properly and nothing odd is
going on. We can accomplish this task with a few different functions in
and outside of the tidyverse. Our favorite functions to view our data
are the following:</p>
<ul>
<li><code>glimpse()</code> in the <code>tidyverse</code> package</li>
</ul>
<p>Lets go ahead and try <code>glimpse()</code>! <em>Run the code</em>
below to view the data.</p>
<div class="tutorial-exercise" data-label="glimpse" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code>glimpse(March_Madness)</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>As you can see, <code>glimpse()</code> provides us with the some
information of data for each of variables. It even tells us the data
type for each of the variables. This is a great way to get a quick
overview of the data.</p>
</div>
<div id="section-basic-dplyr-verbs" class="section level3">
<h3>Basic <code>dplyr</code> verbs</h3>
<p>You can think of the functions within <code>dplyr</code> to
manipulate data as <em>verbs</em>. The function names tells you what
they do in terms of data manipulation. We’ve provided you with very
basic two functions below along with their actions.</p>
<ul>
<li><code>filter()</code> filters columns based on a given value</li>
<li><code>select()</code> selects columns to display in a data set</li>
</ul>
<p>Before we begin, we need to learn about the pipe.</p>
<p>Yes, that one! The pipe operator <code>%>%</code> is used to chain
together multiple functions in R. It takes the output of one function
and passes it as the first argument to the next function. This makes it
easier to read and write code.</p>
<div id="section-pipe" class="section level4">
<h4><code>pipe()</code></h4>
<p>More often than not, you will use multiple <code>dplyr</code>
functions to wrangle your data into the shape you need. Since the
<code>dplyr</code> functions take a data frame as the first argument, it
would be inefficient to save each step as a new object. Plus, you’d have
many different versions of a data frame in your global environment!
Instead, we can use the piper operator <code>%>%</code> or
<code>|></code> to perform multiple data manipulations in one chunk
of code. We like to think of the pipe operator as saying “and then” do
this. We will provide an example below using the <code>filter()</code>
function.</p>
</div>
<div id="section-filter" class="section level4">
<h4><code>filter()</code></h4>
<div class="tutorial-exercise" data-label="filter" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code>filter(March_Madness, TEAM == 'Tennessee')
March_Madness |>
filter(TEAM == 'Tennessee')</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 talk about the first line of code. In this line, we don’t use
the pipe operator; instead we provide the name of the data set as the
first argument for the <code>filter()</code> function, and we use a
logical comparison for the second argument of the function by asking R
to filter and only display observations where the TEAM(team name) equals
“Tennessee.”</p>
<p>In the second line of code, we provide the name of the data set and
use the pipe operator to then filter the team “Tennessee”. For this code
structure, we tell R to take the <code>March_Madness</code> object AND
THEN (the pipe operator) filter the column <code>TEAM</code> which is
Tennessee.</p>
<p>We get the same result using both code structures above, but when we
start to combine <code>dplyr</code> functions in a chunk of code, it
will be more efficient to use the pipe operator.</p>
</div>
<div id="section-select" class="section level4">
<h4><code>select()</code></h4>
<div class="tutorial-exercise" data-label="select" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code>March_Madness |>
select(YEAR, TEAM, POWER.RATING)</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>In the code chunk above, we are asking R to select the columns YEAR,
TEAM, and POWER RATING. Notice that we use backticks around the column
name <code>POWER RATING</code> because it contains a space. This is a
common practice when selecting columns with spaces in the name.</p>
</div>
</div>
<div id="section-reflect" class="section level3">
<h3>Reflect</h3>
<p>Let’s take some time to reflect before moving on. What is one thing
that surprised you? What is one thing that confused you? Did you learn
anything that might be useful in the type of work you do?</p>
</div>
</div>
<div id="section-data-visualization---be-ut-men-basketball-coach"
class="section level2">
<h2>Data Visualization - BE UT Men Basketball coach</h2>
<p>Now, let’s apply your R skills to a real-world dataset: the NCAA
basketball March Madness. We’ll analyze Tennessee Vols team historical
data to understand past performance and perhaps predict future
outcomes.</p>
<p>Analysis Introduction:</p>
<p>In 2024, Tennessee achieved their best historical performance by
reaching the Elite Eight in March Madness. They are now set to compete
against Purdue University for a spot in the Final Four. As the coach,
you have received data from your team’s analysts, containing historical
March Madness data for both your team and the opponent. Your task is to
evaluate both teams’ performances to devise a winning strategy.</p>
<p>We’ll explore how the power rating for the Tennessee team has changed
over last three years in the March Madness tournaments. We’ll also
compare the performances between UT Vols and Purdue based on their power
ratings.</p>
<div id="section-task-1-tennessee-team-power-rating-analysis"
class="section level3">
<h3>Task 1: Tennessee Team Power Rating Analysis</h3>
<p>Explore how the power rating for the Tennessee team has changed over
the years in the March Madness tournaments. Create a line plot to
visualize the trend.</p>
<p><strong>Steps:</strong></p>
<ol style="list-style-type: decimal">
<li>Filter the dataset for team “Tennessee” and years 2021 to 2023.</li>
<li>select the columns “YEAR”,“TEAM” and “POWER RATING”.</li>
<li>Plot the POWER RATING over past 3 years.</li>
</ol>
<div class="tutorial-exercise" data-label="tennessee-PowerRating-trend"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code># Filter data for Tennessee and select relevant columns (YEAR, TEAM, POWER RATING) for years 2021 to 2023
tennessee_data <- March_Madness %>%
filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%
select(YEAR, TEAM, POWER.RATING)
# Plot Power Rating over the years using ggplot2 as a line plot
ggplot(tennessee_data, aes(x = YEAR, y = POWER.RATING)) +
geom_line(color = "orange") +
geom_point() +
labs(title = "Tennessee Vols Power Rating Trend in past 3 years' March Madness", x = "Year", y = "Power Rating") +
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>
</div>
<div
id="section-task-2-coach-its-your-turn.-purdue-team-power-rating-analysis"
class="section level3">
<h3>Task 2: Coach!! It’s your Turn. Purdue Team Power Rating
Analysis</h3>
<p><strong>object</strong>:Explore the Purde performances by analyzing
their Power Ratings.</p>
<p><strong>Steps:</strong></p>
<ol style="list-style-type: decimal">
<li>Filter the dataset for the Purdue university.</li>
<li>Select the columns “TEAM”,“YEAR” and POWER.RATING.</li>
<li>Create a bar plot to visualize the power ratings of Purdue . 4.Try
to think about the 2024 elite eight round result of Tennessee vs Purdue
based on the power rating.</li>
</ol>
<p>Let’s do! Step 1: Filter the dataset for Purdue University Filter the
dataset for team “Purdue” and years 2021 to 2023.</p>
<div class="tutorial-exercise" data-label="filter_data_for_Purdue"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":true,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<div class="tutorial-exercise-support"
data-label="filter_data_for_Purdue-hint" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code># Hint: Use the filter function from dplyr
Purdue_data <- March_Madness %>%
filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)</code></pre>
</div>
<div class="tutorial-exercise-support"
data-label="filter_data_for_Purdue-solution" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code>Purdue_data <- March_Madness %>%
filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)</code></pre>
</div>
<p>Step 2: Select the columns “TEAM”,“YEAR” and POWER.RATING.</p>
<div class="tutorial-exercise" data-label="select_the_relevant_columns"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":true,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<div class="tutorial-exercise-support"
data-label="select_the_relevant_columns-hint" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code># Hint: Use the select function from dplyr
Purdue_data <- Purdue_data %>%
select(YEAR, TEAM, POWER.RATING)</code></pre>
</div>
<div class="tutorial-exercise-support"
data-label="select_the_relevant_columns-solution" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code>Purdue_data <- Purdue_data %>%
select(YEAR, TEAM, POWER.RATING)</code></pre>
</div>
<p>Step 3: Create a line plot to visualize the power ratings of
Purdue.</p>
<div class="tutorial-exercise" data-label="create_lineplot_Purdue"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":true,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{"engine":"R"}\">R Code<\/span>"}</script>
</div>
<div class="tutorial-exercise-support"
data-label="create_lineplot_Purdue-hint" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code># Hint: Use ggplot2 to create the line plot
ggplot(Purdue_data, aes(x = YEAR, y = POWER.RATING)) +
geom_line(color = "blue") +
geom_point(color = "blue")</code></pre>
</div>
<div class="tutorial-exercise-support"
data-label="create_lineplot_Purdue-solution" data-completion="1"
data-diagnostics="1" data-startover="1" data-lines="0"
data-pipe="|>">
<pre class="text"><code>ggplot(Purdue_data, aes(x = YEAR, y = POWER.RATING)) +
geom_line(color = "blue") +
geom_point(color = "blue")</code></pre>
</div>
</div>
<div id="section-task-3-compare-tennessee-and-purdue-power-ratings"
class="section level3">
<h3>Task 3: Compare Tennessee and Purdue Power Ratings</h3>
<p>Now: hand over to the team’s analysts to compare the power ratings of
Tennessee and Purdue over the years.Run the code below to compare the
power ratings of Tennessee and Purdue over past 3 years.</p>
<div class="tutorial-exercise" data-label="power-rating-comparison"
data-completion="1" data-diagnostics="1" data-startover="1"
data-lines="0" data-pipe="|>">
<pre class="text"><code># draw UT vols Power Rating
p <- ggplot() +
geom_line(data = tennessee_data, aes(x = YEAR, y = POWER.RATING, color = "Tennessee"), size = 1) +
geom_point(data = tennessee_data, aes(x = YEAR, y = POWER.RATING, color = "Tennessee"))
# add Purdue Power Rating
p <- p +
geom_line(data = Purdue_data, aes(x = YEAR, y = POWER.RATING, color = "Purdue"), size = 1) +
geom_point(data = Purdue_data, aes(x = YEAR, y = POWER.RATING, color = "Purdue"))
# add labels and theme
p <- p + labs(title = "Tennessee vs Purdue Power Rating Comparison in past 3 years' March Madness",
x = "Year",
y = "Power Rating",
color = "Team") +
theme_minimal() +
scale_color_manual(values = c("Tennessee" = "orange", "Purdue" = "blue"))
# print the plot
print(p)</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>
<script type="application/shiny-prerendered" data-context="server-start">
library(learnr)
library(readr)
library(tidyverse)
library(ggplot2)
knitr::opts_chunk$set(echo = TRUE, eval = FALSE)
tutorial_options(exercise.timelimit = 60)
gradethis::gradethis_setup()
March_Madness <- read.csv("March_Madness_Data.csv")
tennessee_data <- March_Madness %>%
filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%
select(YEAR, TEAM, POWER.RATING)
Purdue_data <- March_Madness %>%
filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)
</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-math_comment-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-math_comment-code-editor`)), session)
output$`tutorial-exercise-math_comment-output` <- renderUI({
`tutorial-exercise-math_comment-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "math_comment", global_setup = structure(c("library(learnr)",
"library(readr)", "library(tidyverse)", "library(ggplot2)", "knitr::opts_chunk$set(echo = TRUE, eval = FALSE)",
"tutorial_options(exercise.timelimit = 60)", "gradethis::gradethis_setup()",
"March_Madness <- read.csv(\"March_Madness_Data.csv\")", "tennessee_data <- March_Madness %>%",
" filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%",
" select(YEAR, TEAM, POWER.RATING)", "Purdue_data <- March_Madness %>%",
" filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)"), chunk_opts = list(
label = "setup", include = FALSE)), setup = NULL, chunks = list(
list(label = "math_comment", code = "12 + 21 #this line of code sums 12 and 21\n",
opts = list(label = "\"math_comment\"", 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 = "Intro-to-Data-Science_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 = "Intro-to-Data-Science_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, exercise.timelimit = 60, exercise.checker = "function (label = NULL, solution_code = NULL, user_code = NULL, \n check_code = NULL, envir_result = NULL, evaluate_result = NULL, \n envir_prep = NULL, last_value = NULL, stage = NULL, ..., \n solution_eval_fn = NULL) \n{\n (utils::getFromNamespace(\"check_exercise\", \"gradethis\"))(label = label, \n solution_code = solution_code, user_code = user_code, \n check_code = check_code, envir_result = envir_result, \n evaluate_result = evaluate_result, envir_prep = envir_prep, \n last_value = last_value, stage = stage, ...)\n}",
exercise.error.check.code = "gradethis_error_checker()",
label = "math_comment", exercise = TRUE, code = c("12 + 21 #this line of code sums 12 and 21",
""), out.width.px = 624, out.height.px = 384, params.src = "math_comment, exercise = TRUE",
fig.num = 0, exercise.df_print = "paged"), engine = "r",
version = "4"), class = c("r", "tutorial_exercise")))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-barplot-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-barplot-code-editor`)), session)
output$`tutorial-exercise-barplot-output` <- renderUI({
`tutorial-exercise-barplot-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "barplot", global_setup = structure(c("library(learnr)",
"library(readr)", "library(tidyverse)", "library(ggplot2)", "knitr::opts_chunk$set(echo = TRUE, eval = FALSE)",
"tutorial_options(exercise.timelimit = 60)", "gradethis::gradethis_setup()",
"March_Madness <- read.csv(\"March_Madness_Data.csv\")", "tennessee_data <- March_Madness %>%",
" filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%",
" select(YEAR, TEAM, POWER.RATING)", "Purdue_data <- March_Madness %>%",
" filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)"), chunk_opts = list(
label = "setup", include = FALSE)), setup = NULL, chunks = list(
list(label = "barplot", code = "\n# Create a data frame\ndata <- data.frame(\n team = c(\"Kansas\", \"Tennessee\", \"Duke\", \"Purdue\"),\n rating = c(98, 95, 92, 90))\n\n# Create a bar plot using ggplot2\nggplot(data, aes(x = team, y = rating)) +\n geom_bar(stat = \"identity\", fill = \"orange\") +\n labs(title = \"Seed Rating of Teams\", x = \"Team\", y = \"Seed Rating\") +\n theme_minimal()",
opts = list(label = "\"barplot\"", exercise = "TRUE",
exercise.eval = "FALSE"), 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 = "Intro-to-Data-Science_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 = "Intro-to-Data-Science_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, exercise.timelimit = 60, exercise.checker = "function (label = NULL, solution_code = NULL, user_code = NULL, \n check_code = NULL, envir_result = NULL, evaluate_result = NULL, \n envir_prep = NULL, last_value = NULL, stage = NULL, ..., \n solution_eval_fn = NULL) \n{\n (utils::getFromNamespace(\"check_exercise\", \"gradethis\"))(label = label, \n solution_code = solution_code, user_code = user_code, \n check_code = check_code, envir_result = envir_result, \n evaluate_result = evaluate_result, envir_prep = envir_prep, \n last_value = last_value, stage = stage, ...)\n}",
exercise.error.check.code = "gradethis_error_checker()",
label = "barplot", exercise = TRUE, exercise.eval = FALSE,
code = c("", "# Create a data frame", "data <- data.frame(",
" team = c(\"Kansas\", \"Tennessee\", \"Duke\", \"Purdue\"),",
" rating = c(98, 95, 92, 90))", "", "# Create a bar plot using ggplot2",
"ggplot(data, aes(x = team, y = rating)) +", " geom_bar(stat = \"identity\", fill = \"orange\") +",
" labs(title = \"Seed Rating of Teams\", x = \"Team\", y = \"Seed Rating\") +",
" theme_minimal()"), out.width.px = 624, out.height.px = 384,
params.src = "barplot, exercise = TRUE,, exercise.eval = FALSE",
fig.num = 0, exercise.df_print = "paged"), engine = "r",
version = "4"), class = c("r", "tutorial_exercise")))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-glimpse-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-glimpse-code-editor`)), session)
output$`tutorial-exercise-glimpse-output` <- renderUI({
`tutorial-exercise-glimpse-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "glimpse", global_setup = structure(c("library(learnr)",
"library(readr)", "library(tidyverse)", "library(ggplot2)", "knitr::opts_chunk$set(echo = TRUE, eval = FALSE)",
"tutorial_options(exercise.timelimit = 60)", "gradethis::gradethis_setup()",
"March_Madness <- read.csv(\"March_Madness_Data.csv\")", "tennessee_data <- March_Madness %>%",
" filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%",
" select(YEAR, TEAM, POWER.RATING)", "Purdue_data <- March_Madness %>%",
" filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)"), chunk_opts = list(
label = "setup", include = FALSE)), setup = NULL, chunks = list(
list(label = "glimpse", code = "glimpse(March_Madness)",
opts = list(label = "\"glimpse\"", exercise = "TRUE",
exercise.eval = "FALSE"), 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 = "Intro-to-Data-Science_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 = "Intro-to-Data-Science_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, exercise.timelimit = 60, exercise.checker = "function (label = NULL, solution_code = NULL, user_code = NULL, \n check_code = NULL, envir_result = NULL, evaluate_result = NULL, \n envir_prep = NULL, last_value = NULL, stage = NULL, ..., \n solution_eval_fn = NULL) \n{\n (utils::getFromNamespace(\"check_exercise\", \"gradethis\"))(label = label, \n solution_code = solution_code, user_code = user_code, \n check_code = check_code, envir_result = envir_result, \n evaluate_result = evaluate_result, envir_prep = envir_prep, \n last_value = last_value, stage = stage, ...)\n}",
exercise.error.check.code = "gradethis_error_checker()",
label = "glimpse", exercise = TRUE, exercise.eval = FALSE,
code = "glimpse(March_Madness)", out.width.px = 624,
out.height.px = 384, params.src = "glimpse, exercise=TRUE, exercise.eval = FALSE",
fig.num = 0, exercise.df_print = "paged"), engine = "r",
version = "4"), class = c("r", "tutorial_exercise")))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-filter-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-filter-code-editor`)), session)
output$`tutorial-exercise-filter-output` <- renderUI({
`tutorial-exercise-filter-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "filter", global_setup = structure(c("library(learnr)",
"library(readr)", "library(tidyverse)", "library(ggplot2)", "knitr::opts_chunk$set(echo = TRUE, eval = FALSE)",
"tutorial_options(exercise.timelimit = 60)", "gradethis::gradethis_setup()",
"March_Madness <- read.csv(\"March_Madness_Data.csv\")", "tennessee_data <- March_Madness %>%",
" filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%",
" select(YEAR, TEAM, POWER.RATING)", "Purdue_data <- March_Madness %>%",
" filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)"), chunk_opts = list(
label = "setup", include = FALSE)), setup = NULL, chunks = list(
list(label = "filter", code = "filter(March_Madness, TEAM == 'Tennessee')\n\nMarch_Madness |>\n filter(TEAM == 'Tennessee')",
opts = list(label = "\"filter\"", exercise = "TRUE",
exercise.eval = "FALSE"), 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 = "Intro-to-Data-Science_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 = "Intro-to-Data-Science_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, exercise.timelimit = 60, exercise.checker = "function (label = NULL, solution_code = NULL, user_code = NULL, \n check_code = NULL, envir_result = NULL, evaluate_result = NULL, \n envir_prep = NULL, last_value = NULL, stage = NULL, ..., \n solution_eval_fn = NULL) \n{\n (utils::getFromNamespace(\"check_exercise\", \"gradethis\"))(label = label, \n solution_code = solution_code, user_code = user_code, \n check_code = check_code, envir_result = envir_result, \n evaluate_result = evaluate_result, envir_prep = envir_prep, \n last_value = last_value, stage = stage, ...)\n}",
exercise.error.check.code = "gradethis_error_checker()",
label = "filter", exercise = TRUE, exercise.eval = FALSE,
code = c("filter(March_Madness, TEAM == 'Tennessee')",
"", "March_Madness |>", " filter(TEAM == 'Tennessee')"
), out.width.px = 624, out.height.px = 384, params.src = "filter, exercise=TRUE, exercise.eval = FALSE",
fig.num = 0, exercise.df_print = "paged"), engine = "r",
version = "4"), class = c("r", "tutorial_exercise")))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-select-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-select-code-editor`)), session)
output$`tutorial-exercise-select-output` <- renderUI({
`tutorial-exercise-select-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "select", global_setup = structure(c("library(learnr)",
"library(readr)", "library(tidyverse)", "library(ggplot2)", "knitr::opts_chunk$set(echo = TRUE, eval = FALSE)",
"tutorial_options(exercise.timelimit = 60)", "gradethis::gradethis_setup()",
"March_Madness <- read.csv(\"March_Madness_Data.csv\")", "tennessee_data <- March_Madness %>%",
" filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%",
" select(YEAR, TEAM, POWER.RATING)", "Purdue_data <- March_Madness %>%",
" filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)"), chunk_opts = list(
label = "setup", include = FALSE)), setup = NULL, chunks = list(
list(label = "select", code = "March_Madness |>\n select(YEAR, TEAM, POWER.RATING)",
opts = list(label = "\"select\"", exercise = "TRUE",
exercise.eval = "FALSE"), 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 = "Intro-to-Data-Science_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 = "Intro-to-Data-Science_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, exercise.timelimit = 60, exercise.checker = "function (label = NULL, solution_code = NULL, user_code = NULL, \n check_code = NULL, envir_result = NULL, evaluate_result = NULL, \n envir_prep = NULL, last_value = NULL, stage = NULL, ..., \n solution_eval_fn = NULL) \n{\n (utils::getFromNamespace(\"check_exercise\", \"gradethis\"))(label = label, \n solution_code = solution_code, user_code = user_code, \n check_code = check_code, envir_result = envir_result, \n evaluate_result = evaluate_result, envir_prep = envir_prep, \n last_value = last_value, stage = stage, ...)\n}",
exercise.error.check.code = "gradethis_error_checker()",
label = "select", exercise = TRUE, exercise.eval = FALSE,
code = c("March_Madness |>", " select(YEAR, TEAM, POWER.RATING)"
), out.width.px = 624, out.height.px = 384, params.src = "select, exercise=TRUE, exercise.eval = FALSE",
fig.num = 0, exercise.df_print = "paged"), engine = "r",
version = "4"), class = c("r", "tutorial_exercise")))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-tennessee-PowerRating-trend-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-tennessee-PowerRating-trend-code-editor`)), session)
output$`tutorial-exercise-tennessee-PowerRating-trend-output` <- renderUI({
`tutorial-exercise-tennessee-PowerRating-trend-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "tennessee-PowerRating-trend", global_setup = structure(c("library(learnr)",
"library(readr)", "library(tidyverse)", "library(ggplot2)", "knitr::opts_chunk$set(echo = TRUE, eval = FALSE)",
"tutorial_options(exercise.timelimit = 60)", "gradethis::gradethis_setup()",
"March_Madness <- read.csv(\"March_Madness_Data.csv\")", "tennessee_data <- March_Madness %>%",
" filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%",
" select(YEAR, TEAM, POWER.RATING)", "Purdue_data <- March_Madness %>%",
" filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)"), chunk_opts = list(
label = "setup", include = FALSE)), setup = NULL, chunks = list(
list(label = "tennessee-PowerRating-trend", code = "# Filter data for Tennessee and select relevant columns (YEAR, TEAM, POWER RATING) for years 2021 to 2023\ntennessee_data <- March_Madness %>%\n filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%\n select(YEAR, TEAM, POWER.RATING)\n\n# Plot Power Rating over the years using ggplot2 as a line plot\nggplot(tennessee_data, aes(x = YEAR, y = POWER.RATING)) +\n geom_line(color = \"orange\") + \n geom_point() + \n labs(title = \"Tennessee Vols Power Rating Trend in past 3 years' March Madness\", x = \"Year\", y = \"Power Rating\") +\n theme_minimal()",
opts = list(label = "\"tennessee-PowerRating-trend\"",
exercise = "TRUE", exercise.eval = "FALSE"), 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 = "Intro-to-Data-Science_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 = "Intro-to-Data-Science_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, exercise.timelimit = 60, exercise.checker = "function (label = NULL, solution_code = NULL, user_code = NULL, \n check_code = NULL, envir_result = NULL, evaluate_result = NULL, \n envir_prep = NULL, last_value = NULL, stage = NULL, ..., \n solution_eval_fn = NULL) \n{\n (utils::getFromNamespace(\"check_exercise\", \"gradethis\"))(label = label, \n solution_code = solution_code, user_code = user_code, \n check_code = check_code, envir_result = envir_result, \n evaluate_result = evaluate_result, envir_prep = envir_prep, \n last_value = last_value, stage = stage, ...)\n}",
exercise.error.check.code = "gradethis_error_checker()",
label = "tennessee-PowerRating-trend", exercise = TRUE,
exercise.eval = FALSE, code = c("# Filter data for Tennessee and select relevant columns (YEAR, TEAM, POWER RATING) for years 2021 to 2023",
"tennessee_data <- March_Madness %>%", " filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%",
" select(YEAR, TEAM, POWER.RATING)", "", "# Plot Power Rating over the years using ggplot2 as a line plot",
"ggplot(tennessee_data, aes(x = YEAR, y = POWER.RATING)) +",
" geom_line(color = \"orange\") + ", " geom_point() + ",
" labs(title = \"Tennessee Vols Power Rating Trend in past 3 years' March Madness\", x = \"Year\", y = \"Power Rating\") +",
" theme_minimal()"), out.width.px = 624, out.height.px = 384,
params.src = "tennessee-PowerRating-trend, exercise=TRUE,, exercise.eval = FALSE",
fig.num = 0, exercise.df_print = "paged"), engine = "r",
version = "4"), class = c("r", "tutorial_exercise")))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-filter_data_for_Purdue-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-filter_data_for_Purdue-code-editor`)), session)
output$`tutorial-exercise-filter_data_for_Purdue-output` <- renderUI({
`tutorial-exercise-filter_data_for_Purdue-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "filter_data_for_Purdue", global_setup = structure(c("library(learnr)",
"library(readr)", "library(tidyverse)", "library(ggplot2)", "knitr::opts_chunk$set(echo = TRUE, eval = FALSE)",
"tutorial_options(exercise.timelimit = 60)", "gradethis::gradethis_setup()",
"March_Madness <- read.csv(\"March_Madness_Data.csv\")", "tennessee_data <- March_Madness %>%",
" filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%",
" select(YEAR, TEAM, POWER.RATING)", "Purdue_data <- March_Madness %>%",
" filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)"), chunk_opts = list(
label = "setup", include = FALSE)), setup = NULL, chunks = list(
list(label = "filter_data_for_Purdue", code = " \n", opts = list(
label = "\"filter_data_for_Purdue\"", exercise = "TRUE",
exercise.eval = "FALSE"), engine = "r")), code_check = NULL,
error_check = NULL, check = structure(c("gradethis::grade_result(gradethis::pass_if(~identical(.result, Purdue_data <- March_Madness %>%",
" filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023))))"
), chunk_opts = list(label = "filter_data_for_Purdue-check")),
solution = structure(c("Purdue_data <- March_Madness %>%",
" filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)"), chunk_opts = list(
label = "filter_data_for_Purdue-solution")), 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 = "Intro-to-Data-Science_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 = "Intro-to-Data-Science_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, exercise.timelimit = 60, exercise.checker = "function (label = NULL, solution_code = NULL, user_code = NULL, \n check_code = NULL, envir_result = NULL, evaluate_result = NULL, \n envir_prep = NULL, last_value = NULL, stage = NULL, ..., \n solution_eval_fn = NULL) \n{\n (utils::getFromNamespace(\"check_exercise\", \"gradethis\"))(label = label, \n solution_code = solution_code, user_code = user_code, \n check_code = check_code, envir_result = envir_result, \n evaluate_result = evaluate_result, envir_prep = envir_prep, \n last_value = last_value, stage = stage, ...)\n}",
exercise.error.check.code = "gradethis_error_checker()",
label = "filter_data_for_Purdue", exercise = TRUE, exercise.eval = FALSE,
code = c(" ", ""), out.width.px = 624, out.height.px = 384,
params.src = "filter_data_for_Purdue, exercise = TRUE, exercise.eval = FALSE",
fig.num = 0L, exercise.df_print = "paged"), engine = "r",
version = "4"), class = c("r", "tutorial_exercise")))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-select_the_relevant_columns-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-select_the_relevant_columns-code-editor`)), session)
output$`tutorial-exercise-select_the_relevant_columns-output` <- renderUI({
`tutorial-exercise-select_the_relevant_columns-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "select_the_relevant_columns", global_setup = structure(c("library(learnr)",
"library(readr)", "library(tidyverse)", "library(ggplot2)", "knitr::opts_chunk$set(echo = TRUE, eval = FALSE)",
"tutorial_options(exercise.timelimit = 60)", "gradethis::gradethis_setup()",
"March_Madness <- read.csv(\"March_Madness_Data.csv\")", "tennessee_data <- March_Madness %>%",
" filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%",
" select(YEAR, TEAM, POWER.RATING)", "Purdue_data <- March_Madness %>%",
" filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)"), chunk_opts = list(
label = "setup", include = FALSE)), setup = NULL, chunks = list(
list(label = "select_the_relevant_columns", code = " \n",
opts = list(label = "\"select_the_relevant_columns\"",
exercise = "TRUE", exercise.eval = "FALSE"), engine = "r")),
code_check = NULL, error_check = NULL, check = structure(c("gradethis::grade_result(gradethis::pass_if(~identical(.result, Purdue_data <- Purdue_data %>%",
" select(YEAR, TEAM, POWER.RATING))))"), chunk_opts = list(
label = "select_the_relevant_columns-check")), solution = structure(c("Purdue_data <- Purdue_data %>%",
" select(YEAR, TEAM, POWER.RATING)"), chunk_opts = list(
label = "select_the_relevant_columns-solution")), 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 = "Intro-to-Data-Science_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 = "Intro-to-Data-Science_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, exercise.timelimit = 60, exercise.checker = "function (label = NULL, solution_code = NULL, user_code = NULL, \n check_code = NULL, envir_result = NULL, evaluate_result = NULL, \n envir_prep = NULL, last_value = NULL, stage = NULL, ..., \n solution_eval_fn = NULL) \n{\n (utils::getFromNamespace(\"check_exercise\", \"gradethis\"))(label = label, \n solution_code = solution_code, user_code = user_code, \n check_code = check_code, envir_result = envir_result, \n evaluate_result = evaluate_result, envir_prep = envir_prep, \n last_value = last_value, stage = stage, ...)\n}",
exercise.error.check.code = "gradethis_error_checker()",
label = "select_the_relevant_columns", exercise = TRUE,
exercise.eval = FALSE, code = c(" ", ""), out.width.px = 624,
out.height.px = 384, params.src = "select_the_relevant_columns, exercise = TRUE, exercise.eval = FALSE",
fig.num = 0L, exercise.df_print = "paged"), engine = "r",
version = "4"), class = c("r", "tutorial_exercise")))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-create_lineplot_Purdue-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-create_lineplot_Purdue-code-editor`)), session)
output$`tutorial-exercise-create_lineplot_Purdue-output` <- renderUI({
`tutorial-exercise-create_lineplot_Purdue-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "create_lineplot_Purdue", global_setup = structure(c("library(learnr)",
"library(readr)", "library(tidyverse)", "library(ggplot2)", "knitr::opts_chunk$set(echo = TRUE, eval = FALSE)",
"tutorial_options(exercise.timelimit = 60)", "gradethis::gradethis_setup()",
"March_Madness <- read.csv(\"March_Madness_Data.csv\")", "tennessee_data <- March_Madness %>%",
" filter(TEAM == 'Tennessee', YEAR >= 2021, YEAR <= 2023) %>%",
" select(YEAR, TEAM, POWER.RATING)", "Purdue_data <- March_Madness %>%",
" filter(TEAM == 'Purdue', YEAR >= 2021, YEAR <= 2023)"), chunk_opts = list(
label = "setup", include = FALSE)), setup = NULL, chunks = list(
list(label = "create_lineplot_Purdue", code = " \n", opts = list(
label = "\"create_lineplot_Purdue\"", exercise = "TRUE",
exercise.eval = "FALSE"), engine = "r")), code_check = NULL,
error_check = NULL, check = structure(c("gradethis::grade_result(gradethis::pass_if(~identical(.result, ggplot(Purdue_data, aes(x = YEAR, y = POWER.RATING)) +",
" geom_line(color = \"blue\") + ", " geom_point(color = \"blue\"))))"
), chunk_opts = list(label = "create_lineplot_Purdue-check")),
solution = structure(c("ggplot(Purdue_data, aes(x = YEAR, y = POWER.RATING)) +",
" geom_line(color = \"blue\") + ", " geom_point(color = \"blue\")"
), chunk_opts = list(label = "create_lineplot_Purdue-solution")),
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 = "Intro-to-Data-Science_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 = "Intro-to-Data-Science_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, exercise.timelimit = 60, exercise.checker = "function (label = NULL, solution_code = NULL, user_code = NULL, \n check_code = NULL, envir_result = NULL, evaluate_result = NULL, \n envir_prep = NULL, last_value = NULL, stage = NULL, ..., \n solution_eval_fn = NULL) \n{\n (utils::getFromNamespace(\"check_exercise\", \"gradethis\"))(label = label, \n solution_code = solution_code, user_code = user_code, \n check_code = check_code, envir_result = envir_result, \n evaluate_result = evaluate_result, envir_prep = envir_prep, \n last_value = last_value, stage = stage, ...)\n}",
exercise.error.check.code = "gradethis_error_checker()",
label = "create_lineplot_Purdue", exercise = TRUE, exercise.eval = FALSE,
code = c(" ", ""), out.width.px = 624, out.height.px = 384,
params.src = "create_lineplot_Purdue, exercise = TRUE, exercise.eval = FALSE",
fig.num = 0L, exercise.df_print = "paged"), engine = "r",
version = "4"), class = c("r", "tutorial_exercise")))
</script>
<script type="application/shiny-prerendered" data-context="server">
`tutorial-exercise-power-rating-comparison-result` <- learnr:::setup_exercise_handler(reactive(req(input$`tutorial-exercise-power-rating-comparison-code-editor`)), session)
output$`tutorial-exercise-power-rating-comparison-output` <- renderUI({
`tutorial-exercise-power-rating-comparison-result`()
})
</script>
<script type="application/shiny-prerendered" data-context="server">
learnr:::store_exercise_cache(structure(list(label = "power-rating-comparison", global_setup = structure(c("library(learnr)",