-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharts.html
More file actions
563 lines (524 loc) · 76.8 KB
/
charts.html
File metadata and controls
563 lines (524 loc) · 76.8 KB
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
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>R User Notebook</title>
<meta name="description" content="A notebook of useful R code and concepts">
<meta name="generator" content="bookdown 0.7 and GitBook 2.6.7">
<meta property="og:title" content="R User Notebook" />
<meta property="og:type" content="book" />
<meta property="og:description" content="A notebook of useful R code and concepts" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="R User Notebook" />
<meta name="twitter:description" content="A notebook of useful R code and concepts" />
<meta name="author" content="Kieran Driscoll">
<meta name="date" content="2019-02-11">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="prev" href="tables.html">
<link rel="next" href="maps.html">
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<script src="libs/htmlwidgets-1.0/htmlwidgets.js"></script>
<link href="libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet" />
<script src="libs/datatables-binding-0.4/datatables.js"></script>
<link href="libs/dt-core-1.10.16/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="libs/dt-core-1.10.16/css/jquery.dataTables.extra.css" rel="stylesheet" />
<script src="libs/dt-core-1.10.16/js/jquery.dataTables.min.js"></script>
<link href="libs/crosstalk-1.0.0/css/crosstalk.css" rel="stylesheet" />
<script src="libs/crosstalk-1.0.0/js/crosstalk.min.js"></script>
<link href="libs/nouislider-7.0.10/jquery.nouislider.min.css" rel="stylesheet" />
<script src="libs/nouislider-7.0.10/jquery.nouislider.min.js"></script>
<link href="libs/selectize-0.12.0/selectize.bootstrap3.css" rel="stylesheet" />
<script src="libs/selectize-0.12.0/selectize.min.js"></script>
<link href="libs/dygraphs-1.1.1/dygraph.css" rel="stylesheet" />
<script src="libs/dygraphs-1.1.1/dygraph-combined.js"></script>
<script src="libs/moment-2.8.4/moment.js"></script>
<script src="libs/moment-timezone-0.2.5/moment-timezone-with-data.js"></script>
<script src="libs/moment-fquarter-1.0.0/moment-fquarter.min.js"></script>
<script src="libs/dygraphs-binding-1.1.1.4/dygraphs.js"></script>
<link href="libs/leaflet-1.3.1/leaflet.css" rel="stylesheet" />
<script src="libs/leaflet-1.3.1/leaflet.js"></script>
<link href="libs/leafletfix-1.0.0/leafletfix.css" rel="stylesheet" />
<script src="libs/Proj4Leaflet-1.0.1/proj4-compressed.js"></script>
<script src="libs/Proj4Leaflet-1.0.1/proj4leaflet.js"></script>
<link href="libs/rstudio_leaflet-1.3.1/rstudio_leaflet.css" rel="stylesheet" />
<script src="libs/leaflet-binding-2.0.2/leaflet.js"></script>
<script src="libs/d3-4.3.0/d3.min.js"></script>
<script src="libs/d3-lasso-0.0.5/d3-lasso.min.js"></script>
<link href="libs/ggiraph-0.3.0/styles.css" rel="stylesheet" />
<script src="libs/ggiraph-0.3.0/ggiraph_utils.js"></script>
<script src="libs/ggiraph-0.3.0/ggiraph_over_effect.js"></script>
<script src="libs/ggiraph-0.3.0/ggiraph_zoom.js"></script>
<script src="libs/ggiraph-0.3.0/ggiraph_tooltip.js"></script>
<script src="libs/ggiraph-0.3.0/ggiraph_selector.js"></script>
<script src="libs/ggiraph-binding-0.4.4/ggiraph.js"></script>
<script src="libs/svg_1-0.0.1/scripts_svg_1.js"></script>
<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
{ position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
{ content: attr(data-line-number);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; pointer-events: all; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter" data-level="1" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i><b>1</b> R User Notebook</a></li>
<li class="chapter" data-level="2" data-path="basic-concepts.html"><a href="basic-concepts.html"><i class="fa fa-check"></i><b>2</b> Basic Concepts</a><ul>
<li class="chapter" data-level="2.1" data-path="basic-concepts.html"><a href="basic-concepts.html#vectors"><i class="fa fa-check"></i><b>2.1</b> Vectors</a></li>
<li class="chapter" data-level="2.2" data-path="basic-concepts.html"><a href="basic-concepts.html#matrices"><i class="fa fa-check"></i><b>2.2</b> Matrices</a></li>
<li class="chapter" data-level="2.3" data-path="basic-concepts.html"><a href="basic-concepts.html#dataframes"><i class="fa fa-check"></i><b>2.3</b> Dataframes</a></li>
<li class="chapter" data-level="2.4" data-path="basic-concepts.html"><a href="basic-concepts.html#tibbles"><i class="fa fa-check"></i><b>2.4</b> Tibbles</a></li>
<li class="chapter" data-level="2.5" data-path="basic-concepts.html"><a href="basic-concepts.html#extracting-data-from-dataframestibbles"><i class="fa fa-check"></i><b>2.5</b> Extracting data from Dataframes/Tibbles</a></li>
<li class="chapter" data-level="2.6" data-path="basic-concepts.html"><a href="basic-concepts.html#lists"><i class="fa fa-check"></i><b>2.6</b> Lists</a></li>
<li class="chapter" data-level="2.7" data-path="basic-concepts.html"><a href="basic-concepts.html#factors"><i class="fa fa-check"></i><b>2.7</b> Factors</a></li>
<li class="chapter" data-level="2.8" data-path="basic-concepts.html"><a href="basic-concepts.html#dates"><i class="fa fa-check"></i><b>2.8</b> Dates</a></li>
<li class="chapter" data-level="2.9" data-path="basic-concepts.html"><a href="basic-concepts.html#style-guide"><i class="fa fa-check"></i><b>2.9</b> Style Guide</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="importing-exporting.html"><a href="importing-exporting.html"><i class="fa fa-check"></i><b>3</b> Importing & Exporting</a><ul>
<li class="chapter" data-level="3.1" data-path="importing-exporting.html"><a href="importing-exporting.html#importing-with-base-r"><i class="fa fa-check"></i><b>3.1</b> Importing with Base R</a></li>
<li class="chapter" data-level="3.2" data-path="importing-exporting.html"><a href="importing-exporting.html#importing-with-other-packages"><i class="fa fa-check"></i><b>3.2</b> Importing with other packages</a><ul>
<li class="chapter" data-level="3.2.1" data-path="importing-exporting.html"><a href="importing-exporting.html#importing-a-csv"><i class="fa fa-check"></i><b>3.2.1</b> Importing a CSV</a></li>
<li class="chapter" data-level="3.2.2" data-path="importing-exporting.html"><a href="importing-exporting.html#importing-a-tsv"><i class="fa fa-check"></i><b>3.2.2</b> Importing a TSV</a></li>
<li class="chapter" data-level="3.2.3" data-path="importing-exporting.html"><a href="importing-exporting.html#importing-a-r-data-file"><i class="fa fa-check"></i><b>3.2.3</b> Importing a R data file</a></li>
<li class="chapter" data-level="3.2.4" data-path="importing-exporting.html"><a href="importing-exporting.html#importing-a-excel-file"><i class="fa fa-check"></i><b>3.2.4</b> Importing a Excel file</a></li>
<li class="chapter" data-level="3.2.5" data-path="importing-exporting.html"><a href="importing-exporting.html#importing-a-sas-file"><i class="fa fa-check"></i><b>3.2.5</b> Importing a SAS file</a></li>
<li class="chapter" data-level="3.2.6" data-path="importing-exporting.html"><a href="importing-exporting.html#importing-json-newline-delimited-json"><i class="fa fa-check"></i><b>3.2.6</b> Importing JSON (Newline Delimited JSON)</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="importing-exporting.html"><a href="importing-exporting.html#exporting"><i class="fa fa-check"></i><b>3.3</b> Exporting</a><ul>
<li class="chapter" data-level="3.3.1" data-path="importing-exporting.html"><a href="importing-exporting.html#write-to-an-r-dataset"><i class="fa fa-check"></i><b>3.3.1</b> Write to an R dataset</a></li>
<li class="chapter" data-level="3.3.2" data-path="importing-exporting.html"><a href="importing-exporting.html#write-to-an-csv-file"><i class="fa fa-check"></i><b>3.3.2</b> Write to an CSV file</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="4" data-path="manipulating-data.html"><a href="manipulating-data.html"><i class="fa fa-check"></i><b>4</b> Manipulating data</a><ul>
<li class="chapter" data-level="4.1" data-path="manipulating-data.html"><a href="manipulating-data.html#basic-data-wrangling"><i class="fa fa-check"></i><b>4.1</b> Basic data wrangling</a></li>
<li class="chapter" data-level="4.2" data-path="manipulating-data.html"><a href="manipulating-data.html#summary-statistics"><i class="fa fa-check"></i><b>4.2</b> Summary statistics</a></li>
<li class="chapter" data-level="4.3" data-path="manipulating-data.html"><a href="manipulating-data.html#conditional-statements"><i class="fa fa-check"></i><b>4.3</b> Conditional statements</a></li>
<li class="chapter" data-level="4.4" data-path="manipulating-data.html"><a href="manipulating-data.html#recode"><i class="fa fa-check"></i><b>4.4</b> Recode</a></li>
<li class="chapter" data-level="4.5" data-path="manipulating-data.html"><a href="manipulating-data.html#appending-columns-and-rows"><i class="fa fa-check"></i><b>4.5</b> Appending columns and rows</a></li>
<li class="chapter" data-level="4.6" data-path="manipulating-data.html"><a href="manipulating-data.html#joins"><i class="fa fa-check"></i><b>4.6</b> Joins</a></li>
<li class="chapter" data-level="4.7" data-path="manipulating-data.html"><a href="manipulating-data.html#tidy-data"><i class="fa fa-check"></i><b>4.7</b> Tidy Data</a></li>
<li class="chapter" data-level="4.8" data-path="manipulating-data.html"><a href="manipulating-data.html#tibbles-1"><i class="fa fa-check"></i><b>4.8</b> tibbles</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="functions.html"><a href="functions.html"><i class="fa fa-check"></i><b>5</b> Functions</a><ul>
<li class="chapter" data-level="5.1" data-path="functions.html"><a href="functions.html#function-basics---an-example-using-str"><i class="fa fa-check"></i><b>5.1</b> Function Basics - an example using str()</a></li>
<li class="chapter" data-level="5.2" data-path="functions.html"><a href="functions.html#common-base-functions"><i class="fa fa-check"></i><b>5.2</b> Common (base) functions</a><ul>
<li class="chapter" data-level="5.2.1" data-path="functions.html"><a href="functions.html#strings"><i class="fa fa-check"></i><b>5.2.1</b> Strings</a></li>
<li class="chapter" data-level="5.2.2" data-path="functions.html"><a href="functions.html#mathematical"><i class="fa fa-check"></i><b>5.2.2</b> Mathematical</a></li>
<li class="chapter" data-level="5.2.3" data-path="functions.html"><a href="functions.html#properties-lookups"><i class="fa fa-check"></i><b>5.2.3</b> Properties & Lookups</a></li>
<li class="chapter" data-level="5.2.4" data-path="functions.html"><a href="functions.html#transformation"><i class="fa fa-check"></i><b>5.2.4</b> Transformation</a></li>
<li class="chapter" data-level="5.2.5" data-path="functions.html"><a href="functions.html#other-useful-functions"><i class="fa fa-check"></i><b>5.2.5</b> Other useful functions</a></li>
</ul></li>
<li class="chapter" data-level="5.3" data-path="functions.html"><a href="functions.html#stringr---more-string-functions"><i class="fa fa-check"></i><b>5.3</b> Stringr - more string functions</a></li>
<li class="chapter" data-level="5.4" data-path="functions.html"><a href="functions.html#lubridate---more-date-functions"><i class="fa fa-check"></i><b>5.4</b> Lubridate - more date functions</a></li>
<li class="chapter" data-level="5.5" data-path="functions.html"><a href="functions.html#converting-data-to-other-formats"><i class="fa fa-check"></i><b>5.5</b> Converting data to other formats</a><ul>
<li class="chapter" data-level="5.5.1" data-path="functions.html"><a href="functions.html#json"><i class="fa fa-check"></i><b>5.5.1</b> JSON</a></li>
</ul></li>
<li class="chapter" data-level="5.6" data-path="functions.html"><a href="functions.html#user-defined-functions"><i class="fa fa-check"></i><b>5.6</b> User Defined Functions</a></li>
<li class="chapter" data-level="5.7" data-path="functions.html"><a href="functions.html#chainingpiping"><i class="fa fa-check"></i><b>5.7</b> Chaining/Piping</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="loops.html"><a href="loops.html"><i class="fa fa-check"></i><b>6</b> Loops</a><ul>
<li class="chapter" data-level="6.1" data-path="loops.html"><a href="loops.html#basic-for-loop-structure"><i class="fa fa-check"></i><b>6.1</b> Basic for Loop structure</a></li>
<li class="chapter" data-level="6.2" data-path="loops.html"><a href="loops.html#looping-through-a-vector"><i class="fa fa-check"></i><b>6.2</b> Looping through a vector</a></li>
<li class="chapter" data-level="6.3" data-path="loops.html"><a href="loops.html#creating-a-list-in-a-loop"><i class="fa fa-check"></i><b>6.3</b> Creating a List in a Loop</a></li>
<li class="chapter" data-level="6.4" data-path="loops.html"><a href="loops.html#looping-with-apply-functions"><i class="fa fa-check"></i><b>6.4</b> Looping with apply functions</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="tables.html"><a href="tables.html"><i class="fa fa-check"></i><b>7</b> Tables</a><ul>
<li class="chapter" data-level="7.1" data-path="tables.html"><a href="tables.html#displaying-tables---htmltable"><i class="fa fa-check"></i><b>7.1</b> Displaying tables - htmlTable</a></li>
<li class="chapter" data-level="7.2" data-path="tables.html"><a href="tables.html#displaying-interactive-tables---dt"><i class="fa fa-check"></i><b>7.2</b> Displaying Interactive tables - DT</a></li>
<li class="chapter" data-level="7.3" data-path="tables.html"><a href="tables.html#creating-tabulations"><i class="fa fa-check"></i><b>7.3</b> Creating Tabulations</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="charts.html"><a href="charts.html"><i class="fa fa-check"></i><b>8</b> Charts</a><ul>
<li class="chapter" data-level="8.0.1" data-path="charts.html"><a href="charts.html#static-charts-with-ggplot2"><i class="fa fa-check"></i><b>8.0.1</b> Static charts with ggplot2</a></li>
<li class="chapter" data-level="8.0.2" data-path="charts.html"><a href="charts.html#changing-axes"><i class="fa fa-check"></i><b>8.0.2</b> Changing Axes</a></li>
<li class="chapter" data-level="8.0.3" data-path="charts.html"><a href="charts.html#chart-themes-styles"><i class="fa fa-check"></i><b>8.0.3</b> Chart Themes & Styles</a></li>
<li class="chapter" data-level="8.0.4" data-path="charts.html"><a href="charts.html#line-charts-geom_line"><i class="fa fa-check"></i><b>8.0.4</b> Line Charts (geom_line)</a></li>
<li class="chapter" data-level="8.0.5" data-path="charts.html"><a href="charts.html#bar-charts-geom_bar-geom_histogram"><i class="fa fa-check"></i><b>8.0.5</b> Bar Charts (geom_bar & geom_histogram)</a></li>
<li class="chapter" data-level="8.0.6" data-path="charts.html"><a href="charts.html#adding-features"><i class="fa fa-check"></i><b>8.0.6</b> Adding features</a></li>
<li class="chapter" data-level="8.0.7" data-path="charts.html"><a href="charts.html#heatmaps"><i class="fa fa-check"></i><b>8.0.7</b> Heatmaps</a></li>
<li class="chapter" data-level="8.0.8" data-path="charts.html"><a href="charts.html#boxplots"><i class="fa fa-check"></i><b>8.0.8</b> Boxplots</a></li>
<li class="chapter" data-level="8.0.9" data-path="charts.html"><a href="charts.html#combination-charts"><i class="fa fa-check"></i><b>8.0.9</b> Combination Charts</a></li>
<li class="chapter" data-level="8.0.10" data-path="charts.html"><a href="charts.html#scales"><i class="fa fa-check"></i><b>8.0.10</b> Scales</a></li>
<li class="chapter" data-level="8.0.11" data-path="charts.html"><a href="charts.html#ggplot-wizard"><i class="fa fa-check"></i><b>8.0.11</b> ggplot wizard</a></li>
<li class="chapter" data-level="8.0.12" data-path="charts.html"><a href="charts.html#interactive-charts-with-ggiraph"><i class="fa fa-check"></i><b>8.0.12</b> Interactive charts with ggiraph</a></li>
<li class="chapter" data-level="8.0.13" data-path="charts.html"><a href="charts.html#interactive-charts-with-dygraph"><i class="fa fa-check"></i><b>8.0.13</b> Interactive charts with dygraph</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="maps.html"><a href="maps.html"><i class="fa fa-check"></i><b>9</b> Maps</a><ul>
<li class="chapter" data-level="9.1" data-path="maps.html"><a href="maps.html#leaflet"><i class="fa fa-check"></i><b>9.1</b> Leaflet</a><ul>
<li class="chapter" data-level="9.1.1" data-path="maps.html"><a href="maps.html#display-a-basic-map"><i class="fa fa-check"></i><b>9.1.1</b> Display a basic map</a></li>
<li class="chapter" data-level="9.1.2" data-path="maps.html"><a href="maps.html#add-markers-shapes-and-popups-to-a-map"><i class="fa fa-check"></i><b>9.1.2</b> Add markers, shapes and popups to a map</a></li>
<li class="chapter" data-level="9.1.3" data-path="maps.html"><a href="maps.html#add-boundaries"><i class="fa fa-check"></i><b>9.1.3</b> Add Boundaries</a></li>
<li class="chapter" data-level="9.1.4" data-path="maps.html"><a href="maps.html#add-interactivity"><i class="fa fa-check"></i><b>9.1.4</b> Add Interactivity</a></li>
<li class="chapter" data-level="9.1.5" data-path="maps.html"><a href="maps.html#attach-extra-information-to-your-boundary-dataset"><i class="fa fa-check"></i><b>9.1.5</b> Attach extra information to your boundary dataset</a></li>
<li class="chapter" data-level="9.1.6" data-path="maps.html"><a href="maps.html#add-colour-based-on-area-data"><i class="fa fa-check"></i><b>9.1.6</b> Add colour based on area data</a></li>
</ul></li>
<li class="chapter" data-level="9.2" data-path="maps.html"><a href="maps.html#inserting-html-javascript-directly-into-r"><i class="fa fa-check"></i><b>9.2</b> Inserting HTML & Javascript directly into R</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="rmarkdown-knitr.html"><a href="rmarkdown-knitr.html"><i class="fa fa-check"></i><b>10</b> RMarkdown & Knitr</a><ul>
<li class="chapter" data-level="10.1" data-path="rmarkdown-knitr.html"><a href="rmarkdown-knitr.html#knitr"><i class="fa fa-check"></i><b>10.1</b> Knitr</a></li>
<li class="chapter" data-level="10.2" data-path="rmarkdown-knitr.html"><a href="rmarkdown-knitr.html#yaml"><i class="fa fa-check"></i><b>10.2</b> YAML</a></li>
<li class="chapter" data-level="10.3" data-path="rmarkdown-knitr.html"><a href="rmarkdown-knitr.html#modular-coding"><i class="fa fa-check"></i><b>10.3</b> Modular coding</a></li>
</ul></li>
<li class="chapter" data-level="11" data-path="machine-learning-predictive-analytics.html"><a href="machine-learning-predictive-analytics.html"><i class="fa fa-check"></i><b>11</b> Machine Learning & Predictive Analytics</a><ul>
<li class="chapter" data-level="11.0.1" data-path="machine-learning-predictive-analytics.html"><a href="machine-learning-predictive-analytics.html#decision-trees"><i class="fa fa-check"></i><b>11.0.1</b> Decision Trees</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html"><i class="fa fa-check"></i><b>12</b> Text Mining & NLP</a><ul>
<li class="chapter" data-level="12.0.1" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#text-data"><i class="fa fa-check"></i><b>12.0.1</b> Text data</a></li>
<li class="chapter" data-level="12.0.2" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#tidy-text"><i class="fa fa-check"></i><b>12.0.2</b> Tidy text</a></li>
<li class="chapter" data-level="12.0.3" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#stemming"><i class="fa fa-check"></i><b>12.0.3</b> Stemming</a></li>
<li class="chapter" data-level="12.0.4" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#basic-text-stats"><i class="fa fa-check"></i><b>12.0.4</b> Basic text stats</a></li>
<li class="chapter" data-level="12.0.5" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#n-grams-analysis"><i class="fa fa-check"></i><b>12.0.5</b> N-Grams analysis</a></li>
<li class="chapter" data-level="12.0.6" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#text-preparation-with-tm"><i class="fa fa-check"></i><b>12.0.6</b> Text Preparation with <strong>tm</strong></a></li>
<li class="chapter" data-level="12.1" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#create-a-term-document-matrix"><i class="fa fa-check"></i><b>12.1</b> Create a Term Document Matrix</a><ul>
<li class="chapter" data-level="12.1.1" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#from-a-corpus-by-default-words-are-converted-to-lowercase-less-than-3-characters-are-excluded"><i class="fa fa-check"></i><b>12.1.1</b> From a Corpus (by default words are converted to lowercase less than 3 characters are excluded)</a></li>
<li class="chapter" data-level="12.1.2" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#matrix-managment"><i class="fa fa-check"></i><b>12.1.2</b> Matrix Managment</a></li>
</ul></li>
<li class="chapter" data-level="12.2" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#topic-modelling-latent-dirichlet-allocation-lda"><i class="fa fa-check"></i><b>12.2</b> Topic Modelling & Latent Dirichlet Allocation (LDA)</a></li>
<li class="chapter" data-level="12.3" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#clustering---similarity-between-topics"><i class="fa fa-check"></i><b>12.3</b> Clustering - Similarity between topics</a></li>
<li class="chapter" data-level="12.4" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#calculating-distance-between-objects"><i class="fa fa-check"></i><b>12.4</b> Calculating distance between objects</a></li>
<li class="chapter" data-level="12.5" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#non-euclidian-distances---jensen-shannon"><i class="fa fa-check"></i><b>12.5</b> Non-Euclidian Distances - Jensen Shannon</a></li>
<li class="chapter" data-level="12.6" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#scaling---principal-components"><i class="fa fa-check"></i><b>12.6</b> Scaling - Principal Components</a></li>
<li class="chapter" data-level="12.7" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#eigen-vectors"><i class="fa fa-check"></i><b>12.7</b> Eigen vectors</a></li>
<li class="chapter" data-level="12.8" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#k-means"><i class="fa fa-check"></i><b>12.8</b> K-Means</a></li>
<li class="chapter" data-level="12.9" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#naive-bayes-classifiers"><i class="fa fa-check"></i><b>12.9</b> Naive Bayes Classifiers</a></li>
<li class="chapter" data-level="12.10" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#tf-idf-classifiers-supervised"><i class="fa fa-check"></i><b>12.10</b> TF-IDF Classifiers (Supervised)</a></li>
<li class="chapter" data-level="12.11" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#sentiment-analysis"><i class="fa fa-check"></i><b>12.11</b> Sentiment Analysis</a></li>
<li class="chapter" data-level="12.12" data-path="text-mining-nlp.html"><a href="text-mining-nlp.html#word-bubble"><i class="fa fa-check"></i><b>12.12</b> Word Bubble</a></li>
</ul></li>
<li class="chapter" data-level="13" data-path="shiny.html"><a href="shiny.html"><i class="fa fa-check"></i><b>13</b> Shiny</a><ul>
<li class="chapter" data-level="13.1" data-path="shiny.html"><a href="shiny.html#basic-shiny-structure"><i class="fa fa-check"></i><b>13.1</b> Basic Shiny Structure</a></li>
<li class="chapter" data-level="13.2" data-path="shiny.html"><a href="shiny.html#user-interface"><i class="fa fa-check"></i><b>13.2</b> User Interface</a><ul>
<li class="chapter" data-level="13.2.1" data-path="shiny.html"><a href="shiny.html#layout"><i class="fa fa-check"></i><b>13.2.1</b> Layout</a></li>
<li class="chapter" data-level="13.2.2" data-path="shiny.html"><a href="shiny.html#inputs"><i class="fa fa-check"></i><b>13.2.2</b> Inputs</a></li>
<li class="chapter" data-level="13.2.3" data-path="shiny.html"><a href="shiny.html#outputs"><i class="fa fa-check"></i><b>13.2.3</b> Outputs</a></li>
</ul></li>
<li class="chapter" data-level="13.3" data-path="shiny.html"><a href="shiny.html#server"><i class="fa fa-check"></i><b>13.3</b> Server</a><ul>
<li class="chapter" data-level="13.3.1" data-path="shiny.html"><a href="shiny.html#linking-to-ui-outputs"><i class="fa fa-check"></i><b>13.3.1</b> Linking to UI outputs</a></li>
<li class="chapter" data-level="13.3.2" data-path="shiny.html"><a href="shiny.html#linking-to-ui-inputs"><i class="fa fa-check"></i><b>13.3.2</b> Linking to UI inputs</a></li>
</ul></li>
<li class="chapter" data-level="13.4" data-path="shiny.html"><a href="shiny.html#shiny-dashboard"><i class="fa fa-check"></i><b>13.4</b> Shiny Dashboard</a></li>
</ul></li>
<li class="chapter" data-level="14" data-path="bookdown.html"><a href="bookdown.html"><i class="fa fa-check"></i><b>14</b> Bookdown</a><ul>
<li class="chapter" data-level="14.1" data-path="bookdown.html"><a href="bookdown.html#set-up"><i class="fa fa-check"></i><b>14.1</b> Set-up</a></li>
<li class="chapter" data-level="14.2" data-path="bookdown.html"><a href="bookdown.html#create-the-book"><i class="fa fa-check"></i><b>14.2</b> Create the book</a></li>
</ul></li>
<li class="chapter" data-level="15" data-path="creating-packages.html"><a href="creating-packages.html"><i class="fa fa-check"></i><b>15</b> Creating Packages</a><ul>
<li class="chapter" data-level="15.1" data-path="creating-packages.html"><a href="creating-packages.html#setup-folders"><i class="fa fa-check"></i><b>15.1</b> Setup Folders</a></li>
<li class="chapter" data-level="15.2" data-path="creating-packages.html"><a href="creating-packages.html#r-folder"><i class="fa fa-check"></i><b>15.2</b> R folder</a></li>
<li class="chapter" data-level="15.3" data-path="creating-packages.html"><a href="creating-packages.html#man-folder"><i class="fa fa-check"></i><b>15.3</b> man folder</a></li>
<li class="chapter" data-level="15.4" data-path="creating-packages.html"><a href="creating-packages.html#package-details"><i class="fa fa-check"></i><b>15.4</b> Package details</a></li>
<li class="chapter" data-level="15.5" data-path="creating-packages.html"><a href="creating-packages.html#package-dependencies"><i class="fa fa-check"></i><b>15.5</b> Package Dependencies</a></li>
<li class="chapter" data-level="15.6" data-path="creating-packages.html"><a href="creating-packages.html#build-the-package"><i class="fa fa-check"></i><b>15.6</b> Build the package</a></li>
<li class="chapter" data-level="15.7" data-path="creating-packages.html"><a href="creating-packages.html#making-changes"><i class="fa fa-check"></i><b>15.7</b> Making changes</a></li>
</ul></li>
<li class="chapter" data-level="16" data-path="git-version-control.html"><a href="git-version-control.html"><i class="fa fa-check"></i><b>16</b> Git - Version Control</a><ul>
<li class="chapter" data-level="16.1" data-path="git-version-control.html"><a href="git-version-control.html#set-up-1"><i class="fa fa-check"></i><b>16.1</b> Set-up</a></li>
<li class="chapter" data-level="16.2" data-path="git-version-control.html"><a href="git-version-control.html#link-git-to-a-github-account"><i class="fa fa-check"></i><b>16.2</b> Link Git to a GitHub account</a></li>
<li class="chapter" data-level="16.3" data-path="git-version-control.html"><a href="git-version-control.html#starting-a-project-with-github"><i class="fa fa-check"></i><b>16.3</b> Starting a project with Github</a></li>
<li class="chapter" data-level="16.4" data-path="git-version-control.html"><a href="git-version-control.html#hosting-a-site-on-github"><i class="fa fa-check"></i><b>16.4</b> Hosting a site on Github</a></li>
</ul></li>
<li class="chapter" data-level="17" data-path="other-languages.html"><a href="other-languages.html"><i class="fa fa-check"></i><b>17</b> Other Languages</a><ul>
<li class="chapter" data-level="17.1" data-path="other-languages.html"><a href="other-languages.html#sql"><i class="fa fa-check"></i><b>17.1</b> SQL</a></li>
<li class="chapter" data-level="17.2" data-path="other-languages.html"><a href="other-languages.html#python"><i class="fa fa-check"></i><b>17.2</b> Python</a></li>
</ul></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">R User Notebook</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="charts" class="section level1">
<h1><span class="header-section-number">8</span> Charts</h1>
<p>There are various ways to create charts, static or interactive, in R.</p>
<div id="static-charts-with-ggplot2" class="section level3">
<h3><span class="header-section-number">8.0.1</span> Static charts with ggplot2</h3>
<p>Static charts can be created with <strong>ggplot2</strong> (in PNG format). By default they have a width=7 and height=5. You can alter this in the code chunk options: <strong>{r fig.width=8, fig.height=4}</strong><br />
For full reference see: <a href="http://ggplot2.tidyverse.org/reference/index.html" class="uri">http://ggplot2.tidyverse.org/reference/index.html</a></p>
<div class="sourceCode" id="cb125"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb125-1" data-line-number="1"><span class="kw">library</span>(ggplot2)</a>
<a class="sourceLine" id="cb125-2" data-line-number="2"></a>
<a class="sourceLine" id="cb125-3" data-line-number="3">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> hp, <span class="dt">y =</span> mpg)) <span class="op">+</span></a>
<a class="sourceLine" id="cb125-4" data-line-number="4"><span class="st"> </span><span class="kw">geom_point</span>(<span class="dt">colour=</span><span class="st">"red"</span>, <span class="dt">size=</span><span class="dv">2</span>)</a></code></pre></div>
<p><img src="_main_files/figure-html4/CHARTS-1.png" width="480" /></p>
<div class="sourceCode" id="cb126"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb126-1" data-line-number="1"><span class="co"># The 1st argument in ggplot() should be the name of your dataframe;</span></a>
<a class="sourceLine" id="cb126-2" data-line-number="2"><span class="co"># The 2nd argument should be an aesthetic attribute - this defines which variables will be on the x and y axes.</span></a>
<a class="sourceLine" id="cb126-3" data-line-number="3"><span class="co"># You can now add 'Layers' to the ggplot object using the + symbol. You must have at least one 'geom' layer that specifies what type of chart it is (eg. geom_bar, geom_point, geom_line etc..) </span></a></code></pre></div>
<p>If you only want to chart frequencies, then you only need to specify the x axis variable. In the <strong>geom</strong> layer add stat=“count” to automatically generate a count.f</p>
<div class="sourceCode" id="cb127"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb127-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> hp)) <span class="op">+</span></a>
<a class="sourceLine" id="cb127-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_point</span>(<span class="dt">stat=</span><span class="st">"count"</span>, <span class="dt">colour=</span><span class="st">"red"</span>) </a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-66-1.png" width="480" /></p>
</div>
<div id="changing-axes" class="section level3">
<h3><span class="header-section-number">8.0.2</span> Changing Axes</h3>
<p>By default the axes labels are based on variable names. To change these or add a title use a ‘labs’ layer:</p>
<div class="sourceCode" id="cb128"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb128-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> hp, <span class="dt">y =</span> mpg)) <span class="op">+</span></a>
<a class="sourceLine" id="cb128-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_point</span>(<span class="dt">stat=</span><span class="st">"identity"</span>, <span class="dt">colour=</span><span class="st">"red"</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb128-3" data-line-number="3"><span class="st"> </span><span class="kw">labs</span>(<span class="dt">title =</span> <span class="st">"Cars"</span>, <span class="dt">x =</span> <span class="st">'Horsepower'</span>, <span class="dt">y =</span> <span class="st">"Miles/Gallon"</span>) </a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-67-1.png" width="480" /></p>
<p>The width of the x and y axes are set automatically, but can be changed:</p>
<div class="sourceCode" id="cb129"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb129-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> hp, <span class="dt">y =</span> mpg)) <span class="op">+</span></a>
<a class="sourceLine" id="cb129-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_point</span>(<span class="dt">colour=</span><span class="st">"red"</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb129-3" data-line-number="3"><span class="st"> </span><span class="kw">labs</span>(<span class="dt">title =</span> <span class="st">"Cars"</span>, <span class="dt">x =</span> <span class="st">'Horsepower'</span>, <span class="dt">y =</span> <span class="st">"Miles/Gallon"</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb129-4" data-line-number="4"><span class="st"> </span><span class="kw">expand_limits</span>(<span class="dt">y =</span> <span class="kw">c</span>(<span class="dv">0</span>,<span class="dv">40</span>), <span class="dt">x =</span> <span class="kw">c</span>(<span class="dv">0</span>,<span class="dv">350</span>)) <span class="op">+</span><span class="st"> </span><span class="co"># Customise where the x and y axes start/end</span></a>
<a class="sourceLine" id="cb129-5" data-line-number="5"><span class="st"> </span><span class="kw">scale_y_continuous</span>(<span class="dt">expand=</span><span class="kw">c</span>(<span class="dv">0</span>,<span class="dv">0</span>)) <span class="op">+</span><span class="st"> </span><span class="co"># Removes The gap at the bottom of the y axis</span></a>
<a class="sourceLine" id="cb129-6" data-line-number="6"><span class="st"> </span><span class="kw">scale_x_continuous</span>(<span class="dt">expand=</span><span class="kw">c</span>(<span class="dv">0</span>,<span class="dv">0</span>)) <span class="co"># Removes The gap at left of the x axis</span></a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-68-1.png" width="480" /></p>
</div>
<div id="chart-themes-styles" class="section level3">
<h3><span class="header-section-number">8.0.3</span> Chart Themes & Styles</h3>
<p>You can change the appearance of most elements of the chart use a ‘theme’ layer. There are various templates available such as theme_classic (see <a href="https://ggplot2.tidyverse.org/reference/ggtheme.html" class="uri">https://ggplot2.tidyverse.org/reference/ggtheme.html</a>):</p>
<div class="sourceCode" id="cb130"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb130-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> hp, <span class="dt">y =</span> mpg)) <span class="op">+</span></a>
<a class="sourceLine" id="cb130-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_point</span>(<span class="dt">stat=</span><span class="st">"identity"</span>, <span class="dt">colour=</span><span class="st">"red"</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb130-3" data-line-number="3"><span class="st"> </span><span class="kw">labs</span>(<span class="dt">title =</span> <span class="st">"Car Efficiency"</span>, <span class="dt">x =</span> <span class="st">'Horsepower'</span>, <span class="dt">y =</span> <span class="st">"Miles/Gallon"</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb130-4" data-line-number="4"><span class="st"> </span><span class="kw">expand_limits</span>(<span class="dt">y =</span> <span class="dv">0</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb130-5" data-line-number="5"><span class="st"> </span><span class="kw">scale_y_continuous</span>(<span class="dt">expand=</span><span class="kw">c</span>(<span class="dv">0</span>,<span class="dv">0</span>)) <span class="op">+</span></a>
<a class="sourceLine" id="cb130-6" data-line-number="6"><span class="st"> </span><span class="kw">scale_x_continuous</span>(<span class="dt">expand=</span><span class="kw">c</span>(<span class="dv">0</span>,<span class="dv">0</span>)) <span class="op">+</span></a>
<a class="sourceLine" id="cb130-7" data-line-number="7"><span class="st"> </span><span class="kw">theme_classic</span>()</a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-69-1.png" width="480" /></p>
<p>You can create a customised theme to :
* Change the appeareance of axes (axis.line)<br />
* Change the plot area (panel.background)<br />
* Add/Remove/Change the gridlines (panel.grid.major.x & panel.grid.major.y)<br />
* Change the position and size of the title (plot.title)</p>
<div class="sourceCode" id="cb131"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb131-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> hp, <span class="dt">y =</span> mpg)) <span class="op">+</span></a>
<a class="sourceLine" id="cb131-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_point</span>(<span class="dt">stat=</span><span class="st">"identity"</span>, <span class="dt">colour=</span><span class="st">"red"</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb131-3" data-line-number="3"><span class="st"> </span><span class="kw">theme</span>(<span class="dt">axis.line =</span> <span class="kw">element_line</span>(<span class="dt">colour =</span> <span class="st">"black"</span>, <span class="dt">size =</span> <span class="fl">0.25</span>, <span class="dt">linetype =</span> <span class="st">"solid"</span>)</a>
<a class="sourceLine" id="cb131-4" data-line-number="4"> ,<span class="dt">axis.ticks =</span> <span class="kw">element_blank</span>()</a>
<a class="sourceLine" id="cb131-5" data-line-number="5"> ,<span class="dt">panel.background =</span> <span class="kw">element_blank</span>()</a>
<a class="sourceLine" id="cb131-6" data-line-number="6"> ,<span class="dt">panel.grid.major.y =</span> <span class="kw">element_line</span>(<span class="dt">colour =</span> <span class="st">"blue"</span>, <span class="dt">size =</span> <span class="fl">0.1</span>, <span class="dt">linetype =</span> <span class="st">"dashed"</span>)</a>
<a class="sourceLine" id="cb131-7" data-line-number="7"> ,<span class="dt">panel.grid.major.x =</span> <span class="kw">element_line</span>(<span class="dt">colour =</span> <span class="st">"green"</span>, <span class="dt">size =</span> <span class="fl">0.1</span>, <span class="dt">linetype =</span> <span class="st">"dashed"</span>)</a>
<a class="sourceLine" id="cb131-8" data-line-number="8"> ,<span class="dt">plot.title =</span> <span class="kw">element_text</span>(<span class="dt">hjust =</span> <span class="fl">0.5</span>) ) </a></code></pre></div>
<p>You can create reusable styles and themes, which can be applied to all charts:</p>
<div class="sourceCode" id="cb132"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb132-1" data-line-number="1">custom_axis <-<span class="st"> </span><span class="kw">list</span>(<span class="kw">expand_limits</span>(<span class="dt">y =</span> <span class="dv">0</span>, <span class="dt">x =</span> <span class="dv">0</span>),</a>
<a class="sourceLine" id="cb132-2" data-line-number="2"> <span class="kw">scale_y_continuous</span>(<span class="dt">expand=</span><span class="kw">c</span>(<span class="dv">0</span>,<span class="dv">0</span>)), </a>
<a class="sourceLine" id="cb132-3" data-line-number="3"> <span class="kw">scale_x_continuous</span>(<span class="dt">expand=</span><span class="kw">c</span>(<span class="dv">0</span>,<span class="dv">0</span>)) )</a>
<a class="sourceLine" id="cb132-4" data-line-number="4"></a>
<a class="sourceLine" id="cb132-5" data-line-number="5">custom_theme <-<span class="st"> </span><span class="kw">theme</span>(<span class="dt">axis.line =</span> <span class="kw">element_line</span>(<span class="dt">colour =</span> <span class="st">"grey"</span>, <span class="dt">size =</span> <span class="fl">0.25</span>, <span class="dt">linetype =</span> <span class="st">"solid"</span>)</a>
<a class="sourceLine" id="cb132-6" data-line-number="6"> ,<span class="dt">axis.ticks =</span> <span class="kw">element_blank</span>()</a>
<a class="sourceLine" id="cb132-7" data-line-number="7"> ,<span class="dt">panel.background =</span> <span class="kw">element_blank</span>()</a>
<a class="sourceLine" id="cb132-8" data-line-number="8"> ,<span class="dt">panel.grid.major.y =</span> <span class="kw">element_line</span>(<span class="dt">colour =</span> <span class="st">"grey"</span>, <span class="dt">size =</span> <span class="fl">0.1</span>, <span class="dt">linetype =</span> <span class="st">"dashed"</span>)</a>
<a class="sourceLine" id="cb132-9" data-line-number="9"> ,<span class="dt">panel.grid.major.x =</span> <span class="kw">element_line</span>(<span class="dt">colour =</span> <span class="st">"grey"</span>, <span class="dt">size =</span> <span class="fl">0.1</span>, <span class="dt">linetype =</span> <span class="st">"dashed"</span>)</a>
<a class="sourceLine" id="cb132-10" data-line-number="10"> ,<span class="dt">plot.title =</span> <span class="kw">element_text</span>(<span class="dt">hjust =</span> <span class="fl">0.5</span>) )</a>
<a class="sourceLine" id="cb132-11" data-line-number="11"></a>
<a class="sourceLine" id="cb132-12" data-line-number="12">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> hp, <span class="dt">y =</span> mpg)) <span class="op">+</span></a>
<a class="sourceLine" id="cb132-13" data-line-number="13"><span class="st"> </span><span class="kw">geom_point</span>(<span class="dt">stat=</span><span class="st">"identity"</span>, <span class="dt">colour=</span><span class="st">"red"</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb132-14" data-line-number="14"><span class="st"> </span>custom_axis <span class="op">+</span><span class="st"> </span></a>
<a class="sourceLine" id="cb132-15" data-line-number="15"><span class="st"> </span>custom_theme </a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-71-1.png" width="480" /></p>
</div>
<div id="line-charts-geom_line" class="section level3">
<h3><span class="header-section-number">8.0.4</span> Line Charts (geom_line)</h3>
<div class="sourceCode" id="cb133"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb133-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> cyl)) <span class="op">+</span></a>
<a class="sourceLine" id="cb133-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_line</span>(<span class="dt">stat=</span><span class="st">"count"</span>, <span class="dt">colour=</span><span class="st">"blue"</span>, <span class="dt">size=</span><span class="dv">2</span>)</a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-72-1.png" width="480" /></p>
</div>
<div id="bar-charts-geom_bar-geom_histogram" class="section level3">
<h3><span class="header-section-number">8.0.5</span> Bar Charts (geom_bar & geom_histogram)</h3>
<p><strong>geom_bar</strong> produces basic bar charts and is best used with categorical variables.<br />
<strong>geom_histogram</strong> allows you to choose bin widths to automatically re-group you data, so it is better for continuous variables.</p>
<div class="sourceCode" id="cb134"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb134-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> hp)) <span class="op">+</span></a>
<a class="sourceLine" id="cb134-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_bar</span>(<span class="dt">stat=</span><span class="st">"count"</span>, <span class="dt">fill=</span><span class="st">"orange"</span>, <span class="dt">width=</span><span class="dv">1</span>) <span class="co"># Use **colour=** to set the border colour</span></a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-73-1.png" width="288" /></p>
<div class="sourceCode" id="cb135"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb135-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> hp)) <span class="op">+</span><span class="st"> </span></a>
<a class="sourceLine" id="cb135-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_histogram</span>(<span class="dt">binwidth =</span> <span class="dv">25</span>, <span class="dt">fill=</span><span class="st">"orange"</span>)</a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-73-2.png" width="288" /></p>
<p>To flip a bar chart from vertical to horizontal use ‘coord_flip’</p>
<div class="sourceCode" id="cb136"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb136-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> hp)) <span class="op">+</span><span class="st"> </span></a>
<a class="sourceLine" id="cb136-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_histogram</span>(<span class="dt">binwidth =</span> <span class="dv">25</span>, <span class="dt">fill=</span><span class="st">"orange"</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb136-3" data-line-number="3"><span class="st"> </span><span class="kw">coord_flip</span>()</a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-74-1.png" width="576" /></p>
</div>
<div id="adding-features" class="section level3">
<h3><span class="header-section-number">8.0.6</span> Adding features</h3>
<p>Extra layers can be added to the chart to show additional information.<br />
Vertical or horizontal lines can be used to show statistics.</p>
<div class="sourceCode" id="cb137"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb137-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> hp)) <span class="op">+</span><span class="st"> </span></a>
<a class="sourceLine" id="cb137-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_histogram</span>(<span class="dt">binwidth =</span> <span class="dv">25</span>, <span class="dt">alpha=</span><span class="fl">0.5</span>, <span class="dt">fill=</span><span class="st">"orange"</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb137-3" data-line-number="3"><span class="st"> </span><span class="kw">geom_vline</span>(<span class="kw">aes</span>(<span class="dt">xintercept =</span> <span class="kw">median</span>(hp)),<span class="dt">col=</span><span class="st">'red'</span>,<span class="dt">size=</span><span class="dv">1</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb137-4" data-line-number="4"><span class="st"> </span><span class="kw">geom_vline</span>(<span class="kw">aes</span>(<span class="dt">xintercept =</span> <span class="kw">quantile</span>(hp, <span class="fl">0.25</span>)),<span class="dt">col=</span><span class="st">'red'</span>,<span class="dt">size=</span><span class="fl">0.5</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb137-5" data-line-number="5"><span class="st"> </span><span class="kw">geom_vline</span>(<span class="kw">aes</span>(<span class="dt">xintercept =</span> <span class="kw">quantile</span>(hp, <span class="fl">0.75</span>)),<span class="dt">col=</span><span class="st">'red'</span>,<span class="dt">size=</span><span class="fl">0.5</span>)</a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-75-1.png" width="480" /></p>
</div>
<div id="heatmaps" class="section level3">
<h3><span class="header-section-number">8.0.7</span> Heatmaps</h3>
<div class="sourceCode" id="cb138"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb138-1" data-line-number="1">esoph <span class="op">%>%</span><span class="st"> </span><span class="kw">group_by</span>(agegp, alcgp) <span class="op">%>%</span><span class="st"> </span><span class="kw">summarise</span>(<span class="dt">n =</span> <span class="kw">sum</span>(ncontrols)) <span class="op">%>%</span></a>
<a class="sourceLine" id="cb138-2" data-line-number="2"><span class="st"> </span><span class="kw">ggplot</span>(<span class="kw">aes</span>(<span class="dt">x =</span> agegp, <span class="dt">y =</span> alcgp, <span class="dt">fill =</span> n)) <span class="op">+</span></a>
<a class="sourceLine" id="cb138-3" data-line-number="3"><span class="st"> </span><span class="kw">geom_tile</span>()</a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-76-1.png" width="480" /></p>
</div>
<div id="boxplots" class="section level3">
<h3><span class="header-section-number">8.0.8</span> Boxplots</h3>
<div class="sourceCode" id="cb139"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb139-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(<span class="dt">data =</span> mtcars, <span class="kw">aes</span>(<span class="dt">y =</span> mpg)) <span class="op">+</span></a>
<a class="sourceLine" id="cb139-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_boxplot</span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb139-3" data-line-number="3"><span class="st"> </span><span class="kw">facet_wrap</span>(<span class="kw">vars</span>(cyl))</a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-77-1.png" width="480" /></p>
</div>
<div id="combination-charts" class="section level3">
<h3><span class="header-section-number">8.0.9</span> Combination Charts</h3>
<p>You can have multiple layers, for example bars and points</p>
<div class="sourceCode" id="cb140"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb140-1" data-line-number="1">ggplot2<span class="op">::</span><span class="kw">ggplot</span>(mtcars, <span class="kw">aes</span>(<span class="dt">x =</span> cyl, <span class="dt">y =</span> mpg)) <span class="op">+</span></a>
<a class="sourceLine" id="cb140-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_bar</span>(<span class="dt">stat=</span><span class="st">"identity"</span>) <span class="op">+</span></a>
<a class="sourceLine" id="cb140-3" data-line-number="3"><span class="st"> </span><span class="kw">geom_point</span>()</a></code></pre></div>
<p><img src="_main_files/figure-html4/unnamed-chunk-78-1.png" width="480" /></p>
</div>
<div id="scales" class="section level3">
<h3><span class="header-section-number">8.0.10</span> Scales</h3>
<p><strong>scales</strong> package</p>
</div>
<div id="ggplot-wizard" class="section level3">
<h3><span class="header-section-number">8.0.11</span> ggplot wizard</h3>
<p>The <strong>esquisse</strong> package has a shiny wizard that can generate code for different chart types:</p>
<div class="sourceCode" id="cb141"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb141-1" data-line-number="1">esquisse<span class="op">::</span><span class="kw">esquisser</span>()</a></code></pre></div>
</div>
<div id="interactive-charts-with-ggiraph" class="section level3">
<h3><span class="header-section-number">8.0.12</span> Interactive charts with ggiraph</h3>
<p>The ggiraph package extends ggplot and allows interactivity.</p>
<div class="sourceCode" id="cb142"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb142-1" data-line-number="1"><span class="kw">library</span>(ggiraph)</a></code></pre></div>
<pre><code>## Warning: package 'ggiraph' was built under R version 3.4.4</code></pre>
</div>
<div id="interactive-charts-with-dygraph" class="section level3">
<h3><span class="header-section-number">8.0.13</span> Interactive charts with dygraph</h3>
<p>For interactive time series charts you can use the <strong>dygraph</strong> package which is related to the dygraph javascript library.</p>
<div class="sourceCode" id="cb144"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb144-1" data-line-number="1"><span class="kw">library</span>(dygraphs)</a>
<a class="sourceLine" id="cb144-2" data-line-number="2">lungDeaths <-<span class="st"> </span><span class="kw">cbind</span>(mdeaths, fdeaths) <span class="co">#Creates the data set for the graph</span></a>
<a class="sourceLine" id="cb144-3" data-line-number="3">dygraphs<span class="op">::</span><span class="kw">dygraph</span>(lungDeaths) <span class="co"># Displays the chart with default settings</span></a></code></pre></div>
<div id="htmlwidget-8c22c2dd9ab5d66c7c85" style="width:672px;height:480px;" class="dygraphs html-widget"></div>
<script type="application/json" data-for="htmlwidget-8c22c2dd9ab5d66c7c85">{"x":{"attrs":{"labels":["month","mdeaths","fdeaths"],"legend":"auto","retainDateWindow":false,"axes":{"x":{"pixelsPerLabel":60}}},"scale":"monthly","annotations":[],"shadings":[],"events":[],"format":"date","data":[["1974-01-01T00:00:00.000Z","1974-02-01T00:00:00.000Z","1974-03-01T00:00:00.000Z","1974-04-01T00:00:00.000Z","1974-05-01T00:00:00.000Z","1974-06-01T00:00:00.000Z","1974-07-01T00:00:00.000Z","1974-08-01T00:00:00.000Z","1974-09-01T00:00:00.000Z","1974-10-01T00:00:00.000Z","1974-11-01T00:00:00.000Z","1974-12-01T00:00:00.000Z","1975-01-01T00:00:00.000Z","1975-02-01T00:00:00.000Z","1975-03-01T00:00:00.000Z","1975-04-01T00:00:00.000Z","1975-05-01T00:00:00.000Z","1975-06-01T00:00:00.000Z","1975-07-01T00:00:00.000Z","1975-08-01T00:00:00.000Z","1975-09-01T00:00:00.000Z","1975-10-01T00:00:00.000Z","1975-11-01T00:00:00.000Z","1975-12-01T00:00:00.000Z","1976-01-01T00:00:00.000Z","1976-02-01T00:00:00.000Z","1976-03-01T00:00:00.000Z","1976-04-01T00:00:00.000Z","1976-05-01T00:00:00.000Z","1976-06-01T00:00:00.000Z","1976-07-01T00:00:00.000Z","1976-08-01T00:00:00.000Z","1976-09-01T00:00:00.000Z","1976-10-01T00:00:00.000Z","1976-11-01T00:00:00.000Z","1976-12-01T00:00:00.000Z","1977-01-01T00:00:00.000Z","1977-02-01T00:00:00.000Z","1977-03-01T00:00:00.000Z","1977-04-01T00:00:00.000Z","1977-05-01T00:00:00.000Z","1977-06-01T00:00:00.000Z","1977-07-01T00:00:00.000Z","1977-08-01T00:00:00.000Z","1977-09-01T00:00:00.000Z","1977-10-01T00:00:00.000Z","1977-11-01T00:00:00.000Z","1977-12-01T00:00:00.000Z","1978-01-01T00:00:00.000Z","1978-02-01T00:00:00.000Z","1978-03-01T00:00:00.000Z","1978-04-01T00:00:00.000Z","1978-05-01T00:00:00.000Z","1978-06-01T00:00:00.000Z","1978-07-01T00:00:00.000Z","1978-08-01T00:00:00.000Z","1978-09-01T00:00:00.000Z","1978-10-01T00:00:00.000Z","1978-11-01T00:00:00.000Z","1978-12-01T00:00:00.000Z","1979-01-01T00:00:00.000Z","1979-02-01T00:00:00.000Z","1979-03-01T00:00:00.000Z","1979-04-01T00:00:00.000Z","1979-05-01T00:00:00.000Z","1979-06-01T00:00:00.000Z","1979-07-01T00:00:00.000Z","1979-08-01T00:00:00.000Z","1979-09-01T00:00:00.000Z","1979-10-01T00:00:00.000Z","1979-11-01T00:00:00.000Z","1979-12-01T00:00:00.000Z"],[2134,1863,1877,1877,1492,1249,1280,1131,1209,1492,1621,1846,2103,2137,2153,1833,1403,1288,1186,1133,1053,1347,1545,2066,2020,2750,2283,1479,1189,1160,1113,970,999,1208,1467,2059,2240,1634,1722,1801,1246,1162,1087,1013,959,1179,1229,1655,2019,2284,1942,1423,1340,1187,1098,1004,970,1140,1110,1812,2263,1820,1846,1531,1215,1075,1056,975,940,1081,1294,1341],[901,689,827,677,522,406,441,393,387,582,578,666,830,752,785,664,467,438,421,412,343,440,531,771,767,1141,896,532,447,420,376,330,357,445,546,764,862,660,663,643,502,392,411,348,387,385,411,638,796,853,737,546,530,446,431,362,387,430,425,679,821,785,727,612,478,429,405,379,393,411,487,574]]},"evals":[],"jsHooks":[]}</script>
<div class="sourceCode" id="cb145"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb145-1" data-line-number="1"><span class="co">#It is possible to add a range selector under the chart</span></a>
<a class="sourceLine" id="cb145-2" data-line-number="2">dygraphs<span class="op">::</span><span class="kw">dygraph</span>(lungDeaths) <span class="op">%>%</span><span class="st"> </span>dygraphs<span class="op">::</span><span class="kw">dyRangeSelector</span>()</a></code></pre></div>
<div id="htmlwidget-9e813f3331e250c47e3a" style="width:672px;height:480px;" class="dygraphs html-widget"></div>
<script type="application/json" data-for="htmlwidget-9e813f3331e250c47e3a">{"x":{"attrs":{"labels":["month","mdeaths","fdeaths"],"legend":"auto","retainDateWindow":false,"axes":{"x":{"pixelsPerLabel":60}},"showRangeSelector":true,"rangeSelectorHeight":40,"rangeSelectorPlotFillColor":" #A7B1C4","rangeSelectorPlotStrokeColor":"#808FAB","interactionModel":"Dygraph.Interaction.defaultModel"},"scale":"monthly","annotations":[],"shadings":[],"events":[],"format":"date","data":[["1974-01-01T00:00:00.000Z","1974-02-01T00:00:00.000Z","1974-03-01T00:00:00.000Z","1974-04-01T00:00:00.000Z","1974-05-01T00:00:00.000Z","1974-06-01T00:00:00.000Z","1974-07-01T00:00:00.000Z","1974-08-01T00:00:00.000Z","1974-09-01T00:00:00.000Z","1974-10-01T00:00:00.000Z","1974-11-01T00:00:00.000Z","1974-12-01T00:00:00.000Z","1975-01-01T00:00:00.000Z","1975-02-01T00:00:00.000Z","1975-03-01T00:00:00.000Z","1975-04-01T00:00:00.000Z","1975-05-01T00:00:00.000Z","1975-06-01T00:00:00.000Z","1975-07-01T00:00:00.000Z","1975-08-01T00:00:00.000Z","1975-09-01T00:00:00.000Z","1975-10-01T00:00:00.000Z","1975-11-01T00:00:00.000Z","1975-12-01T00:00:00.000Z","1976-01-01T00:00:00.000Z","1976-02-01T00:00:00.000Z","1976-03-01T00:00:00.000Z","1976-04-01T00:00:00.000Z","1976-05-01T00:00:00.000Z","1976-06-01T00:00:00.000Z","1976-07-01T00:00:00.000Z","1976-08-01T00:00:00.000Z","1976-09-01T00:00:00.000Z","1976-10-01T00:00:00.000Z","1976-11-01T00:00:00.000Z","1976-12-01T00:00:00.000Z","1977-01-01T00:00:00.000Z","1977-02-01T00:00:00.000Z","1977-03-01T00:00:00.000Z","1977-04-01T00:00:00.000Z","1977-05-01T00:00:00.000Z","1977-06-01T00:00:00.000Z","1977-07-01T00:00:00.000Z","1977-08-01T00:00:00.000Z","1977-09-01T00:00:00.000Z","1977-10-01T00:00:00.000Z","1977-11-01T00:00:00.000Z","1977-12-01T00:00:00.000Z","1978-01-01T00:00:00.000Z","1978-02-01T00:00:00.000Z","1978-03-01T00:00:00.000Z","1978-04-01T00:00:00.000Z","1978-05-01T00:00:00.000Z","1978-06-01T00:00:00.000Z","1978-07-01T00:00:00.000Z","1978-08-01T00:00:00.000Z","1978-09-01T00:00:00.000Z","1978-10-01T00:00:00.000Z","1978-11-01T00:00:00.000Z","1978-12-01T00:00:00.000Z","1979-01-01T00:00:00.000Z","1979-02-01T00:00:00.000Z","1979-03-01T00:00:00.000Z","1979-04-01T00:00:00.000Z","1979-05-01T00:00:00.000Z","1979-06-01T00:00:00.000Z","1979-07-01T00:00:00.000Z","1979-08-01T00:00:00.000Z","1979-09-01T00:00:00.000Z","1979-10-01T00:00:00.000Z","1979-11-01T00:00:00.000Z","1979-12-01T00:00:00.000Z"],[2134,1863,1877,1877,1492,1249,1280,1131,1209,1492,1621,1846,2103,2137,2153,1833,1403,1288,1186,1133,1053,1347,1545,2066,2020,2750,2283,1479,1189,1160,1113,970,999,1208,1467,2059,2240,1634,1722,1801,1246,1162,1087,1013,959,1179,1229,1655,2019,2284,1942,1423,1340,1187,1098,1004,970,1140,1110,1812,2263,1820,1846,1531,1215,1075,1056,975,940,1081,1294,1341],[901,689,827,677,522,406,441,393,387,582,578,666,830,752,785,664,467,438,421,412,343,440,531,771,767,1141,896,532,447,420,376,330,357,445,546,764,862,660,663,643,502,392,411,348,387,385,411,638,796,853,737,546,530,446,431,362,387,430,425,679,821,785,727,612,478,429,405,379,393,411,487,574]]},"evals":["attrs.interactionModel"],"jsHooks":[]}</script>
<p>There are lots of options that can be changed such as axis labels, legends, and colours.</p>
<div class="sourceCode" id="cb146"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb146-1" data-line-number="1"><span class="co">#Adding a title </span></a>
<a class="sourceLine" id="cb146-2" data-line-number="2">dygraphs<span class="op">::</span><span class="kw">dygraph</span>(lungDeaths,<span class="dt">main=</span><span class="st">'This is the chart title'</span>)</a></code></pre></div>
<div id="htmlwidget-5cce7ad189657f2dc857" style="width:672px;height:480px;" class="dygraphs html-widget"></div>
<script type="application/json" data-for="htmlwidget-5cce7ad189657f2dc857">{"x":{"attrs":{"title":"This is the chart title","labels":["month","mdeaths","fdeaths"],"legend":"auto","retainDateWindow":false,"axes":{"x":{"pixelsPerLabel":60}}},"scale":"monthly","annotations":[],"shadings":[],"events":[],"format":"date","data":[["1974-01-01T00:00:00.000Z","1974-02-01T00:00:00.000Z","1974-03-01T00:00:00.000Z","1974-04-01T00:00:00.000Z","1974-05-01T00:00:00.000Z","1974-06-01T00:00:00.000Z","1974-07-01T00:00:00.000Z","1974-08-01T00:00:00.000Z","1974-09-01T00:00:00.000Z","1974-10-01T00:00:00.000Z","1974-11-01T00:00:00.000Z","1974-12-01T00:00:00.000Z","1975-01-01T00:00:00.000Z","1975-02-01T00:00:00.000Z","1975-03-01T00:00:00.000Z","1975-04-01T00:00:00.000Z","1975-05-01T00:00:00.000Z","1975-06-01T00:00:00.000Z","1975-07-01T00:00:00.000Z","1975-08-01T00:00:00.000Z","1975-09-01T00:00:00.000Z","1975-10-01T00:00:00.000Z","1975-11-01T00:00:00.000Z","1975-12-01T00:00:00.000Z","1976-01-01T00:00:00.000Z","1976-02-01T00:00:00.000Z","1976-03-01T00:00:00.000Z","1976-04-01T00:00:00.000Z","1976-05-01T00:00:00.000Z","1976-06-01T00:00:00.000Z","1976-07-01T00:00:00.000Z","1976-08-01T00:00:00.000Z","1976-09-01T00:00:00.000Z","1976-10-01T00:00:00.000Z","1976-11-01T00:00:00.000Z","1976-12-01T00:00:00.000Z","1977-01-01T00:00:00.000Z","1977-02-01T00:00:00.000Z","1977-03-01T00:00:00.000Z","1977-04-01T00:00:00.000Z","1977-05-01T00:00:00.000Z","1977-06-01T00:00:00.000Z","1977-07-01T00:00:00.000Z","1977-08-01T00:00:00.000Z","1977-09-01T00:00:00.000Z","1977-10-01T00:00:00.000Z","1977-11-01T00:00:00.000Z","1977-12-01T00:00:00.000Z","1978-01-01T00:00:00.000Z","1978-02-01T00:00:00.000Z","1978-03-01T00:00:00.000Z","1978-04-01T00:00:00.000Z","1978-05-01T00:00:00.000Z","1978-06-01T00:00:00.000Z","1978-07-01T00:00:00.000Z","1978-08-01T00:00:00.000Z","1978-09-01T00:00:00.000Z","1978-10-01T00:00:00.000Z","1978-11-01T00:00:00.000Z","1978-12-01T00:00:00.000Z","1979-01-01T00:00:00.000Z","1979-02-01T00:00:00.000Z","1979-03-01T00:00:00.000Z","1979-04-01T00:00:00.000Z","1979-05-01T00:00:00.000Z","1979-06-01T00:00:00.000Z","1979-07-01T00:00:00.000Z","1979-08-01T00:00:00.000Z","1979-09-01T00:00:00.000Z","1979-10-01T00:00:00.000Z","1979-11-01T00:00:00.000Z","1979-12-01T00:00:00.000Z"],[2134,1863,1877,1877,1492,1249,1280,1131,1209,1492,1621,1846,2103,2137,2153,1833,1403,1288,1186,1133,1053,1347,1545,2066,2020,2750,2283,1479,1189,1160,1113,970,999,1208,1467,2059,2240,1634,1722,1801,1246,1162,1087,1013,959,1179,1229,1655,2019,2284,1942,1423,1340,1187,1098,1004,970,1140,1110,1812,2263,1820,1846,1531,1215,1075,1056,975,940,1081,1294,1341],[901,689,827,677,522,406,441,393,387,582,578,666,830,752,785,664,467,438,421,412,343,440,531,771,767,1141,896,532,447,420,376,330,357,445,546,764,862,660,663,643,502,392,411,348,387,385,411,638,796,853,737,546,530,446,431,362,387,430,425,679,821,785,727,612,478,429,405,379,393,411,487,574]]},"evals":[],"jsHooks":[]}</script>
<div class="sourceCode" id="cb147"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb147-1" data-line-number="1"><span class="co">#Adding a legend</span></a>
<a class="sourceLine" id="cb147-2" data-line-number="2">dygraphs<span class="op">::</span><span class="kw">dygraph</span>(lungDeaths,<span class="dt">main=</span><span class="st">'This is the chart title'</span>) <span class="op">%>%</span><span class="st"> </span>dygraphs<span class="op">::</span><span class="kw">dyLegend</span>(<span class="dt">show=</span><span class="st">'always'</span>,<span class="dt">width =</span> <span class="dv">500</span>)</a></code></pre></div>
<div id="htmlwidget-85f005bbb9783f6e8c3a" style="width:672px;height:480px;" class="dygraphs html-widget"></div>
<script type="application/json" data-for="htmlwidget-85f005bbb9783f6e8c3a">{"x":{"attrs":{"title":"This is the chart title","labels":["month","mdeaths","fdeaths"],"retainDateWindow":false,"axes":{"x":{"pixelsPerLabel":60}},"legend":"always","labelsDivWidth":500,"labelsShowZeroValues":true,"labelsSeparateLines":false,"hideOverlayOnMouseOut":true},"scale":"monthly","annotations":[],"shadings":[],"events":[],"format":"date","data":[["1974-01-01T00:00:00.000Z","1974-02-01T00:00:00.000Z","1974-03-01T00:00:00.000Z","1974-04-01T00:00:00.000Z","1974-05-01T00:00:00.000Z","1974-06-01T00:00:00.000Z","1974-07-01T00:00:00.000Z","1974-08-01T00:00:00.000Z","1974-09-01T00:00:00.000Z","1974-10-01T00:00:00.000Z","1974-11-01T00:00:00.000Z","1974-12-01T00:00:00.000Z","1975-01-01T00:00:00.000Z","1975-02-01T00:00:00.000Z","1975-03-01T00:00:00.000Z","1975-04-01T00:00:00.000Z","1975-05-01T00:00:00.000Z","1975-06-01T00:00:00.000Z","1975-07-01T00:00:00.000Z","1975-08-01T00:00:00.000Z","1975-09-01T00:00:00.000Z","1975-10-01T00:00:00.000Z","1975-11-01T00:00:00.000Z","1975-12-01T00:00:00.000Z","1976-01-01T00:00:00.000Z","1976-02-01T00:00:00.000Z","1976-03-01T00:00:00.000Z","1976-04-01T00:00:00.000Z","1976-05-01T00:00:00.000Z","1976-06-01T00:00:00.000Z","1976-07-01T00:00:00.000Z","1976-08-01T00:00:00.000Z","1976-09-01T00:00:00.000Z","1976-10-01T00:00:00.000Z","1976-11-01T00:00:00.000Z","1976-12-01T00:00:00.000Z","1977-01-01T00:00:00.000Z","1977-02-01T00:00:00.000Z","1977-03-01T00:00:00.000Z","1977-04-01T00:00:00.000Z","1977-05-01T00:00:00.000Z","1977-06-01T00:00:00.000Z","1977-07-01T00:00:00.000Z","1977-08-01T00:00:00.000Z","1977-09-01T00:00:00.000Z","1977-10-01T00:00:00.000Z","1977-11-01T00:00:00.000Z","1977-12-01T00:00:00.000Z","1978-01-01T00:00:00.000Z","1978-02-01T00:00:00.000Z","1978-03-01T00:00:00.000Z","1978-04-01T00:00:00.000Z","1978-05-01T00:00:00.000Z","1978-06-01T00:00:00.000Z","1978-07-01T00:00:00.000Z","1978-08-01T00:00:00.000Z","1978-09-01T00:00:00.000Z","1978-10-01T00:00:00.000Z","1978-11-01T00:00:00.000Z","1978-12-01T00:00:00.000Z","1979-01-01T00:00:00.000Z","1979-02-01T00:00:00.000Z","1979-03-01T00:00:00.000Z","1979-04-01T00:00:00.000Z","1979-05-01T00:00:00.000Z","1979-06-01T00:00:00.000Z","1979-07-01T00:00:00.000Z","1979-08-01T00:00:00.000Z","1979-09-01T00:00:00.000Z","1979-10-01T00:00:00.000Z","1979-11-01T00:00:00.000Z","1979-12-01T00:00:00.000Z"],[2134,1863,1877,1877,1492,1249,1280,1131,1209,1492,1621,1846,2103,2137,2153,1833,1403,1288,1186,1133,1053,1347,1545,2066,2020,2750,2283,1479,1189,1160,1113,970,999,1208,1467,2059,2240,1634,1722,1801,1246,1162,1087,1013,959,1179,1229,1655,2019,2284,1942,1423,1340,1187,1098,1004,970,1140,1110,1812,2263,1820,1846,1531,1215,1075,1056,975,940,1081,1294,1341],[901,689,827,677,522,406,441,393,387,582,578,666,830,752,785,664,467,438,421,412,343,440,531,771,767,1141,896,532,447,420,376,330,357,445,546,764,862,660,663,643,502,392,411,348,387,385,411,638,796,853,737,546,530,446,431,362,387,430,425,679,821,785,727,612,478,429,405,379,393,411,487,574]]},"evals":[],"jsHooks":[]}</script>
<div class="sourceCode" id="cb148"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb148-1" data-line-number="1"><span class="co">#Adding othe options</span></a>
<a class="sourceLine" id="cb148-2" data-line-number="2">dygraphs<span class="op">::</span><span class="kw">dygraph</span>(lungDeaths,<span class="dt">main=</span><span class="st">'This is the chart title'</span>) <span class="op">%>%</span><span class="st"> </span>dygraphs<span class="op">::</span><span class="kw">dyOptions</span>(<span class="dt">includeZero =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<div id="htmlwidget-4d99b6a9e10c50ac1784" style="width:672px;height:480px;" class="dygraphs html-widget"></div>
<script type="application/json" data-for="htmlwidget-4d99b6a9e10c50ac1784">{"x":{"attrs":{"title":"This is the chart title","labels":["month","mdeaths","fdeaths"],"legend":"auto","retainDateWindow":false,"axes":{"x":{"pixelsPerLabel":60,"drawAxis":true},"y":{"drawAxis":true}},"stackedGraph":false,"fillGraph":false,"fillAlpha":0.15,"stepPlot":false,"drawPoints":false,"pointSize":1,"drawGapEdgePoints":false,"connectSeparatedPoints":false,"strokeWidth":1,"strokeBorderColor":"white","colorValue":0.5,"colorSaturation":1,"includeZero":true,"drawAxesAtZero":false,"logscale":false,"axisTickSize":3,"axisLineColor":"black","axisLineWidth":0.3,"axisLabelColor":"black","axisLabelFontSize":14,"axisLabelWidth":60,"drawGrid":true,"gridLineWidth":0.3,"rightGap":5,"digitsAfterDecimal":2,"labelsKMB":false,"labelsKMG2":false,"labelsUTC":false,"maxNumberWidth":6,"animatedZooms":false,"mobileDisableYTouch":true},"scale":"monthly","annotations":[],"shadings":[],"events":[],"format":"date","data":[["1974-01-01T00:00:00.000Z","1974-02-01T00:00:00.000Z","1974-03-01T00:00:00.000Z","1974-04-01T00:00:00.000Z","1974-05-01T00:00:00.000Z","1974-06-01T00:00:00.000Z","1974-07-01T00:00:00.000Z","1974-08-01T00:00:00.000Z","1974-09-01T00:00:00.000Z","1974-10-01T00:00:00.000Z","1974-11-01T00:00:00.000Z","1974-12-01T00:00:00.000Z","1975-01-01T00:00:00.000Z","1975-02-01T00:00:00.000Z","1975-03-01T00:00:00.000Z","1975-04-01T00:00:00.000Z","1975-05-01T00:00:00.000Z","1975-06-01T00:00:00.000Z","1975-07-01T00:00:00.000Z","1975-08-01T00:00:00.000Z","1975-09-01T00:00:00.000Z","1975-10-01T00:00:00.000Z","1975-11-01T00:00:00.000Z","1975-12-01T00:00:00.000Z","1976-01-01T00:00:00.000Z","1976-02-01T00:00:00.000Z","1976-03-01T00:00:00.000Z","1976-04-01T00:00:00.000Z","1976-05-01T00:00:00.000Z","1976-06-01T00:00:00.000Z","1976-07-01T00:00:00.000Z","1976-08-01T00:00:00.000Z","1976-09-01T00:00:00.000Z","1976-10-01T00:00:00.000Z","1976-11-01T00:00:00.000Z","1976-12-01T00:00:00.000Z","1977-01-01T00:00:00.000Z","1977-02-01T00:00:00.000Z","1977-03-01T00:00:00.000Z","1977-04-01T00:00:00.000Z","1977-05-01T00:00:00.000Z","1977-06-01T00:00:00.000Z","1977-07-01T00:00:00.000Z","1977-08-01T00:00:00.000Z","1977-09-01T00:00:00.000Z","1977-10-01T00:00:00.000Z","1977-11-01T00:00:00.000Z","1977-12-01T00:00:00.000Z","1978-01-01T00:00:00.000Z","1978-02-01T00:00:00.000Z","1978-03-01T00:00:00.000Z","1978-04-01T00:00:00.000Z","1978-05-01T00:00:00.000Z","1978-06-01T00:00:00.000Z","1978-07-01T00:00:00.000Z","1978-08-01T00:00:00.000Z","1978-09-01T00:00:00.000Z","1978-10-01T00:00:00.000Z","1978-11-01T00:00:00.000Z","1978-12-01T00:00:00.000Z","1979-01-01T00:00:00.000Z","1979-02-01T00:00:00.000Z","1979-03-01T00:00:00.000Z","1979-04-01T00:00:00.000Z","1979-05-01T00:00:00.000Z","1979-06-01T00:00:00.000Z","1979-07-01T00:00:00.000Z","1979-08-01T00:00:00.000Z","1979-09-01T00:00:00.000Z","1979-10-01T00:00:00.000Z","1979-11-01T00:00:00.000Z","1979-12-01T00:00:00.000Z"],[2134,1863,1877,1877,1492,1249,1280,1131,1209,1492,1621,1846,2103,2137,2153,1833,1403,1288,1186,1133,1053,1347,1545,2066,2020,2750,2283,1479,1189,1160,1113,970,999,1208,1467,2059,2240,1634,1722,1801,1246,1162,1087,1013,959,1179,1229,1655,2019,2284,1942,1423,1340,1187,1098,1004,970,1140,1110,1812,2263,1820,1846,1531,1215,1075,1056,975,940,1081,1294,1341],[901,689,827,677,522,406,441,393,387,582,578,666,830,752,785,664,467,438,421,412,343,440,531,771,767,1141,896,532,447,420,376,330,357,445,546,764,862,660,663,643,502,392,411,348,387,385,411,638,796,853,737,546,530,446,431,362,387,430,425,679,821,785,727,612,478,429,405,379,393,411,487,574]],"fixedtz":false,"tzone":""},"evals":[],"jsHooks":[]}</script>
</div>
</div>
</section>
</div>
</div>
</div>
<a href="tables.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="maps.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"google": false,
"linkedin": false,
"weibo": false,
"instapper": false,
"vk": false,
"all": ["facebook", "google", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"download": null,
"toc": {
"collapse": "subsection"
}
});
});
</script>
</body>
</html>