-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathComplete-Ggplot2-Tutorial-Part1-With-R-Code.html
480 lines (427 loc) · 46.6 KB
/
Complete-Ggplot2-Tutorial-Part1-With-R-Code.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
<!DOCTYPE html>
<html>
<head>
<title>The Complete ggplot2 Tutorial - Part1 | Introduction To ggplot2 (Full R code)</title>
<meta charset="utf-8">
<meta name="Description" content="R Language Tutorials for Advanced Statistics">
<meta name="Keywords" content="R, Tutorial, Machine learning, Statistics, Data Mining, Analytics, Data science, Linear Regression, Logistic Regression, Time series, Forecasting">
<meta name="Distribution" content="Global">
<meta name="Author" content="Selva Prabhakaran">
<meta name="Robots" content="index, follow">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/screenshots/iconb-64.png" type="image/x-icon" />
<link href="www/bootstrap.min.css" rel="stylesheet">
<link href="www/highlight.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Inconsolata:400,700'
rel='stylesheet' type='text/css'>
<!-- Color Script -->
<style type="text/css">
a {
color: #3675C5;
color: rgb(25, 145, 248);
color: #4582ec;
color: #3F73D8;
}
li {
line-height: 1.65;
}
/* reduce spacing around math formula*/
.MathJax_Display {
margin: 0em 0em;
}
</style>
<!-- Add Google search -->
<script language="Javascript" type="text/javascript">
function my_search_google()
{
var query = document.getElementById("my-google-search").value;
window.open("http://google.com/search?q=" + query
+ "%20site:" + "http://r-statistics.co");
}
</script>
</head>
<body>
<div class="container">
<div class="masthead">
<!--
<ul class="nav nav-pills pull-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Table of contents<b class="caret"></b>
</a>
<ul class="dropdown-menu pull-right" role="menu">
<li class="dropdown-header"></li>
<li class="dropdown-header">Tutorial</li>
<li><a href="R-Tutorial.html">R Tutorial</a></li>
<li class="dropdown-header">ggplot2</li>
<li><a href="ggplot2-Tutorial-With-R.html">ggplot2 Short Tutorial</a></li>
<li><a href="Complete-Ggplot2-Tutorial-Part1-With-R-Code.html">ggplot2 Tutorial 1 - Intro</a></li>
<li><a href="Complete-Ggplot2-Tutorial-Part2-Customizing-Theme-With-R-Code.html">ggplot2 Tutorial 2 - Theme</a></li>
<li><a href="Top50-Ggplot2-Visualizations-MasterList-R-Code.html">ggplot2 Tutorial 3 - Masterlist</a></li>
<li><a href="ggplot2-cheatsheet.html">ggplot2 Quickref</a></li>
<li class="dropdown-header">Foundations</li>
<li><a href="Linear-Regression.html">Linear Regression</a></li>
<li><a href="Statistical-Tests-in-R.html">Statistical Tests</a></li>
<li><a href="Missing-Value-Treatment-With-R.html">Missing Value Treatment</a></li>
<li><a href="Outlier-Treatment-With-R.html">Outlier Analysis</a></li>
<li><a href="Variable-Selection-and-Importance-With-R.html">Feature Selection</a></li>
<li><a href="Model-Selection-in-R.html">Model Selection</a></li>
<li><a href="Logistic-Regression-With-R.html">Logistic Regression</a></li>
<li><a href="Environments.html">Advanced Linear Regression</a></li>
<li class="dropdown-header">Advanced Regression Models</li>
<li><a href="adv-regression-models.html">Advanced Regression Models</a></li>
<li class="dropdown-header">Time Series</li>
<li><a href="Time-Series-Analysis-With-R.html">Time Series Analysis</a></li>
<li><a href="Time-Series-Forecasting-With-R.html">Time Series Forecasting </a></li>
<li><a href="Time-Series-Forecasting-With-R-part2.html">More Time Series Forecasting</a></li>
<li class="dropdown-header">High Performance Computing</li>
<li><a href="Parallel-Computing-With-R.html">Parallel computing</a></li>
<li><a href="Strategies-To-Improve-And-Speedup-R-Code.html">Strategies to Speedup R code</a></li>
<li class="dropdown-header">Useful Techniques</li>
<li><a href="Association-Mining-With-R.html">Association Mining</a></li>
<li><a href="Multi-Dimensional-Scaling-With-R.html">Multi Dimensional Scaling</a></li>
<li><a href="Profiling.html">Optimization</a></li>
<li><a href="Information-Value-With-R.html">InformationValue package</a></li>
</ul>
</li>
</ul>
-->
<ul class="nav nav-pills pull-right">
<div class="input-group">
<form onsubmit="my_search_google()">
<input type="text" class="form-control" id="my-google-search" placeholder="Search..">
<form>
</div><!-- /input-group -->
</ul><!-- /.col-lg-6 -->
<h3 class="muted"><a href="/">r-statistics.co</a><small> by Selva Prabhakaran</small></h3>
<hr>
</div>
<div class="row">
<div class="col-xs-12 col-sm-3" id="nav">
<div class="well">
<li>
<ul class="list-unstyled">
<li class="dropdown-header"></li>
<li class="dropdown-header">Tutorial</li>
<li><a href="R-Tutorial.html">R Tutorial</a></li>
<li class="dropdown-header">ggplot2</li>
<li><a href="ggplot2-Tutorial-With-R.html">ggplot2 Short Tutorial</a></li>
<li><a href="Complete-Ggplot2-Tutorial-Part1-With-R-Code.html">ggplot2 Tutorial 1 - Intro</a></li>
<li><a href="Complete-Ggplot2-Tutorial-Part2-Customizing-Theme-With-R-Code.html">ggplot2 Tutorial 2 - Theme</a></li>
<li><a href="Top50-Ggplot2-Visualizations-MasterList-R-Code.html">ggplot2 Tutorial 3 - Masterlist</a></li>
<li><a href="ggplot2-cheatsheet.html">ggplot2 Quickref</a></li>
<li class="dropdown-header">Foundations</li>
<li><a href="Linear-Regression.html">Linear Regression</a></li>
<li><a href="Statistical-Tests-in-R.html">Statistical Tests</a></li>
<li><a href="Missing-Value-Treatment-With-R.html">Missing Value Treatment</a></li>
<li><a href="Outlier-Treatment-With-R.html">Outlier Analysis</a></li>
<li><a href="Variable-Selection-and-Importance-With-R.html">Feature Selection</a></li>
<li><a href="Model-Selection-in-R.html">Model Selection</a></li>
<li><a href="Logistic-Regression-With-R.html">Logistic Regression</a></li>
<li><a href="Environments.html">Advanced Linear Regression</a></li>
<li class="dropdown-header">Advanced Regression Models</li>
<li><a href="adv-regression-models.html">Advanced Regression Models</a></li>
<li class="dropdown-header">Time Series</li>
<li><a href="Time-Series-Analysis-With-R.html">Time Series Analysis</a></li>
<li><a href="Time-Series-Forecasting-With-R.html">Time Series Forecasting </a></li>
<li><a href="Time-Series-Forecasting-With-R-part2.html">More Time Series Forecasting</a></li>
<li class="dropdown-header">High Performance Computing</li>
<li><a href="Parallel-Computing-With-R.html">Parallel computing</a></li>
<li><a href="Strategies-To-Improve-And-Speedup-R-Code.html">Strategies to Speedup R code</a></li>
<li class="dropdown-header">Useful Techniques</li>
<li><a href="Association-Mining-With-R.html">Association Mining</a></li>
<li><a href="Multi-Dimensional-Scaling-With-R.html">Multi Dimensional Scaling</a></li>
<li><a href="Profiling.html">Optimization</a></li>
<li><a href="Information-Value-With-R.html">InformationValue package</a></li>
</ul>
</li>
</div>
<div class="well">
<p>Stay up-to-date. <a href="https://docs.google.com/forms/d/1xkMYkLNFU9U39Dd8S_2JC0p8B5t6_Yq6zUQjanQQJpY/viewform">Subscribe!</a></p>
<p><a href="https://docs.google.com/forms/d/13GrkCFcNa-TOIllQghsz2SIEbc-YqY9eJX02B19l5Ow/viewform">Chat!</a></p>
</div>
<h4>Contents</h4>
<ul class="list-unstyled" id="toc"></ul>
<!--
<hr>
<p><a href="/contribute.html">How to contribute</a></p>
<p><a class="btn btn-primary" href="">Edit this page</a></p>
-->
</div>
<div id="content" class="col-xs-12 col-sm-8 pull-right">
<h1>The Complete ggplot2 Tutorial - Part1 | Introduction To ggplot2 (Full R code)</h1>
<blockquote>
<p>Previously we saw a brief <a href="ggplot2-Tutorial-With-R.html">tutorial</a> of making charts with ggplot2 package. It quickly touched upon the various aspects of making ggplot. Now, this is a complete and full fledged tutorial. I start from scratch and discuss how to construct and customize almost any ggplot. It goes into the principles, steps and nuances of making the plots effective and more visually appealing. So, for practical purposes I hope this tutorial serves well as a bookmark reference that will be useful for your day-to-day plotmaking.</p>
</blockquote>
<p>This is part 1 of a three part tutorial on ggplot2, an aesthetically pleasing (and very popular) graphics framework in R. This tutorial is primarily geared towards those having some basic knowledge of the R programming language and want to make complex and nice looking charts with R ggplot2.</p>
<ul>
<li><p><a href="Complete-Ggplot2-Tutorial-Part1-With-R-Code.html">Part 1: Introduction to ggplot2</a>, covers the basic knowledge about constructing simple ggplots and modifying the components and aesthetics.</p></li>
<li><p><a href="Complete-Ggplot2-Tutorial-Part2-Customizing-Theme-With-R-Code.html">Part 2: Customizing the Look and Feel</a>, is about more advanced customization like manipulating legend, annotations, multiplots with faceting and custom layouts</p></li>
<li><p><a href="Top50-Ggplot2-Visualizations-MasterList-R-Code.html">Part 3: Top 50 Ggplot2 Visualizations - The Master List</a>, applies what was learnt in part 1 and 2 to construct other types of ggplots such as bar charts, boxplots etc.</p></li>
</ul>
<h3>Part 1: Introduction to ggplot2</h3>
<ol style="list-style-type: decimal">
<li><a href="Complete-Ggplot2-Tutorial-Part1-With-R-Code.html#1.%20Understanding%20the%20general%20ggplot%20format">Understanding the Ggplot Syntax</a></li>
<li><a href="Complete-Ggplot2-Tutorial-Part1-With-R-Code.html#2.%20Making%20a%20simple%20scatter%20plot">How to Making a Simple Scatterplot</a></li>
<li><a href="Complete-Ggplot2-Tutorial-Part1-With-R-Code.html#3.%20Adjusting%20the%20X%20and%20Y%20axis%20limits">How to Adjust the X and Y Axis Limits</a>
<ul>
<li><a href="#__Method%201__:%20By%20deleting%20the%20points%20outside%20the%20range">Method 1: By Deleting the Points Outside the Range</a></li>
<li><a href="#__Method%202__:%20Zooming%20In">Method 2: Zooming In</a></li>
</ul></li>
<li><a href="Complete-Ggplot2-Tutorial-Part1-With-R-Code.html#4.%20Changing%20the%20title%20and%20axis%20labels">How to Change the Title and Axis Labels</a></li>
<li><a href="Complete-Ggplot2-Tutorial-Part1-With-R-Code.html#5.%20Changing%20the%20color%20and%20size%20of%20points">How to Change the Color and Size of Points</a>
<ul>
<li><a href="#How%20to%20Change%20the%20Color%20and%20Size%20To%20Static">Change the Color and Size To Static</a></li>
<li><a href="#How%20to%20Change%20the%20Color%20To%20Reflect%20Categories%20in%20Another%20Column">Change the Color To Reflect Categories in Another Column</a></li>
</ul></li>
<li><a href="Complete-Ggplot2-Tutorial-Part1-With-R-Code.html#6.%20How%20to%20Change%20the%20X%20Axis%20Texts%20and%20Ticks%20Location">How to Change the X Axis Texts and Ticks Location</a>
<ul>
<li><a href="#How%20to%20Change%20the%20X%20and%20Y%20Axis%20Text%20and%20its%20Location">Change the X and Y Axis Text and its Location?</a></li>
<li><a href="#How%20to%20Write%20Customized%20Texts%20for%20Axis%20Labels,%20by%20Formatting%20the%20Original%20Values">Write Customized Texts for Axis Labels, by Formatting the Original Values?</a></li>
<li><a href="#How%20to%20Customize%20the%20Entire%20Theme%20in%20One%20Shot%20using%20Pre-Built%20Themes">Customize the Entire Theme in One Shot using Pre-Built Themes?</a></li>
</ul></li>
</ol>
<h2>1. Understanding the Ggplot Syntax</h2>
<p>The syntax for constructing ggplots could be puzzling if you are a beginner or work primarily with base graphics. The main difference is that, unlike base graphics, ggplot works with dataframes and not individual vectors. All the data needed to make the plot is typically be contained within the dataframe supplied to the <code>ggplot()</code> itself or can be supplied to respective geoms. More on that later.</p>
<p>The second noticeable feature is that you can keep enhancing the plot by adding more layers (and themes) to an existing plot created using the <code>ggplot()</code> function.</p>
<p>Let’s initialize a basic ggplot based on the midwest dataset.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Setup</span>
<span class="kw">options</span>(<span class="dt">scipen=</span><span class="dv">999</span>) <span class="co"># turn off scientific notation like 1e+06</span>
<span class="kw">library</span>(ggplot2)
<span class="kw">data</span>(<span class="st">"midwest"</span>, <span class="dt">package =</span> <span class="st">"ggplot2"</span>) <span class="co"># load the data</span>
<span class="co"># midwest <- read.csv("http://goo.gl/G1K41K") # alt source </span>
<span class="co"># Init Ggplot</span>
<span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) <span class="co"># area and poptotal are columns in 'midwest'</span></code></pre></div>
<p><img src="screenshots/ggplot_tut_1.png" alt="Ggplot Canvas" /></p>
<p>A blank ggplot is drawn. Even though the <code>x</code> and <code>y</code> are specified, there are no points or lines in it. This is because, ggplot doesn’t assume that you meant a scatterplot or a line chart to be drawn. I have only told ggplot what dataset to use and what columns should be used for X and Y axis. I haven’t explicitly asked it to draw any points.</p>
<p>Also note that <code>aes()</code> function is used to specify the X and Y axes. That’s because, any information that is part of the source dataframe has to be specified inside the <code>aes()</code> function.</p>
<h2>2. How to Make a Simple Scatterplot</h2>
<p>Let’s make a scatterplot on top of the blank ggplot by adding points using a geom layer called <code>geom_point</code>.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
<span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span><span class="kw">geom_point</span>()</code></pre></div>
<p><img src="screenshots/ggplot_tut_2.png" alt="Ggplot Scatterplot" /></p>
<p>We got a basic scatterplot, where each point represents a county. However, it lacks some basic components such as the plot title, meaningful axis labels etc. Moreover most of the points are concentrated on the bottom portion of the plot, which is not so nice. You will see how to rectify these in upcoming steps.</p>
<p>Like <code>geom_point()</code>, there are many such geom layers which we will see in a subsequent part in this tutorial series. For now, let’s just add a smoothing layer using <code>geom_smooth(method='lm')</code>. Since the <code>method</code> is set as <code>lm</code> (short for <a href="Linear-Regression.html"><em>linear model</em></a>), it draws the line of best fit.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
g <-<span class="st"> </span><span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>) <span class="co"># set se=FALSE to turnoff confidence bands</span>
<span class="kw">plot</span>(g)</code></pre></div>
<p><img src="screenshots/ggplot_tut_3.png" alt="Ggplot Scatterplot" /></p>
<p>The line of best fit is in blue. Can you find out what other <code>method</code> options are available for <code>geom_smooth</code>? (note: see <code>?geom_smooth</code>). You might have noticed that majority of points lie in the bottom of the chart which doesn’t really look nice. So, let’s change the Y-axis limits to focus on the lower half.</p>
<h2>3. Adjusting the X and Y axis limits</h2>
<p>The X and Y axis limits can be controlled in 2 ways.</p>
<h3><a name="__Method 1__: By deleting the points outside the range"></a><strong>Method 1</strong>: By deleting the points outside the range</h3>
<p>This will change the lines of best fit or smoothing lines as compared to the original data.</p>
<p>This can be done by <code>xlim()</code> and <code>ylim()</code>. You can pass a numeric vector of length 2 (with max and min values) or just the max and min values itself.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
g <-<span class="st"> </span><span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>) <span class="co"># set se=FALSE to turnoff confidence bands</span>
<span class="co"># Delete the points outside the limits</span>
g +<span class="st"> </span><span class="kw">xlim</span>(<span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.1</span>)) +<span class="st"> </span><span class="kw">ylim</span>(<span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1000000</span>)) <span class="co"># deletes points</span>
<span class="co"># g + xlim(0, 0.1) + ylim(0, 1000000) # deletes points</span></code></pre></div>
<p><img src="screenshots/ggplot_tut_4.png" alt="Ggplot Scatterplot" /></p>
<p>In this case, the chart was not built from scratch but rather was built on top of <code>g</code>. This is because, the previous plot was stored as <code>g</code>, a ggplot object, which when called will reproduce the original plot. Using ggplot, you can add more layers, themes and other settings on top of this plot.</p>
<p>Did you notice that the line of best fit became more horizontal compared to the original plot? This is because, when using <code>xlim()</code> and <code>ylim()</code>, the points outside the specified range are deleted and will not be considered while drawing the line of best fit (using <code>geom_smooth(method='lm')</code>). This feature might come in handy when you wish to know how the line of best fit would change when some extreme values (or outliers) are removed.</p>
<h3><a name="__Method 2__: Zooming In"></a><strong>Method 2</strong>: Zooming In</h3>
<p>The other method is to change the X and Y axis limits by zooming in to the region of interest <em>without</em> deleting the points. This is done using <code>coord_cartesian()</code>.</p>
<p>Let’s store this plot as <code>g1</code>.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
g <-<span class="st"> </span><span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>) <span class="co"># set se=FALSE to turnoff confidence bands</span>
<span class="co"># Zoom in without deleting the points outside the limits. </span>
<span class="co"># As a result, the line of best fit is the same as the original plot.</span>
g1 <-<span class="st"> </span>g +<span class="st"> </span><span class="kw">coord_cartesian</span>(<span class="dt">xlim=</span><span class="kw">c</span>(<span class="dv">0</span>,<span class="fl">0.1</span>), <span class="dt">ylim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1000000</span>)) <span class="co"># zooms in</span>
<span class="kw">plot</span>(g1)</code></pre></div>
<p><img src="screenshots/ggplot_tut_5.png" alt="Ggplot Scatterplot" /></p>
<p>Since all points were considered, the line of best fit did not change.</p>
<h2>4. How to Change the Title and Axis Labels</h2>
<p>I have stored this as <code>g1</code>. Let’s add the plot title and labels for X and Y axis. This can be done in one go using the <code>labs()</code> function with <code>title</code>, <code>x</code> and <code>y</code> arguments. Another option is to use the <code>ggtitle()</code>, <code>xlab()</code> and <code>ylab()</code>.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
g <-<span class="st"> </span><span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>) <span class="co"># set se=FALSE to turnoff confidence bands</span>
g1 <-<span class="st"> </span>g +<span class="st"> </span><span class="kw">coord_cartesian</span>(<span class="dt">xlim=</span><span class="kw">c</span>(<span class="dv">0</span>,<span class="fl">0.1</span>), <span class="dt">ylim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1000000</span>)) <span class="co"># zooms in</span>
<span class="co"># Add Title and Labels</span>
g1 +<span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span><span class="st">"Area Vs Population"</span>, <span class="dt">subtitle=</span><span class="st">"From midwest dataset"</span>, <span class="dt">y=</span><span class="st">"Population"</span>, <span class="dt">x=</span><span class="st">"Area"</span>, <span class="dt">caption=</span><span class="st">"Midwest Demographics"</span>)
<span class="co"># or</span>
g1 +<span class="st"> </span><span class="kw">ggtitle</span>(<span class="st">"Area Vs Population"</span>, <span class="dt">subtitle=</span><span class="st">"From midwest dataset"</span>) +<span class="st"> </span><span class="kw">xlab</span>(<span class="st">"Area"</span>) +<span class="st"> </span><span class="kw">ylab</span>(<span class="st">"Population"</span>)</code></pre></div>
<p><img src="screenshots/ggplot_tut_6.png" alt="Ggplot Scatterplot" /></p>
<p>Excellent! So here is the full function call.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Full Plot call</span>
<span class="kw">library</span>(ggplot2)
<span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>) +<span class="st"> </span>
<span class="st"> </span><span class="kw">coord_cartesian</span>(<span class="dt">xlim=</span><span class="kw">c</span>(<span class="dv">0</span>,<span class="fl">0.1</span>), <span class="dt">ylim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1000000</span>)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span><span class="st">"Area Vs Population"</span>, <span class="dt">subtitle=</span><span class="st">"From midwest dataset"</span>, <span class="dt">y=</span><span class="st">"Population"</span>, <span class="dt">x=</span><span class="st">"Area"</span>, <span class="dt">caption=</span><span class="st">"Midwest Demographics"</span>)</code></pre></div>
<h2>5. How to Change the Color and Size of Points</h2>
<h3><a name="How to Change the Color and Size To Static"></a>How to Change the Color and Size To Static?</h3>
<p>We can change the aesthetics of a geom layer by modifying the respective geoms. Let’s change the color of the points and the line to a static value.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
<span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>(<span class="dt">col=</span><span class="st">"steelblue"</span>, <span class="dt">size=</span><span class="dv">3</span>) +<span class="st"> </span><span class="co"># Set static color and size for points</span>
<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>, <span class="dt">col=</span><span class="st">"firebrick"</span>) +<span class="st"> </span><span class="co"># change the color of line</span>
<span class="st"> </span><span class="kw">coord_cartesian</span>(<span class="dt">xlim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.1</span>), <span class="dt">ylim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1000000</span>)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span><span class="st">"Area Vs Population"</span>, <span class="dt">subtitle=</span><span class="st">"From midwest dataset"</span>, <span class="dt">y=</span><span class="st">"Population"</span>, <span class="dt">x=</span><span class="st">"Area"</span>, <span class="dt">caption=</span><span class="st">"Midwest Demographics"</span>)</code></pre></div>
<p><img src="screenshots/ggplot_tut_7.png" alt="Ggplot Scatterplot" /></p>
<h3><a name="How to Change the Color To Reflect Categories in Another Column"></a>How to Change the Color To Reflect Categories in Another Column?</h3>
<p>Suppose if we want the color to change based on another column in the source dataset (<code>midwest</code>), it must be specified inside the <code>aes()</code> function.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
gg <-<span class="st"> </span><span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>(<span class="kw">aes</span>(<span class="dt">col=</span>state), <span class="dt">size=</span><span class="dv">3</span>) +<span class="st"> </span><span class="co"># Set color to vary based on state categories.</span>
<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>, <span class="dt">col=</span><span class="st">"firebrick"</span>, <span class="dt">size=</span><span class="dv">2</span>) +<span class="st"> </span>
<span class="st"> </span><span class="kw">coord_cartesian</span>(<span class="dt">xlim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.1</span>), <span class="dt">ylim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1000000</span>)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span><span class="st">"Area Vs Population"</span>, <span class="dt">subtitle=</span><span class="st">"From midwest dataset"</span>, <span class="dt">y=</span><span class="st">"Population"</span>, <span class="dt">x=</span><span class="st">"Area"</span>, <span class="dt">caption=</span><span class="st">"Midwest Demographics"</span>)
<span class="kw">plot</span>(gg)</code></pre></div>
<p><img src="screenshots/ggplot_tut_9.png" alt="Ggplot Scatterplot" /></p>
<p>Now each point is colored based on the <code>state</code> it belongs because of <code>aes(col=state)</code>. Not just color, but <code>size</code>, <code>shape</code>, <code>stroke</code> (thickness of boundary) and <code>fill</code> (fill color) can be used to discriminate groupings.</p>
<p>As an added benefit, the legend is added automatically. If needed, it can be removed by setting the <code>legend.position</code> to <code>None</code> from within a <code>theme()</code> function.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">gg +<span class="st"> </span><span class="kw">theme</span>(<span class="dt">legend.position=</span><span class="st">"None"</span>) <span class="co"># remove legend</span></code></pre></div>
<p>Also, You can change the color palette entirely.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">gg +<span class="st"> </span><span class="kw">scale_colour_brewer</span>(<span class="dt">palette =</span> <span class="st">"Set1"</span>) <span class="co"># change color palette</span></code></pre></div>
<p><img src="screenshots/ggplot_tut_10.png" alt="Ggplot Scatterplot" /></p>
<p>More of such palettes can be found in the RColorBrewer package</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(RColorBrewer)
<span class="kw">head</span>(brewer.pal.info, <span class="dv">10</span>) <span class="co"># show 10 palettes</span>
<span class="co">#> maxcolors category colorblind</span>
<span class="co">#> BrBG 11 div TRUE</span>
<span class="co">#> PiYG 11 div TRUE</span>
<span class="co">#> PRGn 11 div TRUE</span>
<span class="co">#> PuOr 11 div TRUE</span>
<span class="co">#> RdBu 11 div TRUE</span>
<span class="co">#> RdGy 11 div FALSE</span>
<span class="co">#> RdYlBu 11 div TRUE</span>
<span class="co">#> RdYlGn 11 div FALSE</span>
<span class="co">#> Spectral 11 div FALSE</span>
<span class="co">#> Accent 8 qual FALSE</span></code></pre></div>
<p><img src='screenshots/color_palettes.png' width='503' height='1257' /></p>
<h2>6. How to Change the X Axis Texts and Ticks Location</h2>
<h3><a name="How to Change the X and Y Axis Text and its Location"></a>How to Change the X and Y Axis Text and its Location?</h3>
<p>Alright, now let’s see how to change the X and Y axis text and its location. This involves two aspects: <code>breaks</code> and <code>labels</code>.</p>
<ol style="list-style-type: decimal">
<li><strong>Step 1: Set the <code>breaks</code></strong><br />
The <code>breaks</code> should be of the same scale as the X axis variable. Note that I am using <code>scale_x_continuous</code> because, the X axis variable is a continuous variable. Had it been a date variable, <code>scale_x_date</code> could be used. Like <code>scale_x_continuous()</code> an equivalent <code>scale_y_continuous()</code> is available for Y axis.</li>
</ol>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
<span class="co"># Base plot</span>
gg <-<span class="st"> </span><span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>(<span class="kw">aes</span>(<span class="dt">col=</span>state), <span class="dt">size=</span><span class="dv">3</span>) +<span class="st"> </span><span class="co"># Set color to vary based on state categories.</span>
<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>, <span class="dt">col=</span><span class="st">"firebrick"</span>, <span class="dt">size=</span><span class="dv">2</span>) +<span class="st"> </span>
<span class="st"> </span><span class="kw">coord_cartesian</span>(<span class="dt">xlim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.1</span>), <span class="dt">ylim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1000000</span>)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span><span class="st">"Area Vs Population"</span>, <span class="dt">subtitle=</span><span class="st">"From midwest dataset"</span>, <span class="dt">y=</span><span class="st">"Population"</span>, <span class="dt">x=</span><span class="st">"Area"</span>, <span class="dt">caption=</span><span class="st">"Midwest Demographics"</span>)
<span class="co"># Change breaks</span>
gg +<span class="st"> </span><span class="kw">scale_x_continuous</span>(<span class="dt">breaks=</span><span class="kw">seq</span>(<span class="dv">0</span>, <span class="fl">0.1</span>, <span class="fl">0.01</span>))</code></pre></div>
<p><img src="screenshots/ggplot_tut_11.png" alt="Changing breaks in ggplot2" /></p>
<ol start="2" style="list-style-type: decimal">
<li><strong>Step 2: Change the <code>labels</code></strong> You can optionally change the <code>labels</code> at the axis ticks. <code>labels</code> take a vector of the same length as <code>breaks</code>.</li>
</ol>
<p>Let me demonstrate by setting the <code>labels</code> to alphabets from a to k (though there is no meaning to it in this context).</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplots)
<span class="co"># Base Plot</span>
gg <-<span class="st"> </span><span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>(<span class="kw">aes</span>(<span class="dt">col=</span>state), <span class="dt">size=</span><span class="dv">3</span>) +<span class="st"> </span><span class="co"># Set color to vary based on state categories.</span>
<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>, <span class="dt">col=</span><span class="st">"firebrick"</span>, <span class="dt">size=</span><span class="dv">2</span>) +<span class="st"> </span>
<span class="st"> </span><span class="kw">coord_cartesian</span>(<span class="dt">xlim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.1</span>), <span class="dt">ylim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1000000</span>)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span><span class="st">"Area Vs Population"</span>, <span class="dt">subtitle=</span><span class="st">"From midwest dataset"</span>, <span class="dt">y=</span><span class="st">"Population"</span>, <span class="dt">x=</span><span class="st">"Area"</span>, <span class="dt">caption=</span><span class="st">"Midwest Demographics"</span>)
<span class="co"># Change breaks + label</span>
gg +<span class="st"> </span><span class="kw">scale_x_continuous</span>(<span class="dt">breaks=</span><span class="kw">seq</span>(<span class="dv">0</span>, <span class="fl">0.1</span>, <span class="fl">0.01</span>), <span class="dt">labels =</span> letters[<span class="dv">1</span>:<span class="dv">11</span>])</code></pre></div>
<p><img src="screenshots/ggplot_tut_12.png" alt="How to change axis lables in ggplot2" /></p>
<p>If you need to reverse the scale, use <code>scale_x_reverse()</code>.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
gg <-<span class="st"> </span><span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>(<span class="kw">aes</span>(<span class="dt">col=</span>state), <span class="dt">size=</span><span class="dv">3</span>) +<span class="st"> </span><span class="co"># Set color to vary based on state categories.</span>
<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>, <span class="dt">col=</span><span class="st">"firebrick"</span>, <span class="dt">size=</span><span class="dv">2</span>) +<span class="st"> </span>
<span class="st"> </span><span class="kw">coord_cartesian</span>(<span class="dt">xlim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.1</span>), <span class="dt">ylim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1000000</span>)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span><span class="st">"Area Vs Population"</span>, <span class="dt">subtitle=</span><span class="st">"From midwest dataset"</span>, <span class="dt">y=</span><span class="st">"Population"</span>, <span class="dt">x=</span><span class="st">"Area"</span>, <span class="dt">caption=</span><span class="st">"Midwest Demographics"</span>)
<span class="co"># Reverse X Axis Scale</span>
gg +<span class="st"> </span><span class="kw">scale_x_reverse</span>()</code></pre></div>
<p><img src="screenshots/ggplot_tut_13.png" alt="How to reverse the axis scales in ggplot2" /></p>
<h3><a name="How to Write Customized Texts for Axis Labels, by Formatting the Original Values"></a>How to Write Customized Texts for Axis Labels, by Formatting the Original Values?</h3>
<p>Let’s set the <code>breaks</code> for Y axis text as well and format the X and Y axis labels. I have used 2 methods for formatting labels: * <strong>Method 1</strong>: Using <code>sprintf()</code>. (Have formatted it as % in below example) * <strong>Method 2</strong>: Using a custom user defined function. (Formatted 1000’s to 1K scale)</p>
<p>Use whichever method feels convenient.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
<span class="co"># Base Plot</span>
gg <-<span class="st"> </span><span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>(<span class="kw">aes</span>(<span class="dt">col=</span>state), <span class="dt">size=</span><span class="dv">3</span>) +<span class="st"> </span><span class="co"># Set color to vary based on state categories.</span>
<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>, <span class="dt">col=</span><span class="st">"firebrick"</span>, <span class="dt">size=</span><span class="dv">2</span>) +<span class="st"> </span>
<span class="st"> </span><span class="kw">coord_cartesian</span>(<span class="dt">xlim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.1</span>), <span class="dt">ylim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1000000</span>)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span><span class="st">"Area Vs Population"</span>, <span class="dt">subtitle=</span><span class="st">"From midwest dataset"</span>, <span class="dt">y=</span><span class="st">"Population"</span>, <span class="dt">x=</span><span class="st">"Area"</span>, <span class="dt">caption=</span><span class="st">"Midwest Demographics"</span>)
<span class="co"># Change Axis Texts</span>
gg +<span class="st"> </span><span class="kw">scale_x_continuous</span>(<span class="dt">breaks=</span><span class="kw">seq</span>(<span class="dv">0</span>, <span class="fl">0.1</span>, <span class="fl">0.01</span>), <span class="dt">labels =</span> <span class="kw">sprintf</span>(<span class="st">"%1.2f%%"</span>, <span class="kw">seq</span>(<span class="dv">0</span>, <span class="fl">0.1</span>, <span class="fl">0.01</span>))) +<span class="st"> </span>
<span class="st"> </span><span class="kw">scale_y_continuous</span>(<span class="dt">breaks=</span><span class="kw">seq</span>(<span class="dv">0</span>, <span class="dv">1000000</span>, <span class="dv">200000</span>), <span class="dt">labels =</span> function(x){<span class="kw">paste0</span>(x/<span class="dv">1000</span>, <span class="st">'K'</span>)})</code></pre></div>
<p><img src="screenshots/ggplot_tut_14.png" alt="How to format axis texts in ggplot2" /></p>
<h3><a name="How to Customize the Entire Theme in One Shot using Pre-Built Themes"></a>How to Customize the Entire Theme in One Shot using Pre-Built Themes?</h3>
<p>Finally, instead of changing the theme components individually (which I discuss in detail in <a href="Complete-Ggplot2-Tutorial-Part2-Customizing-Theme-With-R-Code.html">part 2</a>), we can change the entire theme itself using pre-built themes. The help page <code>?theme_bw</code> shows all the available built-in themes.</p>
<p>This again is commonly done in couple of ways. * Use the theme_set() to set the theme before drawing the ggplot. Note that this setting will affect all future plots. * Draw the ggplot and then add the overall theme setting (eg. <code>theme_bw()</code>)</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
<span class="co"># Base plot</span>
gg <-<span class="st"> </span><span class="kw">ggplot</span>(midwest, <span class="kw">aes</span>(<span class="dt">x=</span>area, <span class="dt">y=</span>poptotal)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>(<span class="kw">aes</span>(<span class="dt">col=</span>state), <span class="dt">size=</span><span class="dv">3</span>) +<span class="st"> </span><span class="co"># Set color to vary based on state categories.</span>
<span class="st"> </span><span class="kw">geom_smooth</span>(<span class="dt">method=</span><span class="st">"lm"</span>, <span class="dt">col=</span><span class="st">"firebrick"</span>, <span class="dt">size=</span><span class="dv">2</span>) +<span class="st"> </span>
<span class="st"> </span><span class="kw">coord_cartesian</span>(<span class="dt">xlim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.1</span>), <span class="dt">ylim=</span><span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1000000</span>)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">labs</span>(<span class="dt">title=</span><span class="st">"Area Vs Population"</span>, <span class="dt">subtitle=</span><span class="st">"From midwest dataset"</span>, <span class="dt">y=</span><span class="st">"Population"</span>, <span class="dt">x=</span><span class="st">"Area"</span>, <span class="dt">caption=</span><span class="st">"Midwest Demographics"</span>)
gg <-<span class="st"> </span>gg +<span class="st"> </span><span class="kw">scale_x_continuous</span>(<span class="dt">breaks=</span><span class="kw">seq</span>(<span class="dv">0</span>, <span class="fl">0.1</span>, <span class="fl">0.01</span>))
<span class="co"># method 1: Using theme_set()</span>
<span class="kw">theme_set</span>(<span class="kw">theme_classic</span>()) <span class="co"># not run</span>
gg
<span class="co"># method 2: Adding theme Layer itself.</span>
gg +<span class="st"> </span><span class="kw">theme_bw</span>() +<span class="st"> </span><span class="kw">labs</span>(<span class="dt">subtitle=</span><span class="st">"BW Theme"</span>)
gg +<span class="st"> </span><span class="kw">theme_classic</span>() +<span class="st"> </span><span class="kw">labs</span>(<span class="dt">subtitle=</span><span class="st">"Classic Theme"</span>)</code></pre></div>
<p><img src="screenshots/ggplot_tut_16.png" alt="Ggplot2 Black and White Theme" /> <img src="screenshots/ggplot_tut_17.png" alt="Ggplot2 Classic Theme" /></p>
<p>For more customized and fancy themes have a look at the <a href="https://github.com/jrnold/ggthemes">ggthemes</a> package and the <a href="https://github.com/cttobin/ggthemr">ggthemr</a> package.</p>
<p>That’s it for the basics. We are now ably positioned to tackle more advanced customization. In <a href="Complete-Ggplot2-Tutorial-Part2-Customizing-Theme-With-R-Code.html">ggplot tutorial part-2</a>, I discuss about advanced customization on modifying theme components, manipulating legend, annotations, faceting and custom layouts.</p>
<hr />
<p>Have a suggestion or found a bug? Notify <a href="https://docs.google.com/forms/d/e/1FAIpQLSeIJmlvwe562R7JVpi5J2ydLyhk5-7OrGRMFGYrMJvjPal8eA/viewform">here.</a></p>
</div>
</div>
<div class="footer">
<hr>
<p>© 2016-17 Selva Prabhakaran. Powered by <a href="http://jekyllrb.com/">jekyll</a>,
<a href="http://yihui.name/knitr/">knitr</a>, and
<a href="http://johnmacfarlane.net/pandoc/">pandoc</a>.
This work is licensed under the <a href="http://creativecommons.org/licenses/by-nc/3.0/">Creative Commons License.</a>
</p>
</div>
</div> <!-- /container -->
<script src="//code.jquery.com/jquery.js"></script>
<script src="www/bootstrap.min.js"></script>
<script src="www/toc.js"></script>
<!-- MathJax Script -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Google Analytics Code -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-69351797-1', 'auto');
ga('send', 'pageview');
</script>
<style type="text/css">
/* reduce spacing around math formula*/
.MathJax_Display {
margin: 0em 0em;
}
body {
font-family: 'Helvetica Neue', Roboto, Arial, sans-serif;
font-size: 16px;
line-height: 27px;
font-weight: 400;
}
blockquote p {
line-height: 1.75;
color: #717171;
}
.well li{
line-height: 28px;
}
li.dropdown-header {
display: block;
padding: 0px;
font-size: 14px;
}
</style>
</body>
</html>