Repository navigation
Expand file tree
/
Copy pathggplot_201805.html
More file actions
929 lines (801 loc) · 30 KB
/
Copy pathggplot_201805.html
File metadata and controls
929 lines (801 loc) · 30 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
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
<!DOCTYPE html>
<html>
<head>
<title>ggplot2 blitz</title>
<meta charset="utf-8">
<meta name="author" content="Rick Pack" />
<link href="ggplot_201805_files/remark-css-0.0.1/default.css" rel="stylesheet" />
<link href="ggplot_201805_files/remark-css-0.0.1/default-fonts.css" rel="stylesheet" />
</head>
<body>
<textarea id="source">
class: center, middle, inverse, title-slide
# ggplot2 blitz
## A xaringan presentation
### Rick Pack
### 2018/05/21
---
# We are going to turn this table of countries' oil production (look left)

--
# https://en.wikipedia.org/wiki/List_of_countries_by_oil_production
---
# Into this ggplot2 (R Package) graph of countries' oil production

# http://www.sharpsightlabs.com/blog/map-oil-production-country-r/
---
# This HTML5 presentation was created in RStudio with the Xaringan package by Yihui Xie

--

# get started with Xaringan using Yihui Xie's presentation at https://slides.yihui.name/xaringan/
---
#Yihui Xie - courtesy of usethis.com

# "This code is available on my Github page: https://github.com/RickPack/TriPASS_DataSci_ggplot2_201805
---
# sharpsightlobs.com R Code (map oil production by country) [slight mod] - page 1 / X
```r
#=============
# LOAD PACKAGES, INSTALL IF NOT INSTALLED
#=============
list.of.packages <- c("tidyverse", "sf", "rvest", "stringr", "scales", "viridis", "extrafont", "maps","formatR")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages, repos = "http://cran.us.r-project.org")
```
---
```r
#=============
# LOAD PACKAGES
#=============
# user Nate in https://stackoverflow.com/questions/14733732/cant-change-fonts-in-ggplot-geom-text #<<
# "The key for my system was to call extrafont::loadfonts(device="win") prior to library(ggplot2)."
# needed for Windows to eliminate "font family not found in Windows database error"
# in Linux use X11Fonts()
extrafont::font_import("C:/Windows/Fonts/", pattern = "GIL_____")
```
```
## Exiting.
```
```r
extrafont::loadfonts(device="win")
library(tidyverse)
```
```
## -- Attaching packages --------------------------------------------------------------- tidyverse 1.2.1 --
```
```
## v ggplot2 2.2.1 v purrr 0.2.4
## v tibble 1.4.2 v dplyr 0.7.5
## v tidyr 0.8.1 v stringr 1.3.1
## v readr 1.1.1 v forcats 0.3.0
```
```
## -- Conflicts ------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
```
```r
library(sf)
```
```
## Linking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3
```
```r
library(rvest)
```
```
## Loading required package: xml2
```
```
##
## Attaching package: 'rvest'
```
```
## The following object is masked from 'package:purrr':
##
## pluck
```
```
## The following object is masked from 'package:readr':
##
## guess_encoding
```
```r
library(stringr)
# I love the percent function in the scales package
library(scales) #<<
```
```
##
## Attaching package: 'scales'
```
```
## The following object is masked from 'package:purrr':
##
## discard
```
```
## The following object is masked from 'package:readr':
##
## col_factor
```
```r
# for color palettes: #<<
library(viridis) #<<
```
```
## Loading required package: viridisLite
```
```
##
## Attaching package: 'viridis'
```
```
## The following object is masked from 'package:scales':
##
## viridis_pal
```
```r
scales::percent(3/4)
```
[1] "75%"
---
# An easily produced ggplot2 scatterplot
```r
# mpg is a data frame loaded when one loads the ggplot2 package (loaded in
# tidyverse)
ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() + ggtitle(label = "Fuel economy data from 1999 and 2008 for 38 popular models of car",
subtitle = "from the mpg data frame installed with ggplot2")
```
<img src="ggplot_201805_files/figure-html/unnamed-chunk-4-1.png" width="672" />

# from http://ggplot2.tidyverse.org/
---
# sharpsightlobs.com R Code (map oil production by country) [slight mod] - page 2 / X
```r
# ============ SCRAPE DATA ============
df.oil <- read_html("https://en.wikipedia.org/wiki/List_of_countries_by_oil_production") %>%
html_nodes("table") %>% .[[1]] %>% html_table()
```

