class: title-slide <br> <br> .right-panel[ # Making Maps ## Dr. Mine Dogucu ] --- ```r library(maps) usa <- map_data("usa") glimpse(usa) ``` ``` ## Rows: 7,243 ## Columns: 6 ## $ long <dbl> -101.4078, -101.3906, -101.3620, -101.3505, -101.3219, -101… ## $ lat <dbl> 29.74224, 29.74224, 29.65056, 29.63911, 29.63338, 29.64484,… ## $ group <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,… ## $ order <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, … ## $ region <chr> "main", "main", "main", "main", "main", "main", "main", "ma… ## $ subregion <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,… ``` --- .pull-left[ <br> <br> <br> ```r ggplot(data = usa, aes(x = long, y = lat)) ``` ] .pull-right[ <img src="03d-make-maps_files/figure-html/unnamed-chunk-4-1.png" style="display: block; margin: auto;" /> ] --- .pull-left[ <br> <br> <br> ```r ggplot(data = usa, aes(x = long, y = lat)) + geom_polygon() ``` ] .pull-right[ <img src="03d-make-maps_files/figure-html/unnamed-chunk-6-1.png" style="display: block; margin: auto;" /> ] --- .pull-left[ <br> <br> <br> ```r ggplot(data = usa, aes(x = long, y = lat)) + geom_polygon() + coord_fixed(1.4) ``` ] .pull-right[ <img src="03d-make-maps_files/figure-html/unnamed-chunk-8-1.png" style="display: block; margin: auto;" /> ] --- .pull-left[ <br> <br> <br> ```r ggplot(data = usa, aes(x = long, y = lat)) + geom_polygon(fill = NA, color = "steelblue") + coord_fixed(1.4) ``` ] .pull-right[ <img src="03d-make-maps_files/figure-html/unnamed-chunk-10-1.png" style="display: block; margin: auto;" /> ] --- .pull-left[ <br> <br> <br> ```r ggplot(data = usa, aes(x = long, y = lat)) + geom_polygon(fill = NA, color = "steelblue", aes(group = group)) + coord_fixed(1.4) ``` ] .pull-right[ <img src="03d-make-maps_files/figure-html/unnamed-chunk-12-1.png" style="display: block; margin: auto;" /> ] --- ```r location <- c("Northampton", "Columbus", "Sarasota","Irvine" ) long <- c(-72.6412, -82.998795, -82.538602, -117.824719) lat <- c(42.3251, 39.961178, 27.336483, 33.685908) pop <- c(28726, 892533, 57738, 282572) home <- tibble::tibble(location = location, lat = lat, long = long, pop = pop) ``` --- ```r home ``` ``` ## # A tibble: 4 x 4 ## location lat long pop ## <chr> <dbl> <dbl> <dbl> ## 1 Northampton 42.3 -72.6 28726 ## 2 Columbus 40.0 -83.0 892533 ## 3 Sarasota 27.3 -82.5 57738 ## 4 Irvine 33.7 -118. 282572 ``` --- .pull-left[ <br> <br> <br> ```r usa_map <- ggplot(data = usa, aes(x = long, y = lat)) + geom_polygon(fill = NA, color = "steelblue", aes(group = group)) + coord_fixed(1.4) ``` ] .pull-right[ ] --- .pull-left[ <br> <br> <br> ```r usa_map + geom_point(data = home, aes(x = long, y = lat, color = pop)) ``` ] .pull-right[ <img src="03d-make-maps_files/figure-html/unnamed-chunk-18-1.png" style="display: block; margin: auto;" /> ] --- .pull-left[ <br> <br> <br> ```r usa_map + geom_point(data = home, aes(x = long, y = lat, size = pop)) ``` ] .pull-right[ <img src="03d-make-maps_files/figure-html/unnamed-chunk-20-1.png" style="display: block; margin: auto;" /> ] --- .pull-left[ <br> <br> <br> ```r states <- map_data("state") ggplot(data = states, aes(x = long, y = lat, fill = region)) + geom_polygon(aes(group = group)) + coord_fixed(1.4) + guides(fill = FALSE) ``` ] .pull-right[ <img src="03d-make-maps_files/figure-html/unnamed-chunk-22-1.png" style="display: block; margin: auto;" /> ] --- `library(sf)` [Maps Chapter from ggplot2 book](https://ggplot2-book.org/maps.html)