forked from srkobakian/R-ladies-colombo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.html
1643 lines (1264 loc) · 53 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 lang="" xml:lang="">
<head>
<title>Around the world in 30 minutes</title>
<meta charset="utf-8" />
<meta name="author" content="Stephanie Kobakian" />
<script src="libs/header-attrs/header-attrs.js"></script>
<link href="libs/remark-css/default.css" rel="stylesheet" />
<link href="libs/remark-css/rladies.css" rel="stylesheet" />
<link href="libs/remark-css/rladies-fonts.css" rel="stylesheet" />
<script src="libs/kePrint/kePrint.js"></script>
<link href="libs/lightable/lightable.css" rel="stylesheet" />
</head>
<body>
<textarea id="source">
<img src="images/titleimg.png" style="width 100%;"/>
---
class: top
<img src="images/qut_crest.png" style="position:absolute;bottom:400px;right:200px;height:200px;width:200px;" />
<img src="images/monash_crest.jpg" style="position:absolute;bottom:100px;right:200px;height:200px;width:200px;" />
# About me
### <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" style="height:1em;fill:currentColor;position:relative;display:inline-block;top:.1em;"> [ comment ] <path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z"></path></svg> <svg viewBox="0 0 496 512" xmlns="http://www.w3.org/2000/svg" style="height:1em;fill:currentColor;position:relative;display:inline-block;top:.1em;"> [ comment ] <path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"></path></svg> srkobakian
Master of Philosophy in Statistics (QUT)
Bachelor of Commerce, Bachelor of Economics
I live in Melbourne, Australia
???
I spent most of my masters researching map displays used in Cancer Atlases.
To explore the use of alternative displays, and select one that would work for Australia.
We couldn't find one that would really improve the choropleth map display
---
class: top, center, inverse
<img src="https://media.giphy.com/media/SufoKsersIO2Y/giphy.gif" style="position:absolute;bottom:50px;left:40%;height:50%;width:20%;" />
# Ask me a question
### Use the chat
### Answer in discussion time
???
Now there may have been some terms I used that are unfamiliar to you. And that is great because it means I may get to teach you something today.
So If you have a question during the talk, use the chat to send it through, we may answer it as the presentation continues but if we don't i'll address it in the discussion time.
---
class: top, center
# What can you do with ggplot2?
--
## Use the Grammar of Graphics to build visulisations
<img src="https://prital.netlify.app/talks/rladies2021/fig/7_GG.png" style="position:absolute;height:50%;width:20%;left:40%;" />
---
# What is the geom for mapping?
--
## This is not a simple question
## There are many types of maps
ggplot2: Elegant Graphics for Data Analysis:
[Chapter 6: Maps](https://ggplot2-book.org/maps.html)
<img src="https://ggplot2-book.org/cover.jpg" style="position:absolute;left:60%;bottom:25%;height:60%;width:25%;" />
???
This is not a simple question
There are many ways to map
What do we have to work with?
---
# What do we need to plot?
.pull-left[
Libraries
```r
library(ggplot2)
library(maps)
```
Data
```r
world <- map_data("world")
Australia <- world %>% filter(region == "Australia")
Australia
```
]
.pull-right[
```
## long lat group order region subregion
## 1 123.5945 -12.42568 133 7115 Australia Ashmore and Cartier Islands
## 2 123.5952 -12.43594 133 7116 Australia Ashmore and Cartier Islands
## 3 123.5732 -12.43418 133 7117 Australia Ashmore and Cartier Islands
## 4 123.5725 -12.42393 133 7118 Australia Ashmore and Cartier Islands
## 5 123.5945 -12.42568 133 7119 Australia Ashmore and Cartier Islands
## 6 158.8788 -54.70976 139 7267 Australia Macquarie Island
```
]
---
# Mapping Data
.pull-left[
```r
ggplot(Australia) +
geom_point(aes(x = long, y = lat))
```
<img src="Index_files/figure-html/auspoints-1.png" width="3600" />
]
.pull-right[
```r
ggplot(Australia) +
geom_line(aes(x = long, y = lat))
```
<img src="Index_files/figure-html/ausline-1.png" width="3600" />
]
???
These points are what we need for a map.
But it is about how you use them.
---
# Polygon Mapping
.pull-left[
```r
ggplot(Australia) +
* geom_polygon(aes(x = long, y = lat, group = group))
```
<img src="Index_files/figure-html/auspolygon-1.png" width="3600" />
]
.pull-right[
### This is a great start
- It looks like Australia!
- Borders are clear
- Islands are also clear
### How can we improve this?
]
???
Polygons are very similar to paths (as drawn by geom_path()) except that the start and end points are connected and the inside is coloured by fill.
---
class: middle, center, inverse
# SF system
---
## Simple Features
### Key difference:
### geometry list-column
--
Converts many, many rows
into a single row per area
Geometries fit together,
like puzzle pieces
<img src="images/sfAH.jpg" style="position:absolute;right:2%;bottom:15%;height:80%;width:60%;" />
.footnote[
[1] https://r-spatial.github.io/sf/index.html
]
---
# ozmaps package
.pull-left[
```r
library(sf)
library(ozmaps)
sf_oz <- ozmap_data("country")
sf_oz %>% kable()
```
<table>
<thead>
<tr>
<th style="text-align:left;"> NAME </th>
<th style="text-align:left;"> geometry </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> Australia </td>
<td style="text-align:left;"> MULTIPOLYGON (((144.8691 -4... </td>
</tr>
</tbody>
</table>
```r
*ggplot(sf_oz) + geom_sf()
```
]
.pull-right[
<img src="Index_files/figure-html/unnamed-chunk-1-1.png" width="3600" />
]
---
.pull-left[
<table>
<thead>
<tr>
<th style="text-align:left;"> NAME </th>
<th style="text-align:left;"> geometry </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> New South Wales </td>
<td style="text-align:left;"> MULTIPOLYGON (((150.7016 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Victoria </td>
<td style="text-align:left;"> MULTIPOLYGON (((146.6196 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Queensland </td>
<td style="text-align:left;"> MULTIPOLYGON (((148.8473 -2... </td>
</tr>
<tr>
<td style="text-align:left;"> South Australia </td>
<td style="text-align:left;"> MULTIPOLYGON (((137.3481 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Western Australia </td>
<td style="text-align:left;"> MULTIPOLYGON (((126.3868 -1... </td>
</tr>
<tr>
<td style="text-align:left;"> Tasmania </td>
<td style="text-align:left;"> MULTIPOLYGON (((147.8397 -4... </td>
</tr>
<tr>
<td style="text-align:left;"> Northern Territory </td>
<td style="text-align:left;"> MULTIPOLYGON (((136.3669 -1... </td>
</tr>
<tr>
<td style="text-align:left;"> Australian Capital Territory </td>
<td style="text-align:left;"> MULTIPOLYGON (((149.2317 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Other Territories </td>
<td style="text-align:left;"> MULTIPOLYGON (((167.9333 -2... </td>
</tr>
</tbody>
</table>
]
.pull-right[
```r
sf_states <- ozmap_data("states")
ggplot(sf_states) + geom_sf()
```
<img src="Index_files/figure-html/ozmapstates2-1.png" width="3600" />
]
---
class: middle, center, inverse
# Creating Choropleth maps
### A choropleth maps fills regions on the maps according to their data value
--
## We need two things:
### Map and Data
---
# Data: COVID LIVE Australia
```r
*library(rvest)
*library(polite)
covid_url <- "https://covidlive.com.au/report/cases"
covid_data <- bow(covid_url) %>%
scrape() %>%
html_table() %>%
purrr::pluck(2) %>%
as_tibble()
covid_data
```
```
## # A tibble: 9 x 5
## STATE CASES OSEAS VAR NET
## <chr> <chr> <int> <lgl> <int>
## 1 Victoria 20,479 NA NA 0
## 2 NSW 5,150 1 NA 1
## 3 Queensland 1,323 2 NA 2
## 4 WA 912 1 NA 1
## 5 SA 610 NA NA 0
## 6 Tasmania 234 NA NA 0
## 7 ACT 118 NA NA 0
## 8 NT 104 NA NA 0
## 9 Australia 28,930 4 NA 4
```
<img src="images/covidlive.png" style="position:absolute;bottom:2%;right:2%;height:90%;width:50%;" />
---
.pull-left[
# Data <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" style="height:1em;fill:currentColor;position:relative;display:inline-block;top:.1em;"> [ comment ] <path d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"></path></svg>
<table>
<thead>
<tr>
<th style="text-align:left;"> STATE </th>
<th style="text-align:left;"> CASES </th>
<th style="text-align:right;"> OSEAS </th>
<th style="text-align:right;"> NET </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> Victoria </td>
<td style="text-align:left;"> 20,479 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> NSW </td>
<td style="text-align:left;"> 5,150 </td>
<td style="text-align:right;"> 1 </td>
<td style="text-align:right;"> 1 </td>
</tr>
<tr>
<td style="text-align:left;"> Queensland </td>
<td style="text-align:left;"> 1,323 </td>
<td style="text-align:right;"> 2 </td>
<td style="text-align:right;"> 2 </td>
</tr>
<tr>
<td style="text-align:left;"> WA </td>
<td style="text-align:left;"> 912 </td>
<td style="text-align:right;"> 1 </td>
<td style="text-align:right;"> 1 </td>
</tr>
<tr>
<td style="text-align:left;"> SA </td>
<td style="text-align:left;"> 610 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Tasmania </td>
<td style="text-align:left;"> 234 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> ACT </td>
<td style="text-align:left;"> 118 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> NT </td>
<td style="text-align:left;"> 104 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Australia </td>
<td style="text-align:left;"> 28,930 </td>
<td style="text-align:right;"> 4 </td>
<td style="text-align:right;"> 4 </td>
</tr>
</tbody>
</table>
]
.pull-right[
# Map <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" style="height:1em;fill:currentColor;position:relative;display:inline-block;top:.1em;"> [ comment ] <path d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"></path></svg>
<table>
<thead>
<tr>
<th style="text-align:left;"> NAME </th>
<th style="text-align:left;"> geometry </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> New South Wales </td>
<td style="text-align:left;"> MULTIPOLYGON (((150.7016 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Victoria </td>
<td style="text-align:left;"> MULTIPOLYGON (((146.6196 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Queensland </td>
<td style="text-align:left;"> MULTIPOLYGON (((148.8473 -2... </td>
</tr>
<tr>
<td style="text-align:left;"> South Australia </td>
<td style="text-align:left;"> MULTIPOLYGON (((137.3481 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Western Australia </td>
<td style="text-align:left;"> MULTIPOLYGON (((126.3868 -1... </td>
</tr>
<tr>
<td style="text-align:left;"> Tasmania </td>
<td style="text-align:left;"> MULTIPOLYGON (((147.8397 -4... </td>
</tr>
<tr>
<td style="text-align:left;"> Northern Territory </td>
<td style="text-align:left;"> MULTIPOLYGON (((136.3669 -1... </td>
</tr>
<tr>
<td style="text-align:left;"> Australian Capital Territory </td>
<td style="text-align:left;"> MULTIPOLYGON (((149.2317 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Other Territories </td>
<td style="text-align:left;"> MULTIPOLYGON (((167.9333 -2... </td>
</tr>
</tbody>
</table>
]
---
# To join the Covid data to the map
--
.pull-left[
### - Expand the abbreviations so the names match
### - Convert cases to numeric values
```r
covid_data <- covid_data %>%
mutate(STATE = case_when(
# replace the abbreviations
STATE == "NSW" ~ "New South Wales",
STATE == "WA" ~ "Western Australia",
STATE == "SA" ~ "South Australia",
STATE == "NT" ~ "Northern Territory",
STATE == "ACT" ~ "Australian Capital Territory",
# keep the rest of the state names
TRUE ~ STATE )) %>%
mutate(CASES = parse_number(CASES))
```
]
.pull-right[
### - Peform a join
```r
covid_states <- left_join(ozmap_states, covid_data,
by = c("NAME" = "STATE"))
```
### - Remove the "Other Territories"
```r
covid_states <- covid_states %>%
filter(!(NAME == "Other Territories"))
```
]
---
.pull-left[
# Data <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" style="height:1em;fill:currentColor;position:relative;display:inline-block;top:.1em;"> [ comment ] <path d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"></path></svg>
<table>
<thead>
<tr>
<th style="text-align:left;"> STATE </th>
<th style="text-align:right;"> CASES </th>
<th style="text-align:right;"> OSEAS </th>
<th style="text-align:right;"> NET </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> Victoria </td>
<td style="text-align:right;"> 20479 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> New South Wales </td>
<td style="text-align:right;"> 5150 </td>
<td style="text-align:right;"> 1 </td>
<td style="text-align:right;"> 1 </td>
</tr>
<tr>
<td style="text-align:left;"> Queensland </td>
<td style="text-align:right;"> 1323 </td>
<td style="text-align:right;"> 2 </td>
<td style="text-align:right;"> 2 </td>
</tr>
<tr>
<td style="text-align:left;"> Western Australia </td>
<td style="text-align:right;"> 912 </td>
<td style="text-align:right;"> 1 </td>
<td style="text-align:right;"> 1 </td>
</tr>
<tr>
<td style="text-align:left;"> South Australia </td>
<td style="text-align:right;"> 610 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Tasmania </td>
<td style="text-align:right;"> 234 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Australian Capital Territory </td>
<td style="text-align:right;"> 118 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Northern Territory </td>
<td style="text-align:right;"> 104 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Australia </td>
<td style="text-align:right;"> 28930 </td>
<td style="text-align:right;"> 4 </td>
<td style="text-align:right;"> 4 </td>
</tr>
</tbody>
</table>
]
.pull-right[
# Map <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" style="height:1em;fill:currentColor;position:relative;display:inline-block;top:.1em;"> [ comment ] <path d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"></path></svg>
<table>
<thead>
<tr>
<th style="text-align:left;"> NAME </th>
<th style="text-align:left;"> geometry </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> New South Wales </td>
<td style="text-align:left;"> MULTIPOLYGON (((150.7016 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Victoria </td>
<td style="text-align:left;"> MULTIPOLYGON (((146.6196 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Queensland </td>
<td style="text-align:left;"> MULTIPOLYGON (((148.8473 -2... </td>
</tr>
<tr>
<td style="text-align:left;"> South Australia </td>
<td style="text-align:left;"> MULTIPOLYGON (((137.3481 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Western Australia </td>
<td style="text-align:left;"> MULTIPOLYGON (((126.3868 -1... </td>
</tr>
<tr>
<td style="text-align:left;"> Tasmania </td>
<td style="text-align:left;"> MULTIPOLYGON (((147.8397 -4... </td>
</tr>
<tr>
<td style="text-align:left;"> Northern Territory </td>
<td style="text-align:left;"> MULTIPOLYGON (((136.3669 -1... </td>
</tr>
<tr>
<td style="text-align:left;"> Australian Capital Territory </td>
<td style="text-align:left;"> MULTIPOLYGON (((149.2317 -3... </td>
</tr>
<tr>
<td style="text-align:left;"> Other Territories </td>
<td style="text-align:left;"> MULTIPOLYGON (((167.9333 -2... </td>
</tr>
</tbody>
</table>
]
---
.pull-left[
# Complete map data <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" style="height:1em;fill:currentColor;position:relative;display:inline-block;top:.1em;"> [ comment ] <path d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"></path></svg>
<table class="table" style="font-size: 12px; margin-left: auto; margin-right: auto;">
<thead>
<tr>
<th style="text-align:left;"> NAME </th>
<th style="text-align:left;"> geometry </th>
<th style="text-align:right;"> CASES </th>
<th style="text-align:right;"> OSEAS </th>
<th style="text-align:right;"> NET </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> New South Wales </td>
<td style="text-align:left;"> MULTIPOLYGON (((150.7016 -3... </td>
<td style="text-align:right;"> 5150 </td>
<td style="text-align:right;"> 1 </td>
<td style="text-align:right;"> 1 </td>
</tr>
<tr>
<td style="text-align:left;"> Victoria </td>
<td style="text-align:left;"> MULTIPOLYGON (((146.6196 -3... </td>
<td style="text-align:right;"> 20479 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Queensland </td>
<td style="text-align:left;"> MULTIPOLYGON (((148.8473 -2... </td>
<td style="text-align:right;"> 1323 </td>
<td style="text-align:right;"> 2 </td>
<td style="text-align:right;"> 2 </td>
</tr>
<tr>
<td style="text-align:left;"> South Australia </td>
<td style="text-align:left;"> MULTIPOLYGON (((137.3481 -3... </td>
<td style="text-align:right;"> 610 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Western Australia </td>
<td style="text-align:left;"> MULTIPOLYGON (((126.3868 -1... </td>
<td style="text-align:right;"> 912 </td>
<td style="text-align:right;"> 1 </td>
<td style="text-align:right;"> 1 </td>
</tr>
<tr>
<td style="text-align:left;"> Tasmania </td>
<td style="text-align:left;"> MULTIPOLYGON (((147.8397 -4... </td>
<td style="text-align:right;"> 234 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Northern Territory </td>
<td style="text-align:left;"> MULTIPOLYGON (((136.3669 -1... </td>
<td style="text-align:right;"> 104 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
<tr>
<td style="text-align:left;"> Australian Capital Territory </td>
<td style="text-align:left;"> MULTIPOLYGON (((149.2317 -3... </td>
<td style="text-align:right;"> 118 </td>
<td style="text-align:right;"> NA </td>
<td style="text-align:right;"> 0 </td>
</tr>
</tbody>
</table>
]
.pull-right[
# Choropleth Map <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" style="height:1em;fill:currentColor;position:relative;display:inline-block;top:.1em;"> [ comment ] <path d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"></path></svg>
```r
ggplot(covid_states) +
geom_sf(aes(fill = CASES))
```
<img src="Index_files/figure-html/covidmap-1.png" width="3600" />
]
---
```r
*library(ggforce)
ggplot(covid_states) +
geom_sf(aes(fill = CASES)) +
* facet_zoom(xy = NAME == "Australian Capital Territory", zoom.size = 0.6)
```
<img src="Index_files/figure-html/auszoom2-1.png" width="7800" />
---
class: inverse, center
# Off we go!
<img src="https://simplyettad.files.wordpress.com/2016/05/plane-travel-animated-gif-4.gif" style="position:absolute;bottom:10%;left:25%;height:55%;width:50%;" />
---
# Covid in Sri Lanka
<img src="images/covidSLpdf.png" style="position:absolute;bottom:15%;left:12%;height:70%;width:35%;" />
<img src="images/covidSLtable.png" style="position:absolute;bottom:15%;right:12%;height:70%;width:35%;" />
.footnote[
[2] https://covid19.gov.lk/wp-content/uploads/2021/02/sitrep-sl-en-18-02_10_21.pdf
]
---
### Data: Epidemiology Unit, Ministry of Health
.left-column[
<table>
<thead>
<tr>
<th style="text-align:left;"> DISTRICT </th>
<th style="text-align:left;"> Count </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> COLOMBO </td>
<td style="text-align:left;"> 26925 </td>
</tr>
<tr>
<td style="text-align:left;"> GAMPAHA </td>
<td style="text-align:left;"> 15669 </td>
</tr>
<tr>
<td style="text-align:left;"> PUTTALAM </td>
<td style="text-align:left;"> 1011 </td>
</tr>
<tr>
<td style="text-align:left;"> KALUTARA </td>
<td style="text-align:left;"> 5674 </td>
</tr>
<tr>
<td style="text-align:left;"> ANURADHAPURA </td>
<td style="text-align:left;"> 428 </td>
</tr>
<tr>
<td style="text-align:left;"> KANDY </td>
<td style="text-align:left;"> 3573 </td>
</tr>
<tr>
<td style="text-align:left;"> KURUNEGALA </td>
<td style="text-align:left;"> 2040 </td>
</tr>
<tr>
<td style="text-align:left;"> POLONNARUWA </td>
<td style="text-align:left;"> 202 </td>
</tr>
<tr>
<td style="text-align:left;"> JAFFNA </td>
<td style="text-align:left;"> 229 </td>
</tr>
<tr>
<td style="text-align:left;"> RATNAPURA </td>
<td style="text-align:left;"> 1661 </td>
</tr>
</tbody>
</table>
]
.right-column[
```r
*library(stringr)
# https://covid19.gov.lk/wp-content/uploads/2021/02/sitrep-sl-en-18-02_10_21.pdf
covid_sl_table <- c("COLOMBO26925GAMPAHA15669PUTTALAM1011KALUTARA5674ANURADHAPURA428KANDY3573KURUNEGALA2040POLONNARUWA202JAFFNA229RATNAPURA1661KEGALLE1315MONERAGALA345KALMUNAI1183MATALE702GALLE1852AMPARA227BADULLA1060MATARA1346BATTICOLOA426HAMBANTOTA539VAVUNIA356TRINCOMALEE463NUWARAELIYA970KILINOCHCHI80MANNAR198MULLATIVU20")
# Extract names of regions, using a regular expression to search for letters
districts <- covid_sl_table %>%
str_extract_all(string = ., pattern = "[A-Z]*") %>% unlist( ) %>%
str_subset(., pattern = "[A-Z]")
# Extract number of cases, using a regular expression to search for numbers
counts <- covid_sl_table %>%
str_extract_all(string = ., pattern = "[0-9]*") %>% unlist() %>%
str_subset(., pattern = "[0-9]")
# Combine two sets of data to create a table
covid_sl <- tibble(DISTRICT = districts,
Count = counts) %>%
mutate(Count = parse_number(Count))
```
]
---
# Map data for Sri Lanka
```r
# Select the level 2 districts (adm2)
sf_sl <- read_sf("data/lka_adm_slsd_20200305_shp/lka_admbnda_adm2_slsd_20200305.shp") %>%
select(ADM2_EN, geometry)
sf_sl
```
```
## Simple feature collection with 26 features and 1 field
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: 79.51916 ymin: 5.918297 xmax: 81.8772 ymax: 9.835718
## geographic CRS: WGS 84
## # A tibble: 26 x 2
## ADM2_EN geometry
## <chr> <MULTIPOLYGON [°]>
## 1 [unknown] (((79.80303 7.8503, 79.80333 7.849463, 79.80333 7.849463, 79.803~
## 2 Ampara (((81.23892 7.738495, 81.23903 7.73846, 81.23912 7.738474, 81.23~
## 3 Anuradhapu~ (((80.79126 8.918771, 80.79164 8.918763, 80.79209 8.91885, 80.79~
## 4 Badulla (((80.9806 7.61768, 80.98104 7.617651, 80.98152 7.617694, 80.982~
## 5 Batticaloa (((81.76936 7.536074, 81.76918 7.536048, 81.76907 7.536107, 81.7~
## 6 Colombo (((79.87696 6.98085, 79.87805 6.98068, 79.87808 6.980692, 79.878~
## 7 Galle (((80.09646 6.132867, 80.09638 6.132866, 80.0963 6.132871, 80.09~
## 8 Gampaha (((80.14677 7.312115, 80.14689 7.311824, 80.1469 7.311761, 80.14~
## 9 Hambantota (((81.61401 6.572167, 81.61425 6.572167, 81.61462 6.572185, 81.6~
## 10 Jaffna (((79.52615 9.383134, 79.52537 9.383026, 79.5245 9.383076, 79.52~
## # ... with 16 more rows
```
```r
# Choose a projection from epsg.io:
sf_sl <- sf_sl %>% st_transform(5235)
```
.footnote[
[3] https://data.humdata.org/dataset/sri-lanka-administrative-levels-0-4-boundaries
]
---
.pull-left[
## Data <svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" style="height:1em;fill:currentColor;position:relative;display:inline-block;top:.1em;"> [ comment ] <path d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"></path></svg>
<table class="table" style="font-size: 20px; margin-left: auto; margin-right: auto;">
<thead>
<tr>
<th style="text-align:left;"> DISTRICT </th>
<th style="text-align:right;"> Count </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;"> COLOMBO </td>
<td style="text-align:right;"> 26925 </td>
</tr>
<tr>
<td style="text-align:left;"> GAMPAHA </td>
<td style="text-align:right;"> 15669 </td>
</tr>
<tr>
<td style="text-align:left;"> PUTTALAM </td>
<td style="text-align:right;"> 1011 </td>
</tr>
<tr>
<td style="text-align:left;"> KALUTARA </td>
<td style="text-align:right;"> 5674 </td>
</tr>
<tr>
<td style="text-align:left;"> ANURADHAPURA </td>
<td style="text-align:right;"> 428 </td>
</tr>
<tr>