---
# sharpsightlobs.com R Code (map oil production by country) [slight mod] - page 3 / X
```r
# ==================== CHANGE COLUMN NAMES ====================
print(names(df.oil))
```
```
## [1] "" "Country"
## [3] "Oil Production(bbl/day, 2016)[1]"
```
```r
colnames(df.oil) <- c("rank", "country", "oil_bbl_per_day")
# ============================= WRANGLE VARIABLES INTO SHAPE
# =============================
#----------------------------------
# COERCE 'rank' VARIABLE TO INTEGER
#----------------------------------
# What is the class of each variable?
lapply(df.oil, class)
```
```
## $rank
## [1] "character"
##
## $country
## [1] "character"
##
## $oil_bbl_per_day
## [1] "character"
```
```r
df.oil <- df.oil %>% mutate(rank = as.integer(rank))
```
```
## Warning in evalq(as.integer(rank), <environment>): NAs introduced by
## coercion
```
```r
# glimpse is installed with the tidyverse See class and sampling of values
# Commas in oil_bbl_per_day are a problem, country sometimes shows OPEC
df.oil %>% glimpse()
```
```
## Observations: 99
## Variables: 3
## $ rank <int> NA, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,...
## $ country <chr> "World Production", "Russia", "Saudi Arabia (O...
## $ oil_bbl_per_day <chr> "80,622,000", "10,551,497", "10,460,710", "8,8...
```
```r
#---------------------------------------------------
# WRANGLE FROM CHARACTER TO NUMERIC: oil_bbl_per_day
#---------------------------------------------------
df.oil <- df.oil %>% mutate(oil_bbl_per_day = oil_bbl_per_day %>% str_replace_all(',','') %>% as.integer())
#===========================
#CREATE VARIABLE: 'opec_ind'
#===========================
df.oil <- df.oil %>% mutate(opec_ind = if_else(str_detect(country, 'OPEC'), 1, 0))
df.oil <- df.oil %>% mutate(country = country %>%
str_replace(' \\(OPEC\\)', '') %>% str_replace('\\s{2,}',' '))
# inspect
df.oil %>% glimpse()
```
```
## Observations: 99
## Variables: 4
## $ rank <int> NA, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,...
## $ country <chr> "World Production", "Russia", "Saudi Arabia", ...
## $ oil_bbl_per_day <int> 80622000, 10551497, 10460710, 8875817, 4451516...
## $ opec_ind <dbl> 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0...
```
```r
#------------------------------------------
# EXAMINE OPEC COUNTRIES
# - here, we'll just visually inspect
# to make sure that the names are correct
#------------------------------------------
df.oil %>%
filter(opec_ind == 1) %>%
select(country)
```
```
## country
## 1 Saudi Arabia
## 2 Iraq
## 3 Iran
## 4 United Arab Emirates
## 5 Kuwait
## 6 Venezuela
## 7 Nigeria
## 8 Angola
## 9 Qatar
## 10 Algeria
## 11 Libya
## 12 Ecuador
## 13 Equatorial Guinea
## 14 Gabon
```
```r
#==================
# REORDER VARIABLES
#==================
df.oil <- df.oil %>% select(rank, country, opec_ind, oil_bbl_per_day)
#========
# GET MAP
#========
# map_data turns data "from the maps package in to a data frame suitable for plotting with ggplot2".
map.world <- map_data('world')
```
```
##
## Attaching package: 'maps'
```
```
## The following object is masked from 'package:purrr':
##
## map
```
```r
#==========================
# CHECK FOR JOIN MISMATCHES
#==========================
mismatch_frm <- anti_join(df.oil, map.world, by = c('country' = 'region'))
print(head(mismatch_frm))
```
```
## rank country opec_ind oil_bbl_per_day
## 1 NA World Production 0 80622000
## 2 3 United States 0 8875817
## 3 21 United Kingdom 0 939760
## 4 31 Congo, Republic of the 0 308363
## 5 35 Sudan and South Sudan 0 255000
## 6 47 Trinidad and Tobago 0 60090
```
```r
#=====================
# RECODE COUNTRY NAMES
#=====================
map.world %>%
group_by(region) %>%
summarise() %>%
print(n = Inf)
```
```
## # A tibble: 252 x 1
## region
## <chr>
## 1 Afghanistan
## 2 Albania
## 3 Algeria
## 4 American Samoa
## 5 Andorra
## 6 Angola
## 7 Anguilla
## 8 Antarctica
## 9 Antigua
## 10 Argentina
## 11 Armenia
## 12 Aruba
## 13 Ascension Island
## 14 Australia
## 15 Austria
## 16 Azerbaijan
## 17 Azores
## 18 Bahamas
## 19 Bahrain
## 20 Bangladesh
## 21 Barbados
## 22 Barbuda
## 23 Belarus
## 24 Belgium
## 25 Belize
## 26 Benin
## 27 Bermuda
## 28 Bhutan
## 29 Bolivia
## 30 Bonaire
## 31 Bosnia and Herzegovina
## 32 Botswana
## 33 Brazil
## 34 Brunei
## 35 Bulgaria
## 36 Burkina Faso
## 37 Burundi
## 38 Cambodia
## 39 Cameroon
## 40 Canada
## 41 Canary Islands
## 42 Cape Verde
## 43 Cayman Islands
## 44 Central African Republic
## 45 Chad
## 46 Chagos Archipelago
## 47 Chile
## 48 China
## 49 Christmas Island
## 50 Cocos Islands
## 51 Colombia
## 52 Comoros
## 53 Cook Islands
## 54 Costa Rica
## 55 Croatia
## 56 Cuba
## 57 Curacao
## 58 Cyprus
## 59 Czech Republic
## 60 Democratic Republic of the Congo
## 61 Denmark
## 62 Djibouti
## 63 Dominica
## 64 Dominican Republic
## 65 Ecuador
## 66 Egypt
## 67 El Salvador
## 68 Equatorial Guinea
## 69 Eritrea
## 70 Estonia
## 71 Ethiopia
## 72 Falkland Islands
## 73 Faroe Islands
## 74 Fiji
## 75 Finland
## 76 France
## 77 French Guiana
## 78 French Polynesia
## 79 French Southern and Antarctic Lands
## 80 Gabon
## 81 Gambia
## 82 Georgia
## 83 Germany
## 84 Ghana
## 85 Greece
## 86 Greenland
## 87 Grenada
## 88 Grenadines
## 89 Guadeloupe
## 90 Guam
## 91 Guatemala
## 92 Guernsey
## 93 Guinea
## 94 Guinea-Bissau
## 95 Guyana
## 96 Haiti
## 97 Heard Island
## 98 Honduras
## 99 Hungary
## 100 Iceland
## 101 India
## 102 Indonesia
## 103 Iran
## 104 Iraq
## 105 Ireland
## 106 Isle of Man
## 107 Israel
## 108 Italy
## 109 Ivory Coast
## 110 Jamaica
## 111 Japan
## 112 Jersey
## 113 Jordan
## 114 Kazakhstan
## 115 Kenya
## 116 Kiribati
## 117 Kosovo
## 118 Kuwait
## 119 Kyrgyzstan
## 120 Laos
## 121 Latvia
## 122 Lebanon
## 123 Lesotho
## 124 Liberia
## 125 Libya
## 126 Liechtenstein
## 127 Lithuania
## 128 Luxembourg
## 129 Macedonia
## 130 Madagascar
## 131 Madeira Islands
## 132 Malawi
## 133 Malaysia
## 134 Maldives
## 135 Mali
## 136 Malta
## 137 Marshall Islands
## 138 Martinique
## 139 Mauritania
## 140 Mauritius
## 141 Mayotte
## 142 Mexico
## 143 Micronesia
## 144 Moldova
## 145 Monaco
## 146 Mongolia
## 147 Montenegro
## 148 Montserrat
## 149 Morocco
## 150 Mozambique
## 151 Myanmar
## 152 Namibia
## 153 Nauru
## 154 Nepal
## 155 Netherlands
## 156 Nevis
## 157 New Caledonia
## 158 New Zealand
## 159 Nicaragua
## 160 Niger
## 161 Nigeria
## 162 Niue
## 163 Norfolk Island
## 164 North Korea
## 165 Northern Mariana Islands
## 166 Norway
## 167 Oman
## 168 Pakistan
## 169 Palau
## 170 Palestine
## 171 Panama
## 172 Papua New Guinea
## 173 Paraguay
## 174 Peru
## 175 Philippines
## 176 Pitcairn Islands
## 177 Poland
## 178 Portugal
## 179 Puerto Rico
## 180 Qatar
## 181 Republic of Congo
## 182 Reunion
## 183 Romania
## 184 Russia
## 185 Rwanda
## 186 Saba
## 187 Saint Barthelemy
## 188 Saint Helena
## 189 Saint Kitts
## 190 Saint Lucia
## 191 Saint Martin
## 192 Saint Pierre and Miquelon
## 193 Saint Vincent
## 194 Samoa
## 195 San Marino
## 196 Sao Tome and Principe
## 197 Saudi Arabia
## 198 Senegal
## 199 Serbia
## 200 Seychelles
## 201 Siachen Glacier
## 202 Sierra Leone
## 203 Singapore
## 204 Sint Eustatius
## 205 Sint Maarten
## 206 Slovakia
## 207 Slovenia
## 208 Solomon Islands
## 209 Somalia
## 210 South Africa
## 211 South Georgia
## 212 South Korea
## 213 South Sandwich Islands
## 214 South Sudan
## 215 Spain
## 216 Sri Lanka
## 217 Sudan
## 218 Suriname
## 219 Swaziland
## 220 Sweden
## 221 Switzerland
## 222 Syria
## 223 Taiwan
## 224 Tajikistan
## 225 Tanzania
## 226 Thailand
## 227 Timor-Leste
## 228 Tobago
## 229 Togo
## 230 Tonga
## 231 Trinidad
## 232 Tunisia
## 233 Turkey
## 234 Turkmenistan
## 235 Turks and Caicos Islands
## 236 Uganda
## 237 UK
## 238 Ukraine
## 239 United Arab Emirates
## 240 Uruguay
## 241 USA
## 242 Uzbekistan
## 243 Vanuatu
## 244 Vatican
## 245 Venezuela
## 246 Vietnam
## 247 Virgin Islands
## 248 Wallis and Futuna
## 249 Western Sahara
## 250 Yemen
## 251 Zambia
## 252 Zimbabwe
```
```r
df.oil <- df.oil %>% mutate(country = recode(country,
`United States` = 'USA'
, `United Kingdom` = 'UK'
, `Congo, Democratic Republic of the` = 'Democratic Republic of the Congo'
, `Trinidad and Tobago` = 'Trinidad'
, `Sudan and South Sudan` = 'Sudan'
#, `Sudan and South Sudan` = 'South Sudan'
, `Congo, Republic of the` = 'Republic of Congo'
)
)
#-----------------------
# JOIN DATASETS TOGETHER
#-----------------------
map.oil <- left_join( map.world, df.oil, by = c('region' = 'country'))
#=====
# PLOT
#=====
# BASIC (this is a first draft)
ggplot(map.oil, aes( x = long, y = lat, group = group )) +
geom_polygon(aes(fill = oil_bbl_per_day))
```
<img src="ggplot_201805_files/figure-html/unnamed-chunk-7-1.png" width="672" />
```r
# Top 5 countries
map.oil %>% distinct(rank, region) %>% top_n(-5, rank) %>% arrange(rank) %>% select(region)
```
```
## region
## 1 Russia
## 2 Saudi Arabia
## 3 USA
## 4 Iraq
## 5 Iran
```
```r
# PROFESSIONAL ELEGANCE (this is a first draft)
gill_map <-
ggplot(map.oil, aes( x = long, y = lat, group = group )) +
geom_polygon(aes(fill = oil_bbl_per_day)) +
scale_fill_gradientn(colours = c('#461863','#404E88','#2A8A8C','#7FD157','#F9E53F')
,values = scales::rescale(c(100,96581,822675,3190373,10000000))
,labels = comma
,breaks = c(100,96581,822675,3190373,10000000)
) +
guides(fill = guide_legend(reverse = T)) +
labs(fill = 'bbl/day'
,title = 'Oil Production by Country'
,subtitle = 'Barrels per day, 2016'
,x = NULL
,y = NULL) +
theme(text = element_text(family = 'Gill Sans MT', color = '#EEEEEE')
,plot.title = element_text(size = 28)
,plot.subtitle = element_text(size = 14)
,axis.ticks = element_blank()
,axis.text = element_blank()
,panel.grid = element_blank()
,panel.background = element_rect(fill = '#333333')
,plot.background = element_rect(fill = '#333333')
,legend.position = c(.18,.36)
,legend.background = element_blank()
,legend.key = element_blank()
) +
annotate(geom = 'text'
,label = 'Source: U.S. Energy Information Administration\nhttps://en.wikipedia.org/wiki/List_of_countries_by_oil_production'
,x = 18, y = -55
,size = 3
,family = 'Gill Sans MT'
,color = '#CCCCCC'
,hjust = 'left'
)
orig_map <-
ggplot(map.oil, aes( x = long, y = lat, group = group )) +
geom_polygon(aes(fill = oil_bbl_per_day)) +
scale_fill_gradientn(colours = c('#461863','#404E88','#2A8A8C','#7FD157','#F9E53F')
,values = scales::rescale(c(100,96581,822675,3190373,10000000))
,labels = comma
,breaks = c(100,96581,822675,3190373,10000000)
) +
guides(fill = guide_legend(reverse = T)) +
labs(fill = 'bbl/day'
,title = 'Oil Production by Country'
,subtitle = 'Barrels per day, 2016'
,x = NULL
,y = NULL) +
theme(text = element_text(color = '#EEEEEE')
,plot.title = element_text(size = 28)
,plot.subtitle = element_text(size = 14)
,axis.ticks = element_blank()
,axis.text = element_blank()
,panel.grid = element_blank()
,panel.background = element_rect(fill = '#333333')
,plot.background = element_rect(fill = '#333333')
,legend.position = c(.18,.36)
,legend.background = element_blank()
,legend.key = element_blank()
) +
annotate(geom = 'text'
,label = 'Source: U.S. Energy Information Administration\nhttps://en.wikipedia.org/wiki/List_of_countries_by_oil_production'
,x = 18, y = -55
,size = 3
,color = '#CCCCCC'
,hjust = 'left'
)
gill_map
```
```
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
```
```
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x
## $y, : font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x
## $y, : font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x
## $y, : font family not found in Windows font database
```
```
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
```
<img src="ggplot_201805_files/figure-html/unnamed-chunk-7-2.png" width="672" />
---
# Default [ (theme_get() ] vs. Gill Sans font
## font family not found in Windows font database

