-
Notifications
You must be signed in to change notification settings - Fork 1
/
11202020.html
878 lines (651 loc) · 22.8 KB
/
11202020.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
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<title>Map visualization basics</title>
<meta charset="utf-8" />
<meta name="author" content="Paul Villanueva" />
<meta name="date" content="2020-11-20" />
<script src="libs/header-attrs-2.10/header-attrs.js"></script>
<link href="libs/remark-css-0.0.1/default.css" rel="stylesheet" />
<link href="libs/remark-css-0.0.1/default-fonts.css" rel="stylesheet" />
</head>
<body>
<textarea id="source">
class: center, middle, inverse, title-slide
# Map visualization basics
### Paul Villanueva
### 11/20/2020
---
class: middle
# Today's goal:
- Reproduce this animation:
.center[
<img src="./pct_change_by_year.gif" width="600" />
]
---
# Along the way, we'll:
- Learn some basics about shapefiles
- Work with some open data from `data.iowa.gov` and `geodata.iowa.gov`
- Use simple features with `ggplot2`
- Do a basic animation
---
# About me
- Bioinformatics PhD student in Adina Howe's lab
- Background in math and computer science
- Previous project was [MetaFunPrimer](https://github.com/pommevilla/MetaFunPrimer), a primer design pipeline for high-throughput qPCR.
- Current research is on the impact of human activity on biodiversity and environmental multifunctionality.
- Interested in machine learning, statistical modeling, Python, R, data visualization, reproducible research, and vim
---
class: inverse, center, middle
# Getting started
---
# Clone the repo:
```r
git clone https://github.com/pommevilla/lunchinatoR.git
```
# Install the packages we'll use today
- `tidyverse`: data manipulation and visualization
- `sf`: working with shapefiles
- `gganimate`: animations
- `ggthemes`: we'll use `theme_map()`
- `geofacet`: some bonus visualizations
---
# Reading in a simple feature
```r
library(sf)
iowa.sf <- st_read('data/iowa_county_shapes')
```
.footnote[Source: https://geodata.iowa.gov/dataset/county-boundaries-iowa]
---
# What's in an `sf` object?
```r
iowa.sf
```
```
## Simple feature collection with 99 features and 10 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: 202073.8 ymin: 4470598 xmax: 736849.2 ymax: 4822674
## Projected CRS: NAD83 / UTM zone 15N
## First 10 features:
## Shape_Leng Shape_Area AREA PERIMETER CO_NUMBER CO_FIPS ACRES FIPS
## 1 192784.4 1394779996 1394779996 192783.7 56 111 344657.6 19111
## 2 146566.4 1335646711 1335646711 146566.5 4 7 330045.5 19007
## 3 147784.7 1364467491 1364467491 147785.1 93 185 337167.3 19185
## 4 148600.6 1381358612 1381358612 148600.8 27 53 341341.1 19053
## 5 144994.2 1306355106 1306355106 144995.3 26 51 322807.4 19051
## 6 146043.0 1270590821 1270590821 146043.4 89 177 313969.8 19177
## 7 149323.9 1394401127 1394401127 149323.5 80 159 344564.0 19159
## 8 150053.8 1384384206 1384384206 150052.3 87 173 342088.8 19173
## 9 151615.0 1386916974 1386916974 151614.2 73 145 342714.6 19145
## 10 152472.0 1338533928 1338533928 152470.5 36 71 330758.9 19071
## COUNTY ST geometry
## 1 Lee IA POLYGON ((634170.7 4519205,...
## 2 Appanoose IA POLYGON ((530372.2 4527603,...
## 3 Wayne IA POLYGON ((454680.2 4527594,...
## 4 Decatur IA POLYGON ((435312 4527874, 4...
## 5 Davis IA POLYGON ((569161.2 4526465,...
## 6 Van Buren IA POLYGON ((607982 4526969, 6...
## 7 Ringgold IA POLYGON ((377640.2 4528611,...
## 8 Taylor IA POLYGON ((339087.5 4529491,...
## 9 Page IA POLYGON ((299921.7 4530537,...
## 10 Fremont IA POLYGON ((263800.8 4531621,...
```
---
# What's in an `sf` object?
- An `sf` object is basically a data frame with a `geometry` column describing where the object is located on Earth.
```r
class(iowa.sf)
```
```
## [1] "sf" "data.frame"
```
- Since it inherits from the `data.frame` class, you can do all the things you're used to with an `sf` object
- `ggplot` has support for plotting simple features via `geom_sf`.
.footnote[For a more in-depth walkthrough of the simple feature class, refer to [`sf` vignette](https://cran.r-project.org/web/packages/sf/vignettes/sf1.html)]
---
class: middle
### Use `ggplot::geom_sf` to plot shapefiles
```r
library(tidyverse)
iowa.sf %>%
ggplot() +
geom_sf()
```
<img src="11202020_files/figure-html/unnamed-chunk-6-1.png" style="display: block; margin: auto;" />
---
### `ggplot` and `dplyr` things work with `sf` objects
```r
iowa.sf %>%
ggplot() +
geom_sf(aes(fill = ACRES))
```
<img src="11202020_files/figure-html/unnamed-chunk-7-1.png" style="display: block; margin: auto;" />
---
### `ggplot` and `dplyr` things work with `sf` objects
```r
iowa.sf %>%
* filter(COUNTY == "Lee") %>%
ggplot() +
geom_sf(aes(fill = ACRES))
```
<img src="11202020_files/figure-html/unnamed-chunk-8-1.png" style="display: block; margin: auto;" />
---
### `ggplot` and `dplyr` things work with `sf` objects
```r
iowa.sf %>%
* filter(ACRES < 340000) %>%
ggplot() +
geom_sf(aes(fill = ACRES))
```
<img src="11202020_files/figure-html/unnamed-chunk-9-1.png" style="display: block; margin: auto;" />
---
### Let's make it look nicer
```r
*theme_set(ggthemes::theme_map())
iowa.sf %>%
ggplot() +
geom_sf(aes(fill = ACRES))
```
<img src="11202020_files/figure-html/unnamed-chunk-10-1.png" style="display: block; margin: auto;" />
---
```r
iowa.sf %>%
ggplot() +
geom_sf(aes(fill = ACRES)) +
* labs(title = "Iowa Counties",
* subtitle = "Filled by area")
```
<img src="11202020_files/figure-html/unnamed-chunk-11-1.png" style="display: block; margin: auto;" />
---
```r
iowa.sf %>%
ggplot() +
geom_sf(aes(fill = ACRES)) +
labs(title = "Iowa Counties",
subtitle = "Filled by area") +
* theme(plot.title = element_text(hjust = 0.5),
* plot.subtitle = element_text(hjust = 0.5),
* legend.position = "none")
```
<img src="11202020_files/figure-html/unnamed-chunk-12-1.png" style="display: block; margin: auto;" />
---
```r
iowa.sf %>%
ggplot() +
geom_sf(aes(fill = ACRES)) +
labs(title = "Iowa Counties",
subtitle = "Filled by area",
* caption = "Source: https://geodata.iowa.gov/dataset/county-boundaries-iowa") +
theme(plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
legend.position = "none") +
* geom_sf_text(aes(label = COUNTY), size = 2.25)
```
<img src="11202020_files/figure-html/unnamed-chunk-13-1.png" style="display: block; margin: auto;" />
---
class: inverse, center, middle
# Plotting multiple `sf` objects together
---
### Let's work with another `sf` object:
```r
iowa.districts <-
st_read('data/iowa_congressional_districts')
```
```r
iowa.districts
```
.footnote[Source: http://cdmaps.polisci.ucla.edu]
---
### Let's see what the districts look like
```r
iowa.districts %>%
ggplot() +
geom_sf()
```
<img src="11202020_files/figure-html/unnamed-chunk-16-1.png" style="display: block; margin: auto;" />
---
```r
iowa.districts %>%
ggplot() +
* geom_sf(color = "red", fill = "white" ) +
* labs(title = "Iowa Congressional Districts") +
* theme(plot.title = element_text(hjust = 0.5))
```
<img src="11202020_files/figure-html/unnamed-chunk-17-1.png" style="display: block; margin: auto;" />
---
### To plot multiple `sf` objects together, call `geom_sf` again and specify the new `sf` object:
```r
*iowa.sf %>%
ggplot() +
geom_sf(fill = "white") +
labs(title = "Iowa Counties") +
theme(plot.title = element_text(hjust = 0.5)) +
geom_sf_text(aes(label = COUNTY), size = 2.25) + # inherits iowa.sf
* geom_sf(data = iowa.districts, color = "red")
```
---
### Be careful when plotting multiple `sf` objects together...
```r
iowa.sf %>%
ggplot() +
geom_sf(fill = "white") +
labs(title = "Iowa Counties") +
theme(plot.title = element_text(hjust = 0.5)) +
geom_sf_text(aes(label = COUNTY), size = 2.25) +
geom_sf(data = iowa.districts, color = "red")
```
<img src="11202020_files/figure-html/unnamed-chunk-19-1.png" style="display: block; margin: auto;" />
---
### Be careful when plotting multiple `sf` objects together...
```r
iowa.sf %>%
ggplot() +
geom_sf(fill = "white") +
labs(title = "Iowa Counties") +
theme(plot.title = element_text(hjust = 0.5)) +
geom_sf_text(aes(label = COUNTY), size = 2.25) +
* geom_sf(data = iowa.districts, color = "red", fill = NA)
```
<img src="11202020_files/figure-html/unnamed-chunk-20-1.png" style="display: block; margin: auto;" />
---
* When we read in `iowa.districts`, we got a warning message that said "automatically selected the first layer in a data source containing more than one."
* This is because the `iowa_congressional_districts` folder contains more than one set of geometry information.
* You can access these with the `layer` argument of `st_read`:
```r
iowa.house_districts <-
st_read('data/iowa_congressional_districts',
layer = "IA_House_2013")
```
<br><br>
Try plotting the other two geometries present in the `iowa_congressional_districts` folder.
---
class: inverse, center, middle
# Converting coordinates to `sf` objects
---
### We can add points by latitude and longitude, but...
```r
sampling_site_coords <-
read.csv("./data/sampling_site_coordinates.csv")
```
```r
iowa.sf %>%
ggplot() +
geom_sf(fill = "white") +
* geom_sf(data = sampling_site_coords)
```
```
## Error: stat_sf requires the following missing aesthetics: geometry
```
<img src="11202020_files/figure-html/unnamed-chunk-23-1.png" style="display: block; margin: auto;" />
---
### Use `st_as_sf` to convert lat/long coordinates to an `sf` object
```r
sampling_site_coords <- sampling_site_coords %>%
st_as_sf(coords = c("site_longitude", "site_latitude"),
crs = 4269)
head(sampling_site_coords)
```
```
## Simple feature collection with 6 features and 1 field
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -95.02906 ymin: 41.79395 xmax: -91.5359 ymax: 43.12524
## Geodetic CRS: NAD83
## site_name geometry
## 1 Backbone Beach POINT (-91.5359 42.6015)
## 2 Beed's Lake Beach POINT (-93.23654 42.77043)
## 3 Big Creek Beach POINT (-93.73185 41.79395)
## 4 Black Hawk Beach POINT (-95.02906 42.29637)
## 5 Brushy Creek Beach POINT (-93.97857 42.38858)
## 6 Clear Lake Beach POINT (-93.41469 43.12524)
```
---
.footnote[See https://epsg.io/ for more information about coordinate reference systems. In general, mapping the coordinates to the same CRS as the shape object you're using will work out fine.]
---
### Now we're ready to plot
```r
iowa.sf %>%
ggplot() +
geom_sf(fill = "white") +
labs(title = "DNR Sampling Site Locations") +
theme(plot.title = element_text(hjust = 0.5)) +
geom_sf(data = sampling_site_coords, color = "red")
```
<img src="11202020_files/figure-html/unnamed-chunk-25-1.png" style="display: block; margin: auto;" />
---
class: inverse, center, middle
# Preparing county population data
---
```r
iowa.county_pops <- read.csv('data/iowa_county_pops.csv')
head(iowa.county_pops)
```
```
## FIPS County City Year Estimate
## 1 19185 Wayne Balance of Wayne County July 01 2011 2656
## 2 1917985 Palo Alto Cylinder July 01 2017 85
## 3 1981840 Linn Walford (pt.) April 01 2010 382
## 4 1978195 Ringgold Tingley April 01 2010 184
## 5 1907750 Boone Boxholm April 01 2010 195
## 6 1934500 Shelby Harlan July 01 2014 4975
## Primary.Point
## 1 POINT (-93.3273639 40.7394702)
## 2 POINT (-94.5511492 43.089664)
## 3 POINT (-91.8305169 41.8796623)
## 4 POINT (-94.195803 40.852747)
## 5 POINT (-94.1062028 42.1736058)
## 6 POINT (-95.3268616 41.6495154)
```
.footnote[Source: https://data.iowa.gov/]
---
### Data prep
- Extract year from `Year` column
- Convert year to integer
- Rename O'Brien county to match the `iowa.sf` object.
```r
iowa.county_pops <- iowa.county_pops %>%
separate('Year',
c(NA, NA, 'Year'),
sep = ' ') %>%
mutate(County = replace(County,
County == "O'Brien", "Obrien"),
Year = as.integer(Year))
head(iowa.county_pops)
```
---
```
## FIPS County City Year Estimate
## 1 19185 Wayne Balance of Wayne County 2011 2656
## 2 1917985 Palo Alto Cylinder 2017 85
## 3 1981840 Linn Walford (pt.) 2010 382
## 4 1978195 Ringgold Tingley 2010 184
## 5 1907750 Boone Boxholm 2010 195
## 6 1934500 Shelby Harlan 2014 4975
## Primary.Point
## 1 POINT (-93.3273639 40.7394702)
## 2 POINT (-94.5511492 43.089664)
## 3 POINT (-91.8305169 41.8796623)
## 4 POINT (-94.195803 40.852747)
## 5 POINT (-94.1062028 42.1736058)
## 6 POINT (-95.3268616 41.6495154)
```
---
### Summarize year by year change
```r
iowa.county_pops.by_year <- iowa.county_pops %>%
group_by(County, Year) %>%
summarise(total_pop = sum(Estimate, na.rm = TRUE)) %>%
mutate(last_year_pop = lag(total_pop)) %>%
mutate(pct_change = (total_pop / last_year_pop - 1) * 100) %>%
ungroup() %>%
filter(Year > 2010)
```
---
Let's do a quick visualization:
```r
iowa.county_pops.by_year %>%
filter(Year > 2010,
County %in% sample(unique(County), 20)) %>%
ggplot(aes(Year, pct_change)) +
geom_point() +
geom_line() +
theme_bw() +
facet_wrap(~ County)
```
<img src="11202020_files/figure-html/unnamed-chunk-30-1.png" style="display: block; margin: auto;" />
---
class: inverse, center, middle
# Working towards an animation
---
### Let's combine our population data with the `iowa.sf` object:
```r
iowa.joined_sf <-
inner_join(iowa.sf,
iowa.county_pops.by_year,
by = c("COUNTY" = "County"))
```
**Sanity check**: How many rows does `iowa.joined_sf` have? How many should it have?
---
### Let's begin by plotting one year:
```r
iowa.joined_sf %>%
filter(Year == 2018) %>%
ggplot(aes(fill = pct_change)) +
geom_sf()
```
<img src="11202020_files/figure-html/unnamed-chunk-32-1.png" style="display: block; margin: auto;" />
---
### Let's clean this up:
```r
iowa.joined_sf %>%
filter(Year == 2018) %>%
ggplot(aes(fill = pct_change)) +
geom_sf() +
scale_fill_viridis_c(name = "% Change\nfrom prev. year") +
labs(title = "Percentage change in Iowa county populations by year",
subtitle = "Year: 2018") +
theme(plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
legend.background = element_rect(fill = NA)) +
geom_sf_text(aes(label = COUNTY), size = 2.5)
```
---
class: center, middle
<img src="11202020_files/figure-html/unnamed-chunk-34-1.png" style="display: block; margin: auto;" />
---
### Now that we have our graph mostly how we want it, let's animate it
```r
library(gganimate)
iowa.joined_sf %>%
ggplot(aes(fill = pct_change)) +
geom_sf() +
scale_fill_viridis_c(name = "% Change\nfrom prev. year") +
labs(title = "Percentage change in Iowa county populations by year",
* subtitle = "Year: { current_frame }") +
theme(plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
legend.background = element_rect(fill = NA),
legend.position = "right") +
geom_sf_text(aes(label = COUNTY), size = 2.5) +
* transition_manual(Year)
```
---
class: center, middle
```
## nframes and fps adjusted to match transition
```
<img src="11202020_files/figure-html/unnamed-chunk-36-1.gif" style="display: block; margin: auto;" />
---
class: inverse, center, middle
# Bonus: `geofacet`
---
### The `geofacet` package makes it easy to make complex maps with the US map
As an example, let's plot the change in state population over the past few years on the US map.
---
### The data:
```r
state_pops <- read.csv("data/us_state_pops.csv", check.names = FALSE) %>%
as_tibble()
state_pops_long <- state_pops %>%
pivot_longer(cols = `2010`:`2019`, names_to = "year", values_to = "pop") %>%
mutate(year = as.integer(year)) %>%
group_by(state) %>%
mutate(pct_change = (pop / lag(pop) - 1) * 100) %>%
ungroup() %>%
filter(year > 2010)
head(state_pops_long)
```
.footnote[Source: https://www.census.gov/data/datasets/time-series/demo/popest/2010s-state-total.html]
---
### A quick visualization:
```r
state_pops_long %>%
filter(state != sample(unique(state), 1)) %>% # to make faceting nicer
ggplot(aes(year, pct_change, color = state)) +
geom_point() +
geom_line() +
labs(x = "",
y = "",
title = "Yearly percent change in population by state from 2010 to 2019",
caption = "Source: U.S. Census Bureau, Population Division") +
facet_wrap(~ state, ncol = 10) +
scale_x_continuous(breaks = seq(2011, 2019, 2), expand = c(0, 0)) +
scale_y_continuous(labels = function (x) paste0(x, "%")) +
theme_bw() +
geom_hline(yintercept = 0, alpha = 0.5, linetype = "dashed") +
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5),
axis.text.x = element_blank(),
axis.ticks.x = element_blank() )
```
---
class: center, middle
<img src="11202020_files/figure-html/unnamed-chunk-39-1.png" style="display: block; margin: auto;" />
---
`geofacet::facet_geo` maps each of the plots onto the states:
```r
library(geofacet)
state_pops_long %>%
ggplot(aes(year, pct_change, color = state)) +
geom_point() +
geom_line() +
labs(x = "",
y = "",
title = "Yearly percent change in population by state") +
* facet_geo(~ state) +
scale_x_continuous(breaks = seq(2011, 2019, 2)) +
theme_minimal() +
geom_hline(yintercept = 0, alpha = 0.5, linetype = "dashed") +
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank())
```
---
class: center, middle
<img src="11202020_files/figure-html/unnamed-chunk-41-1.png" style="display: block; margin: auto;" />
---
# Thanks for your time! Have a nice day!
- Email me at pev@iastate.edu if you want to talk about coding, visualizations, Vim, or Teamfight Tactics :)
</textarea>
<style data-target="print-only">@media screen {.remark-slide-container{display:block;}.remark-slide-scaler{box-shadow:none;}}</style>
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script>var slideshow = remark.create({
"highlightStyle": "github",
"highlightLines": true,
"countIncrementalSlides": false
});
if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {
window.dispatchEvent(new Event('resize'));
});
(function(d) {
var 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);
})(document);
(function(d) {
var el = d.getElementsByClassName("remark-slides-area");
if (!el) return;
var slide, slides = slideshow.getSlides(), els = el[0].children;
for (var i = 1; i < slides.length; i++) {
slide = slides[i];
if (slide.properties.continued === "true" || slide.properties.count === "false") {
els[i - 1].className += ' has-continuation';
}
}
var s = d.createElement("style");
s.type = "text/css"; s.innerHTML = "@media print { .has-continuation { display: none; } }";
d.head.appendChild(s);
})(document);
// delete the temporary CSS (for displaying all slides initially) when the user
// starts to view slides
(function() {
var deleted = false;
slideshow.on('beforeShowSlide', function(slide) {
if (deleted) return;
var sheets = document.styleSheets, node;
for (var i = 0; i < sheets.length; i++) {
node = sheets[i].ownerNode;
if (node.dataset["target"] !== "print-only") continue;
node.parentNode.removeChild(node);
}
deleted = true;
});
})();
(function() {
"use strict"
// Replace <script> tags in slides area to make them executable
var scripts = document.querySelectorAll(
'.remark-slides-area .remark-slide-container script'
);
if (!scripts.length) return;
for (var i = 0; i < scripts.length; i++) {
var s = document.createElement('script');
var code = document.createTextNode(scripts[i].textContent);
s.appendChild(code);
var scriptAttrs = scripts[i].attributes;
for (var j = 0; j < scriptAttrs.length; j++) {
s.setAttribute(scriptAttrs[j].name, scriptAttrs[j].value);
}
scripts[i].parentElement.replaceChild(s, scripts[i]);
}
})();
(function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
links[i].target = '_blank';
}
}
})();
// adds .remark-code-has-line-highlighted class to <pre> parent elements
// of code chunks containing highlighted lines with class .remark-code-line-highlighted
(function(d) {
const hlines = d.querySelectorAll('.remark-code-line-highlighted');
const preParents = [];
const findPreParent = function(line, p = 0) {
if (p > 1) return null; // traverse up no further than grandparent
const el = line.parentElement;
return el.tagName === "PRE" ? el : findPreParent(el, ++p);
};
for (let line of hlines) {
let pre = findPreParent(line);
if (pre && !preParents.includes(pre)) preParents.push(pre);
}
preParents.forEach(p => p.classList.add("remark-code-has-line-highlighted"));
})(document);</script>
<script>
slideshow._releaseMath = function(el) {
var i, text, code, codes = el.getElementsByTagName('code');
for (i = 0; i < codes.length;) {
code = codes[i];
if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
text = code.textContent;
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
/^\$\$(.|\s)+\$\$$/.test(text) ||
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
code.outerHTML = code.innerHTML; // remove <code></code>
continue;
}
}
i++;
}
};
slideshow._releaseMath(document);
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://mathjax.rstudio.com/latest/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>