forked from swcarpentry/r-novice-gapminder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
motivation.html
117 lines (116 loc) · 5.15 KB
/
motivation.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title>Software Carpentry: R for reproducible scientific analysis</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-theme.css" />
<link rel="stylesheet" type="text/css" href="css/swc.css" />
<link rel="alternate" type="application/rss+xml" title="Software Carpentry Blog" href="http://software-carpentry.org/feed.xml"/>
<meta charset="UTF-8" />
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="lesson">
<div class="container card">
<div class="banner">
<a href="http://software-carpentry.org" title="Software Carpentry">
<img alt="Software Carpentry banner" src="img/software-carpentry-banner.png" />
</a>
</div>
<article>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<a href="index.html"><h1 class="title">R for reproducible scientific analysis</h1></a>
<h2 class="subtitle">Why Use R?</h2>
<h2 id="why-r">Why R?</h2>
<ul>
<li>Powerful statistical analysis</li>
<li>and powerful visualisation</li>
<li>integrated elegantly</li>
</ul>
<h2 id="what-well-accomplish">What We’ll Accomplish</h2>
<ul>
<li>Get to know R and RStudio</li>
<li>Analyze a meaningful data set</li>
<li>Extract insights and deliver them visually</li>
<li>Leave ready to learn more R independently</li>
</ul>
<h2 id="r-loves-ingesting-data">R loves ingesting data</h2>
<pre><code>gapminder <- read.csv(
"data/gapminder-FiveYearData.csv",
header=TRUE,
sep=',')</code></pre>
<h2 id="data-w-column-names">Data w/ column names</h2>
<p>head(gapminder, 1) # Show me the first row</p>
<p>country year pop continent lifeExp gdpPercap 1 Afghanistan 1952 8425333 Asia 28.801 779.4453</p>
<h2 id="quickly-graph">Quickly graph …</h2>
<pre><code>ggplot(
data=gapminder,
aes(x=lifeExp, y=gdpPercap)
) + geom_point()</code></pre>
<h2 id="to-see-what-we-have">… to see what we have</h2>
<div class="figure">
<img src="img/first_plot.png" alt="First plot" />
<p class="caption">First plot</p>
</div>
<h2 id="lets-graph-more-factors">Let’s graph more factors</h2>
<pre><code>ggplot(
data=gapminder,
aes(x=year, y=lifeExp, by=country, colour=continent)
) + geom_line()
+ geom_point()</code></pre>
<h2 id="pretty">Pretty!</h2>
<div class="figure">
<img src="img/countries_and_colors.png" alt="Countries and colors" />
<p class="caption">Countries and colors</p>
</div>
<h2 id="dyplr-gives-us">dyplr gives us …</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(dplyr)
cors <-<span class="st"> </span>gapminder %>%
<span class="st"> </span><span class="kw">group_by</span>(year) %>%
<span class="st"> </span><span class="kw">summarise</span>(
<span class="dt">gdpPercap.lifeExp =</span> <span class="kw">cor</span>(gdpPercap, lifeExp),
<span class="dt">gdpPercap.pop =</span> <span class="kw">cor</span>(gdpPercap, pop),
<span class="dt">pop.lifeExp =</span> <span class="kw">cor</span>(pop, lifeExp))</code></pre></div>
<h2 id="pairwise-correlations">… pairwise correlations</h2>
<pre><code>head(cors, 1)
Source: local data frame [1 x 4]
year gdpPercap.lifeExp gdpPercap.pop pop.lifeExp
1 1952 0.2780236 -0.02526041 -0.002724782</code></pre>
<h2 id="restructuring-the-table">Restructuring the table …</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(tidyr)
tidy.cors <-<span class="st"> </span>cors %>%<span class="st"> </span><span class="kw">gather</span>(
variables, correlation,
gdpPercap.lifeExp, gdpPercap.pop,
pop.lifeExp)</code></pre></div>
<h2 id="a-subtle-art">… a subtle art …</h2>
<pre><code>head(tidy.cors, 1)
Source: local data frame [1 x 3]
year variables correlation
1 1952 gdpPercap.lifeExp 0.2780236</code></pre>
<h2 id="produces-great-results">… produces great results</h2>
<div class="figure">
<img src="img/gdp_and_life.png" alt="GDP and Life" />
<p class="caption">GDP and Life</p>
</div>
</div>
</div>
</article>
<div class="footer">
<a class="label swc-blue-bg" href="http://software-carpentry.org">Software Carpentry</a>
<a class="label swc-blue-bg" href="https://github.com/swcarpentry/lesson-template">Source</a>
<a class="label swc-blue-bg" href="mailto:[email protected]">Contact</a>
<a class="label swc-blue-bg" href="LICENSE.html">License</a>
</div>
</div>
<!-- Javascript placed at the end of the document so the pages load faster -->
<script src="http://software-carpentry.org/v5/js/jquery-1.9.1.min.js"></script>
<script src="css/bootstrap/bootstrap-js/bootstrap.js"></script>
</body>
</html>