--
## Gill Sans after

---
# Same but using grid.arrange from the gridExtra package
```r
if (!require("grid")) install.packages("grid", repos = "http://cran.us.r-project.org")
```
```
## Loading required package: grid
```
```r
if (!require("gridExtra")) install.packages("gridExtra", repos = "http://cran.us.r-project.org")
```
```
## Loading required package: gridExtra
```
```
##
## Attaching package: 'gridExtra'
```
```
## The following object is masked from 'package:dplyr':
##
## combine
```
```r
gridExtra::grid.arrange(orig_map, gill_map , nrow = 2, heights = c(2,2))
```
```
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
```
```
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x
## $y, : font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x
## $y, : font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x
## $y, : font family not found in Windows font database
```
```
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
```
<img src="ggplot_201805_files/figure-html/unnamed-chunk-8-1.png" width="672" />
---
# also see grid.arrange in the code from the "Applying Data Science fundamentals to Stock Market Data"
# TriPASS Data Sci presentation by Conrad D'Cruz and Yin-Ting Chou

# https://github.com/choux130/EU_TSClustering_101117/blob/master/TSClustering/code_1024/execute_funs.R
# https://www.meetup.com/tripass/events/244117529/
---
# References
* http://www.sharpsightlabs.com/blog/map-public-debt-ggplot2/
* http://www.sharpsightlabs.com/blog/map-oil-production-country-r/
* https://www.rstudio.com/wp-content/uploads/2016/03/rmarkdown-cheatsheet-2.0.pdf
</textarea>
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script>var slideshow = remark.create();
if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {
window.dispatchEvent(new Event('resize'));
});
(function() {
var d = document, s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler");
if (!r) return;
s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }";
d.head.appendChild(s);
})();</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre']
}
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML';
if (location.protocol !== 'file:' && /^https?:/.test(script.src))
script.src = script.src.replace(/^https?:/, '');
document.getElementsByTagName('head')[0].appendChild(script);
})();
</script>
</body>
</html>