<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> <td style="text-align:left;"> KANDY </td> <td style="text-align:right;"> 3573 </td> </tr> <tr> <td style="text-align:left;"> KURUNEGALA </td> <td style="text-align:right;"> 2040 </td> </tr> <tr> <td style="text-align:left;"> POLONNARUWA </td> <td style="text-align:right;"> 202 </td> </tr> <tr> <td style="text-align:left;"> JAFFNA </td> <td style="text-align:right;"> 229 </td> </tr> <tr> <td style="text-align:left;"> RATNAPURA </td> <td style="text-align:right;"> 1661 </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 class="table" style="font-size: 20px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;"> ADM2_EN </th> <th style="text-align:left;"> geometry </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> [unknown] </td> <td style="text-align:left;"> MULTIPOLYGON (((392952.6 59... </td> </tr> <tr> <td style="text-align:left;"> Ampara </td> <td style="text-align:left;"> MULTIPOLYGON (((551311.8 58... </td> </tr> <tr> <td style="text-align:left;"> Anuradhapura </td> <td style="text-align:left;"> MULTIPOLYGON (((501928.5 71... </td> </tr> <tr> <td style="text-align:left;"> Badulla </td> <td style="text-align:left;"> MULTIPOLYGON (((522825 5682... </td> </tr> <tr> <td style="text-align:left;"> Batticaloa </td> <td style="text-align:left;"> MULTIPOLYGON (((609877 5593... </td> </tr> <tr> <td style="text-align:left;"> Colombo </td> <td style="text-align:left;"> MULTIPOLYGON (((400911.5 49... </td> </tr> <tr> <td style="text-align:left;"> Galle </td> <td style="text-align:left;"> MULTIPOLYGON (((425038.8 40... </td> </tr> <tr> <td style="text-align:left;"> Gampaha </td> <td style="text-align:left;"> MULTIPOLYGON (((430775.7 53... </td> </tr> <tr> <td style="text-align:left;"> Hambantota </td> <td style="text-align:left;"> MULTIPOLYGON (((592923.3 45... </td> </tr> <tr> <td style="text-align:left;"> Jaffna </td> <td style="text-align:left;"> MULTIPOLYGON (((362968.6 76... </td> </tr> </tbody> </table> ] ??? A different problem to the Australia set --- # What is this unknown district? <img src="Index_files/figure-html/lagoon-1.png" width="2700" /> --- # To join the Covid data to the map -- .pull-left[ ### - Convert the district names to match ```r covid_sl <- covid_sl %>% # use District names from Covid data mutate(DISTRICT = case_when( DISTRICT == "BATTICOLOA" ~ "BATTICALOA", DISTRICT == "NUWARAELIYA" ~ "NUWARA ELIYA", DISTRICT == "MONERAGALA" ~ "MONARAGALA", DISTRICT == "MULLATIVU" ~ "MULLAITIVU", DISTRICT == "VAVUNIA" ~ "VAVUNIYA", TRUE ~ DISTRICT)) sf_sl <- sf_sl %>% mutate(DISTRICT = str_to_upper(ADM2_EN)) %>% select(-ADM2_EN) ``` ] .pull-right[ ### - Peform a join ```r covid_districts_sl <- left_join(sf_sl, covid_sl, by = c("DISTRICT")) ``` ### - Remove the "[unknown]" ```r covid_districts_sl <- covid_districts_sl %>% filter(!(DISTRICT == "[UNKNOWN]")) %>% filter(!(DISTRICT == "KALMUNAI")) %>% # adjust case numbers # city of Kalmunai in Ampara 1183+227 = 1410 mutate(Count = ifelse(DISTRICT == "AMPARA", 1410, Count)) ``` ] --- .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;"> geometry </th> <th style="text-align:left;"> DISTRICT </th> <th style="text-align:right;"> Count </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> MULTIPOLYGON (((551311.8 58... </td> <td style="text-align:left;"> AMPARA </td> <td style="text-align:right;"> 1410 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((501928.5 71... </td> <td style="text-align:left;"> ANURADHAPURA </td> <td style="text-align:right;"> 428 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((522825 5682... </td> <td style="text-align:left;"> BADULLA </td> <td style="text-align:right;"> 1060 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((609877 5593... </td> <td style="text-align:left;"> BATTICALOA </td> <td style="text-align:right;"> 426 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((400911.5 49... </td> <td style="text-align:left;"> COLOMBO </td> <td style="text-align:right;"> 26925 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((425038.8 40... </td> <td style="text-align:left;"> GALLE </td> <td style="text-align:right;"> 1852 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((430775.7 53... </td> <td style="text-align:left;"> GAMPAHA </td> <td style="text-align:right;"> 15669 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((592923.3 45... </td> <td style="text-align:left;"> HAMBANTOTA </td> <td style="text-align:right;"> 539 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((362968.6 76... </td> <td style="text-align:left;"> JAFFNA </td> <td style="text-align:right;"> 229 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((411888.2 43... </td> <td style="text-align:left;"> KALUTARA </td> <td style="text-align:right;"> 5674 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((520143.4 55... </td> <td style="text-align:left;"> KANDY </td> <td style="text-align:right;"> 3573 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((432117.3 52... </td> <td style="text-align:left;"> KEGALLE </td> <td style="text-align:right;"> 1315 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((415223 7518... </td> <td style="text-align:left;"> KILINOCHCHI </td> <td style="text-align:right;"> 80 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((425843.2 63... </td> <td style="text-align:left;"> KURUNEGALA </td> <td style="text-align:right;"> 2040 </td> </tr> <tr> <td style="text-align:left;"> MULTIPOLYGON (((405858.7 70... </td> <td style="text-align:left;"> MANNAR </td> <td style="text-align:right;"> 198 </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> <img src="Index_files/figure-html/coviddistrictsmap-1.png" width="1200" /> ] --- class: inverse, center # What should we continue to ask ourselves? -- ## How can we improve? --- 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%;" /> --- # We can use projections -- ### A projection converts the 3D globe, into to a 2D representation <img src="images/ggchoro.png" style="position:absolute;bottom:-20%;left:20%;height:100%;width:65%;" /> --- <img src="images/epsgio.png" style="position:absolute;bottom:2%;left:10;height:110%;width:80%;" /> .footnote[ [4] https://epsg.io/3857 [5] https://lyzidiamond.com/posts/4326-vs-3857 ] --- # Common Projections -- <img src="images/gg4326.png" style="position:absolute;bottom:10%;left:0%;height:50%;width:33%;" /> EPSG: 4326, World Geodetic System 1984, used in GPS -- <img src="images/gg2163.png" style="position:absolute;bottom:10%;left:33%;height:50%;width:33%;" /> EPSG: 2163, US National Atlas Equal Area, spherical projection -- <img src="images/gg8826.png" style="position:absolute;bottom:10%;right:0%;height:50%;width:33%;" /> EPSG: 8826, North American Datum 1983 --- # Choropleths - Familiar shapes of areas - Familiar boundary relationships - Identify spatial structures and patterns ### However, if we have: - sparsely populated rural areas are easy to see - densely populated inner city areas are geographically small --- class: inverse, center # What are we trying to communicate? --- class: center # What are the alternatives? <img src="images/ggcont.png" style="position:absolute;bottom:45%;left:0%;height:50%;width:50%;" /> <img src="images/ggncont.png" style="position:absolute;bottom:45%;right:0%;height:50%;width:50%;" /> <img src="images/ggdorl.png" style="position:absolute;bottom:4%;left:0%;height:55%;width:50%;" /> <img src="images/gghexmap.png" style="position:absolute;bottom:4%;right:0%;height:50%;width:50%;" /> .left[ .footnote[ [6] https://www.researchgate.net/publication/347076645_Mapping_cancer_the_potential_of_cartograms_and_alternative_map_displays ] ] ??? Our paper covers in detail and has lots of examples of world wide cancer atlases --- # Cartograms ### - augment the size, shape, or distance of geographical areas ### - sizes areas by the value of a statistic, not earth size area ### - account for the population density, reveal hidden spatial patterns ### - reducing the visual impact of large areas with small populations ??? map creators can use white lies to create useful displays by distorting the geometry and suppressing features. [26]. The distortion in an area cartogram accounts for the population density, preventing it from obscuring the spatial patterns [27]. --- 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%;" /> --- # Population ```r pop_url <- "https://www.citypopulation.de/en/srilanka/prov/admin/" pop_table <- bow(pop_url) %>% scrape() %>% html_table() %>% purrr::pluck(1) pop_data <- pop_table %>% select(DISTRICT = Name, Status, population = `PopulationEstimate2020-07-01`) %>% filter(Status == "District") %>% mutate(DISTRICT = str_to_upper(DISTRICT)) %>% mutate(DISTRICT = ifelse( DISTRICT == "MONERAGALA", "MONARAGALA", DISTRICT)) %>% mutate(population = parse_number(population)) covid_districts_sl <- left_join(covid_districts_sl, pop_data) ``` --- # Contiguous Cartogram .pull-left[ ```r *library(cartogram) cont <- cartogram_cont(covid_districts_sl, weight = "population") %>% st_as_sf() ggplot(cont) + geom_sf(aes(fill = Count), colour = NA) + scale_fill_distiller(type = "seq", palette = "RdPu", direction = 1, ) + theme_map() + guides(legend.position = "right") ``` ] .pull-right[ <img src="Index_files/figure-html/contfig-1.png" width="504" /> ] --- # Non-Contiguous Cartogram .pull-left[ ```r ncont <- cartogram_ncont(covid_districts_sl, weight = "population") %>% st_as_sf() ggplot(ncont) + geom_sf(data = covid_districts_sl) + geom_sf(aes(fill = Count), colour = NA) + scale_fill_distiller(type = "seq", palette = "RdPu", direction = 1) + theme_void() + guides(legend.position = "right") ``` ] .pull-right[ <img src="Index_files/figure-html/ncontfig-1.png" width="504" /> ] --- # Dorling Cartogram .pull-left[ ```r dorl <- cartogram_dorling(covid_districts_sl, weight = "population") %>% st_as_sf() ggplot(dorl) + geom_sf(data = covid_districts_sl) + geom_sf(aes(fill = Count), colour = NA) + scale_fill_distiller(type = "seq", palette = "RdPu", direction = 1) + theme_void() + guides(legend.position = "right") ``` ] .pull-right[ <img src="Index_files/figure-html/dorlfig-1.png" width="504" /> ] --- 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 ??? --- class: center, middle # Thank you for listening! Slides created via the R package [**xaringan**](https://github.com/yihui/xaringan). The chakra comes from [remark.js](https://remarkjs.com), [**knitr**](https://yihui.org/knitr), and [R Markdown](https://rmarkdown.rstudio.com). --- Footnotes [1] https://r-spatial.github.io/sf/index.html [2] https://covid19.gov.lk/wp-content/uploads/2021/02/sitrep-sl-en-18-02_10_21.pdf [3] https://data.humdata.org/dataset/sri-lanka-administrative-levels-0-4-boundaries [4] https://epsg.io/3857 [5] https://lyzidiamond.com/posts/4326-vs-3857 [6] https://www.researchgate.net/publication/347076645_Mapping_cancer_the_potential_of_cartograms_and_alternative_map_displays