-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
7043 lines (6799 loc) · 125 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>R Graphics</title>
<meta charset="utf-8">
<meta name="description" content="R Graphics">
<meta name="author" content="Bo Werth">
<meta name="generator" content="slidify" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link rel="stylesheet" href="libraries/frameworks/io2012/css/default.css" media="all" >
<link rel="stylesheet" href="libraries/frameworks/io2012/css/phone.css"
media="only screen and (max-device-width: 480px)" >
<link rel="stylesheet" href="libraries/frameworks/io2012/css/slidify.css" >
<link rel="stylesheet" href="libraries/highlighters/highlight.js/css/tomorrow.css" />
<base target="_blank"> <!-- This amazingness opens all links in a new tab. --> <link rel=stylesheet href="libraries/widgets/nvd3/css/nv.d3.css"></link>
<link rel=stylesheet href="libraries/widgets/nvd3/css/rNVD3.css"></link>
<link rel=stylesheet href="./assets/css/ribbons.css"></link>
<!-- Grab CDN jQuery, fall back to local if offline -->
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script>
<script>window.jQuery || document.write('<script src="libraries/widgets/quiz/js/jquery.js"><\/script>')</script>
<script data-main="libraries/frameworks/io2012/js/slides"
src="libraries/frameworks/io2012/js/require-1.0.8.min.js">
</script>
<script src="libraries/widgets/highcharts/js/jquery-1.9.1.min.js"></script>
<script src="libraries/widgets/highcharts/js/highcharts.js"></script>
<script src="libraries/widgets/highcharts/js/highcharts-more.js"></script>
<script src="libraries/widgets/highcharts/js/exporting.js"></script>
<script src="libraries/widgets/nvd3/js/jquery-1.8.2.min.js"></script>
<script src="libraries/widgets/nvd3/js/d3.v3.min.js"></script>
<script src="libraries/widgets/nvd3/js/nv.d3.min-new.js"></script>
<script src="libraries/widgets/nvd3/js/fisheye.js"></script>
</head>
<body style="opacity: 0">
<slides class="layout-widescreen">
<!-- LOGO SLIDE -->
<slide class="title-slide segue nobackground">
<hgroup class="auto-fadein">
<h1>R Graphics</h1>
<h2>Generating graphics for statistical analysis using R</h2>
<p>Bo Werth<br/>Statistician STI/EAS</p>
</hgroup>
<article></article>
</slide>
<!-- SLIDES -->
<slide class="" id="slide-1" style="background:;">
<hgroup>
<h2>Graphics in statistical software</h2>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p>programming</p>
<ul>
<li><p>quality: reproducibility, calculations</p></li>
<li><p>efficiency gains: scaling</p></li>
<li><p>output flexibility: PDF, Word, HTML</p></li>
</ul>
</div>
<div style='float:right;width:48%;'>
<p>interactive creation (e.g. Excel, Tableau)</p>
<ul>
<li><p>development time</p></li>
<li><p>changing requirements</p></li>
<li><p>maintenance and transparency</p></li>
</ul>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-2" style="background:;">
<hgroup>
<h2><code>R</code> Graphics Systems</h2>
</hgroup>
<article data-timings="">
<p><a href="https://www.google.com/trends/explore?date=all&q=python%20programming,r%20programming,ggplot">google trends: python, r, ggplot</a></p>
<div style='float:left;width:48%;' class='centered'>
<p>traditional graphics</p>
<ul>
<li>graphics facilities of the S language</li>
<li>fast, intuitive</li>
<li>create plot with high-level function</li>
<li>add elements with low-level functions</li>
</ul>
</div>
<div style='float:right;width:48%;'>
<p>grid graphics system</p>
<ul>
<li>produce complete plots</li>
<li>ideal proportions</li>
<li>facetting or multi-panel conditioning</li>
<li><code>trellis</code>, <code>lattice</code>, <code>ggplot</code></li>
</ul>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h2>The organization of <code>R</code> graphics</h2>
</hgroup>
<article data-timings="">
<p style="text-align:center"><img src="assets/img/R_graphics_system.svg" alt="R graphics system" height="550px"/></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h4>Publication quality graphics with <code>ggplot</code></h4>
</hgroup>
<article data-timings="">
<ul>
<li>implementation of Leland Wilkinson's "grammar of graphics" (2005)</li>
<li>independent components that can be composed in different ways</li>
<li>not limited to a set of pre-specified graphics</li>
<li>create new graphics that are precisely tailored</li>
</ul>
<h4>Interactive Graphics using JavaScript</h4>
<ul>
<li><code>ggvis</code>: <code>ggplot</code> for dynamic charts based on <code>vega.js</code></li>
<li><code>rCharts</code>: interface to high-level js libraries building e.g. on <code>d3.js</code>
<ul>
<li><code>highcharts</code>, <code>polyplot</code>, <code>nvd3</code>, <code>ricksaw</code> for statistical charts</li>
<li><code>crosslet</code>, <code>datamaps</code>, <code>leaflet</code> etc. for map visualisations</li>
</ul></li>
</ul>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics</h3>
</hgroup>
<article data-timings="">
<ul>
<li>pen on paper model:
<ul>
<li>can only draw on top of the plot</li>
<li>cannot modify or delete existing content</li>
</ul></li>
<li>no (user accessible) representation of the graphics</li>
<li>includes both tools for drawing primitives and entire plots</li>
<li>generally fast, but have limited scope</li>
</ul>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: <code>example(plot)</code></h3>
</hgroup>
<article data-timings="">
<p><img src="assets/fig/plotexample-1.png" alt="plot of chunk plotexample"></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-7" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: plot regions</h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p>Single plot regions</p>
<p><img src="assets/img/single_plot_regions.svg" alt="Single Plot Regions"></p>
</div>
<div style='float:right;width:48%;'>
<p>Multiple plot regions</p>
<p><img src="assets/img/multi_plot_regions.svg" alt="Multi Plot Regions"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: plot regions</h3>
</hgroup>
<article data-timings="">
<pre><code class="r">op <- par(mfrow = c(2, 2),
mar = c(3, 0, 0, 0))
plot(...); plot(...); plot(...); plot(...)
## At end of plotting, reset to previous settings:
par(op)
</code></pre>
<ul>
<li>the documentation can be looked up with <code>?par()</code></li>
<li>margins are measured in multiples of lines of text</li>
<li>modifying traditional graphics state settings via <code>par()</code> has a persistent effect</li>
</ul>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-9" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: plot regions</h3>
</hgroup>
<article data-timings="">
<pre><code class="r">op <- par(mfrow = c(2, 2),
mar = c(3, 0, 0, 0))
plot(...); plot(...); plot(...); plot(...)
## At end of plotting, reset to previous settings:
par(op)
</code></pre>
<ul>
<li><code>mfrow</code> and <code>mfcol</code> control the number of figure regions on a page</li>
</ul>
<div style='float:left;width:48%;' class='centered'>
<p><img src="assets/img/par_mfrow.svg" alt="par mfrow"></p>
</div>
<div style='float:right;width:48%;'>
<p><img src="assets/img/par_mfcol.svg" alt="par mfcol"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-10" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: controlling plot regions</h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p><img src="assets/img/graphic_state_setting_controlling_plot_regions.svg" alt="Graphics state settings controlling plot regions"></p>
</div>
<div style='float:right;width:48%;'>
<ul>
<li>diagram for controlling widths and horizontal locations</li>
<li>plot region = figure region - figure margins</li>
<li><code>plt</code>: location of the plot region (l, r, b, t)</li>
<li><code>pin</code>: size of the plot region, (width, height)</li>
<li><code>pty</code>: <code>m</code>: use all available space, <code>s</code>: preserve square format</li>
</ul>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: colors and colours</h3>
</hgroup>
<article data-timings="">
<pre><code class="r">colours()[1:4] # 657 color names
</code></pre>
<pre><code>## [1] "white" "aliceblue" "antiquewhite" "antiquewhite1"
</code></pre>
<pre><code class="r">col2rgb("transparent") # see the RGB values for a particular color name
</code></pre>
<pre><code>## [,1]
## red 255
## green 255
## blue 255
</code></pre>
<pre><code class="r">rgb(1, 0, 0) # Red-Green-Blue triplet of intensities, format #RRGGBB, FF = 255
</code></pre>
<pre><code>## [1] "#FF0000"
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: <code>pch</code> point symbols</h3>
</hgroup>
<article data-timings="">
<p><img src="assets/img/pch_symbols.png" alt="pch symbols"></p>
<p>A particular data symbol is selected by specifying an integer between 0 and 25 or a single character for the <code>pch</code> graphical setting. In the diagram, the relevant integer or character <code>pch</code> value is shown in grey to the left of the relevant symbol.</p>
<p>Source: <a href="http://vis.supstat.com/2013/04/plotting-symbols-and-color-palettes/">http://vis.supstat.com/2013/04/plotting-symbols-and-color-palettes/</a></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-13" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics</h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p>example(barplot)</p>
<p><img src="assets/fig/barplot-1.png" alt="plot of chunk barplot"></p>
</div>
<div style='float:right;width:48%;'>
<p>example(boxplot)</p>
<p><img src="assets/fig/boxplotex-1.png" alt="plot of chunk boxplotex"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-14" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics</h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p>example(pairs)</p>
<p><img src="assets/fig/pairplot-1.png" alt="plot of chunk pairplot"></p>
</div>
<div style='float:right;width:48%;'>
<p>example(persp)</p>
<p><img src="assets/fig/perspplot-1.png" alt="plot of chunk perspplot"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-15" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: <code>example(stars)</code></h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p><img src="assets/fig/starsegment-1.png" alt="plot of chunk starsegment"></p>
</div>
<div style='float:right;width:48%;'>
<p><img src="assets/fig/starradar-1.png" alt="plot of chunk starradar"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-16" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: <code>example(mosaicplot)</code></h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p><img src="assets/fig/mosaic1-1.png" alt="plot of chunk mosaic1"></p>
</div>
<div style='float:right;width:48%;'>
<p><img src="assets/fig/mosaic2-1.png" alt="plot of chunk mosaic2"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-17" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: conditioning plot, <code>example(coplot)</code></h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p><img src="assets/fig/coplot1-1.png" alt="plot of chunk coplot1"></p>
</div>
<div style='float:right;width:48%;'>
<p><img src="assets/fig/coplot2-1.png" alt="plot of chunk coplot2"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: lm example</h3>
</hgroup>
<article data-timings="">
<p><img src="assets/fig/lmplot-1.png" alt="plot of chunk lmplot"></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics: Agglomerative Nesting (Hierarchical Clustering)</h3>
</hgroup>
<article data-timings="">
<p><img src="assets/fig/agnesplot-1.png" alt="plot of chunk agnesplot"></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>traditional S-PLUS graphics</h3>
</hgroup>
<article data-timings="">
<pre><code class="r">plot(hclust(d = dist(USArrests), method = "average"), main=title)
</code></pre>
<p><img src="assets/fig/unnamed-chunk-2-1.png" alt="plot of chunk unnamed-chunk-2"></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-21" style="background:;">
<hgroup>
<h3>lattice / grid graphics: pre and post drawing</h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p><img src="assets/fig/oztemp-1.png" alt="plot of chunk oztemp"></p>
</div>
<div style='float:right;width:48%;'>
<ul>
<li>draw map of Australia</li>
<li>draw average monthly temperatures for six cities</li>
</ul>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-22" style="background:;">
<hgroup>
<h3>lattice / grid graphics: embedding plots in grid viewports</h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p><img src="assets/fig/viewport-1.png" alt="plot of chunk viewport"></p>
</div>
<div style='float:right;width:48%;'>
<ul>
<li>create dendrogram object and cut it into four subtrees</li>
<li>define lattice panel function to draw the dendrograms</li>
<li>make base plot region correspond to the created viewport</li>
<li>use traditional <code>plot()</code> function to draw the dendrogram</li>
</ul>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>Layered Grammar of Graphics</h3>
</hgroup>
<article data-timings="">
<p>A statistical graphic is a mapping from data to</p>
<ul>
<li>geometric objects (points, lines, bars)</li>
<li>with aesthetic attributes (colour, shape, size)</li>
<li>in a coordinate system (cartesian, polar, map projection)</li>
</ul>
<p>and optionally entails</p>
<ul>
<li>statistical transformations of the data (binning, counting)</li>
<li>faceting to generate the same graphic for different subsets of the dataset</li>
</ul>
<p>ggplot2 attempts to produce any kind of statistical graphic using</p>
<ul>
<li>a compact syntax and independent components to facilitate extensions</li>
<li>the <code>grid</code> package to exercise low-level control over the appearance of the plot</li>
</ul>
<p>Wickham, H. (2009). ggplot2. doi:10.1007/978-0-387-98141-3</p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-24" style="background:;">
<hgroup>
<h3>Comparison <code>plot()</code> and <code>qplot()</code></h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<pre><code class="r">plot(x, y)
</code></pre>
<p><img src="assets/fig/plot1-1.png" alt="plot of chunk plot1"></p>
</div>
<div style='float:right;width:48%;'>
<pre><code class="r">qplot(x, y)
</code></pre>
<p><img src="assets/fig/qplot1-1.png" alt="plot of chunk qplot1"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-25" style="background:;">
<hgroup>
<h3>Comparison <code>plot()</code> and <code>qplot()</code></h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<pre><code class="r">plot(x, y, type = "l")
</code></pre>
<p><img src="assets/fig/plot2-1.png" alt="plot of chunk plot2"></p>
</div>
<div style='float:right;width:48%;'>
<pre><code class="r">qplot(x, y, geom = "line")
</code></pre>
<p><img src="assets/fig/qplot2-1.png" alt="plot of chunk qplot2"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-26" style="background:;">
<hgroup>
<h3>Comparison <code>plot()</code> and <code>qplot()</code></h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<pre><code class="r">plot(x, y, type = "s")
</code></pre>
<p><img src="assets/fig/plot3-1.png" alt="plot of chunk plot3"></p>
</div>
<div style='float:right;width:48%;'>
<pre><code class="r">qplot(x, y, geom = "step")
</code></pre>
<p><img src="assets/fig/qplot3-1.png" alt="plot of chunk qplot3"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-27" style="background:;">
<hgroup>
<h3>Comparison <code>plot()</code> and <code>qplot()</code></h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<pre><code class="r">plot(x, y, type = "b")
</code></pre>
<p><img src="assets/fig/plot4-1.png" alt="plot of chunk plot4"></p>
</div>
<div style='float:right;width:48%;'>
<pre><code class="r">qplot(x, y, geom = c("point", "line"))
</code></pre>
<p><img src="assets/fig/qplot4-1.png" alt="plot of chunk qplot4"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3><code>mtcars</code> dataset</h3>
</hgroup>
<article data-timings="">
<p>Data from the 1974 <em>Motor Trend</em> US magazine for 32 automobiles (1973-74 models). The variables are the following:</p>
<ul>
<li><code>mpg</code> Miles/(US) gallon</li>
<li><code>cyl</code> Number of cylinders</li>
<li><code>disp</code> Displacement (cu.in.)</li>
<li><code>hp</code> Gross horsepower</li>
<li><code>drat</code> Rear axle ratio</li>
<li><code>wt</code> Weight (lb/1000)</li>
<li><code>qsec</code> 1/4 mile time</li>
<li><code>vs</code> V/S</li>
<li><code>am</code> Transmission (0 = automatic, 1 = manual)</li>
<li><code>gear</code> Number of forward gears</li>
<li><code>carb</code> Number of carburetors</li>
</ul>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-29" style="background:;">
<hgroup>
<h3>Comparison <code>plot()</code> and <code>qplot()</code></h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<pre><code class="r">boxplot(wt~cyl,
data=mtcars, col="lightgray")
</code></pre>
<p><img src="assets/fig/boxplotcomp-1.png" alt="plot of chunk boxplotcomp"></p>
</div>
<div style='float:right;width:48%;'>
<pre><code class="r">qplot(factor(cyl), wt,
data=mtcars, geom=c("boxplot", "jitter"))
</code></pre>
<p><img src="assets/fig/boxqplotcomp-1.png" alt="plot of chunk boxqplotcomp"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-30" style="background:;">
<hgroup>
<h3>Comparison <code>plot()</code> and <code>qplot()</code></h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<pre><code class="r">hist(mtcars$wt)
</code></pre>
<p><img src="assets/fig/histplotcomp-1.png" alt="plot of chunk histplotcomp"></p>
</div>
<div style='float:right;width:48%;'>
<pre><code class="r">qplot(mtcars$wt, geom = "histogram",
binwidth = 0.5, color = factor(0))
</code></pre>
<p><img src="assets/fig/histqplotcomp-1.png" alt="plot of chunk histqplotcomp"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-31" style="background:;">
<hgroup>
<h3>Comparison <code>plot()</code> and <code>qplot()</code></h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<pre><code class="r">cdplot(mtcars$wt, factor(mtcars$cyl))
</code></pre>
<p><img src="assets/fig/cdplotcomp-1.png" alt="plot of chunk cdplotcomp"></p>
</div>
<div style='float:right;width:48%;'>
<pre><code class="r">qplot(mtcars$wt, fill=factor(mtcars$cyl),
geom="density")
</code></pre>
<p><img src="assets/fig/cdqplotcomp-1.png" alt="plot of chunk cdqplotcomp"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3><code>diamonds</code> dataset</h3>
</hgroup>
<article data-timings="">
<p>A dataset containing the prices and other attributes of almost 54,000 diamonds. The variables are as follows:</p>
<ul>
<li><code>price</code> price in US dollars ($326-$18,823)</li>
<li><code>carat</code> weight of the diamond (0.2-5.01)</li>
<li><code>cut</code> quality of the cut (Fair, Good, Very Good, Premium, Ideal)</li>
<li><code>colour</code> diamond colour, from J (worst) to D (best)</li>
<li><code>clarity</code> a measurement of how clear the diamond is (I1 (worst), SI1, SI2, VS1, VS2, VVS1, VVS2, IF (best))</li>
<li><code>x</code> length in mm (0-10.74)</li>
<li><code>y</code> width in mm (0-58.9)</li>
<li><code>z</code> depth in mm (0-31.8)</li>
<li><code>depth</code> total depth percentage = z / mean(x, y) = 2 * z / (x + y) (43-79)</li>
<li><code>table</code> width of top of diamond relative to widest point (43-95)</li>
</ul>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-33" style="background:;">
<hgroup>
<h3>ggplot2 <code>qplot()</code>: single line of code</h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<pre><code class="r">qplot(x=carat, y=price, colour=clarity,
data=diamonds, geom=("point"))
</code></pre>
<p><img src="assets/fig/qplotex1-1.png" alt="plot of chunk qplotex1"></p>
</div>
<div style='float:right;width:48%;'>
<pre><code class="r">qplot(carat, price,
data = diamonds, geom = c("point", "smooth"))
</code></pre>
<p><img src="assets/fig/qplotex2-1.png" alt="plot of chunk qplotex2"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>ggplot2 <code>ggplot()</code>: add layers for more control using "<code>+</code>"</h3>
</hgroup>
<article data-timings="">
<pre><code class="r">ggplot(data=diamonds) +
geom_point(aes(x=price, y=carat, colour=color)) +
facet_grid(. ~ clarity)
</code></pre>
<p><img src="assets/fig/ggplotex-1.png" alt="plot of chunk ggplotex"></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>ggplot2 <code>ggplot()</code>: add layers for more control using "<code>+</code>"</h3>
</hgroup>
<article data-timings="">
<pre><code class="r">ggplot(data = df,aes(x = x,y = y)) + # source: https://plot.ly/ggplot2/geom_errorbar/
geom_errorbar(aes(ymin = ymin,ymax = ymax), colour = 'steelblue', width = 0.2) +
geom_errorbarh(aes(xmin = xmin,xmax = xmax), colour = 'steelblue', height = 0.4) +
geom_point(color = "black", size = 3)
</code></pre>
<p><img src="assets/fig/ggplotlayer-1.png" alt="plot of chunk ggplotlayer"></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-36" style="background:;">
<hgroup>
<h3>ggplot Themes</h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p><code>theme_stata()</code></p>
<p><img src="assets/fig/ggthemesstata-1.png" alt="plot of chunk ggthemesstata"></p>
</div>
<div style='float:right;width:48%;'>
<p><code>theme_economist()</code></p>
<p><img src="assets/fig/ggthemeseconomist-1.png" alt="plot of chunk ggthemeseconomist"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-37" style="background:;">
<hgroup>
<h3>ggplot Themes</h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p><code>theme_fivethirtyeight()</code></p>
<p><img src="assets/fig/ggthemesfivethirtyeight-1.png" alt="plot of chunk ggthemesfivethirtyeight"></p>
</div>
<div style='float:right;width:48%;'>
<p>Tableau <code>theme_igray()</code></p>
<p><img src="assets/fig/ggthemesigray-1.png" alt="plot of chunk ggthemesigray"></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>ggplot Themes: <code>ggthemr</code></h3>
</hgroup>
<article data-timings="">
<pre><code class="r">pal.crN <- c('#95B3D7','#F79646','#8064A2','#4BACC6','#9BBB59','#C0504D')
ugly <- define_palette(
swatch = pal.crN, gradient = c(lower = pal.crN[1L], upper = pal.crN[2L]))
ggthemr(ugly)
ggplot(dsamp, aes(x=price, fill=cut)) + geom_bar(binwidth = 500)
</code></pre>
<p><img src="assets/fig/ggthemr-1.png" alt="plot of chunk ggthemr"></p>
<pre><code class="r">ggthemr_reset()
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-39" style="background:;">
<hgroup>
<h3>gridSVG: gapminder</h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p style="text-align:center"><img src="assets/img/gapminderOnePanel.svg" alt="gapminder animation" height="550px"/></p>
</div>
<div style='float:right;width:48%;'>
<ul>
<li><code>gridSVG</code> animates a ggplot object before the output is flattened for export
to a graphics device</li>
<li>the animation is obtained from mapping to the time dimension (annual since
1950)</li>
<li><code>size</code> = population</li>
<li><code>color</code> = continent
<ul>
<li><code>blue</code>: Europe</li>
<li><code>red</code>: Asia</li>
<li><code>green</code>: Africa</li>
<li><code>yellow</code>: America</li>
</ul></li>
</ul>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-40" style="background:;">
<hgroup>
<h3>gridSVG: R&D Expendidures</h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<p style="text-align:center"><img src="assets/img/RDplotOnePanel.svg" alt="rnd animation" height="550px"/></p>
</div>
<div style='float:right;width:48%;'>
<ul>
<li></li>
</ul>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-41" style="background:;">
<hgroup>
<h3>ggvis: <code>/demo/dynamic.r</code></h3>
</hgroup>
<article data-timings="">
<div style='float:left;width:48%;' class='centered'>
<h3>dynamic stacked bars</h3>
<p style="text-align:center"><img src="assets/img/ggvis_demo_dynamic_stacked_bars.svg" alt="ggvis stacked bars" height="450px"/></p>
</div>
<div style='float:right;width:48%;'>
<h3>moving data points</h3>
<p style="text-align:center"><img src="assets/img/ggvis_demo_moving_points.svg" alt="ggvis moving points" height="450px"/></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="class" id="id" style="background:;">
<hgroup>
<h3>rCharts: nvd3 Sparklines</h3>
</hgroup>
<article data-timings="">
<pre><code class="r">p2 <- nPlot(uempmed ~ date, data = economics, type = 'sparklinePlus')
p2$chart(xTickFormat="#!function(d) {return d3.time.format('%b %Y')(new Date( d * 86400000 ));}!#")
p2$print('chart2')
</code></pre>
<div id = 'chart2' class = 'rChart nvd3'></div>
<script type='text/javascript'>
$(document).ready(function(){
drawchart2()
});
function drawchart2(){
var opts = {
"dom": "chart2",
"width": 800,
"height": 400,
"x": "date",
"y": "uempmed",
"type": "sparklinePlus",
"id": "chart2"
},
data = [
{
"date": -915,
"pce": 507.4,
"pop": 198712,
"psavert": 12.5,
"uempmed": 4.5,
"unemploy": 2944
},
{
"date": -884,
"pce": 510.5,
"pop": 198911,
"psavert": 12.5,
"uempmed": 4.7,
"unemploy": 2945