{"found":57669,"hits":[{"document":{"authors":[{"contributor_roles":[],"family":"Shan","given":"Mridula","url":"https://orcid.org/0000-0003-4613-2669"},{"affiliation":[{"id":"https://ror.org/03m2x1q45","name":"University of Arizona"}],"contributor_roles":[],"family":"Scott","given":"Eric","url":"https://orcid.org/0000-0002-7430-7879"}],"blog":{"authors":null,"community_id":"3446712e-ab03-4bb7-8641-571dcda8d8cd","created":1787702400,"current_feed_url":null,"description":"Tracking disruptions to U.S. federal science funding, grant by grant.","doi":"https://doi.org/10.59350/grantwitness","favicon":"https://rogue-scholar.org/api/communities/3446712e-ab03-4bb7-8641-571dcda8d8cd/logo","feed_format":"application/atom+xml","feed_url":"https://grantwitness.org/updates/rogue-scholar.xml","filter":null,"generator":"Other","home_page_url":"https://grantwitness.org/updates?type=updates","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"grantwitness","status":"active","subfield":"3321","title":"Grant Witness","updated":1790553600,"use_api":null},"blog_name":"Grant Witness","blog_slug":"grantwitness","content_html":"<p>Unlike some other agencies we track, NOAA grants lack an agency-specific data source for grants.\nFor NOAA, we rely primarily on USAspending, DOGE, and crowd-sourced information to make determinations on grant status.</p>\n<h2>Data Sources</h2>\n<h4>DOGE</h4>\n<p>DOGE provides data on terminated awards, although we have found that it is incomplete or occasionally incorrect, so we generally do manual review of DOGE data or use it only in combination with other sources.</p>\n<h4>USAspending awards data</h4>\n<p>We use this source primarily for metadata including grantee information, grant assistance listing (CFDA), grant notice of funding announcement (NOFO), and total obligated and total outlaid amounts.\nWe also track changes to project end dates (i.e. project end date moved earlier, a \"cutoff\", or later, a \"reextension\"), and deobligation events (i.e. a negative amount obligated) which we use in combination as signals of disruption.</p>\n<h4>USAspending account data (File C)</h4>\n<p>File C is released roughly once a month (except that Sep/Oct are combined into one release).\nWe use this source primarily for outlay actions which we use to confirm reinstatements.</p>\n<h2>Terminations</h2>\n<p>An award is marked as terminated if it has been reported as such directly to us by a PI or via a trusted source, if it was listed by DOGE as being terminated, or if we see both a project end date cutoff and a deobligation in USAspending data.</p>\n<h2>Reinstatements</h2>\n<p>An award is labeled as reinstated if it has been reported as such directly to us by a PI, or if there is a re-extension of project end date or a positive obligation after a deobligation in USAspending awards data.\nReinstatements are confirmed by verifying that an award has received outlays since the reinstatement.</p>\n<h2>Award value</h2>\n<p>The funds obligated and spent at time of earliest disruption are calculated using the current total obligated amount minus obligations since the earliest termination date and the total outlays minus outlays since the earliest termination date, respectively.\nThe outlay and obligation events come from File C, while the current total obligated and outlaid numbers are from the more regularly updating USAspending awards data.\nAs a result, these estimates may fluctuate week-to-week.</p>","doi":"https://doi.org/10.59350/74brw-em383","guid":"https://doi.org/10.59350/74brw-em383","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1790553600,"rid":"c2qz2-pwj80","summary":"Unlike some other agencies we track, NOAA grants lack an agency-specific data source for grants. For NOAA, we rely primarily on USAspending, DOGE, and crowd-sourced information to make determinations on grant status.","tags":["Methods","National Oceanic And Atmospheric Administration"],"title":"NOAA Grant Disruption Methodology","updated_at":1790621962,"url":"https://grantwitness.org/noaa/updates/methodology","version":"v1"}},{"document":{"authors":[{"contributor_roles":[],"family":"Shan","given":"Mridula","url":"https://orcid.org/0000-0003-4613-2669"},{"affiliation":[{"id":"https://ror.org/019jywm96","name":"rOpenSci"}],"contributor_roles":[],"family":"Ross","given":"Noam","url":"https://orcid.org/0000-0002-2136-0000"}],"blog":{"authors":null,"community_id":"3446712e-ab03-4bb7-8641-571dcda8d8cd","created":1787702400,"current_feed_url":null,"description":"Tracking disruptions to U.S. federal science funding, grant by grant.","doi":"https://doi.org/10.59350/grantwitness","favicon":"https://rogue-scholar.org/api/communities/3446712e-ab03-4bb7-8641-571dcda8d8cd/logo","feed_format":"application/atom+xml","feed_url":"https://grantwitness.org/updates/rogue-scholar.xml","filter":null,"generator":"Other","home_page_url":"https://grantwitness.org/updates?type=updates","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"grantwitness","status":"active","subfield":"3321","title":"Grant Witness","updated":1790553600,"use_api":null},"blog_name":"Grant Witness","blog_slug":"grantwitness","content_html":"<p>At Grant Witness, we have been tracking the damage of funding terminations across federal agencies since March 2025. We have focused on our core research agencies (NIH and NSF) and expanded to other agencies in science and public health such as EPA and CDC. Yet scientific research, development, and application are core functions across the federal government, and we are always striving to expand our view to better understand how the current administration is upending the American science enterprise.</p>\n<p>Today we're expanding both our <a href=\"https://grantwitness.org/noaa\">termination</a> and <a href=\"https://grantwitness.org/noaa/analyses/agency-pulse-noaa-grantmaking\">grantmaking</a> trackers to include the National Oceanic and Atmospheric Administration (NOAA). NOAA is a scientific agency within the United States Department of Commerce. Its stated mission is \"to understand and predict our changing environment, from the deep sea to outer space, and to manage and conserve America's coastal marine resources.\" It includes the National Weather Service.</p>\n<p>NOAA's work has been targeted from the start of the administration. The Trump administration has engaged in <a href=\"https://www.pbs.org/newshour/politics/fired-rehired-and-fired-again-noaa-employees-are-caught-in-a-liminal-state\">staff firings</a>, <a href=\"https://www.nytimes.com/2026/08/11/climate/noaa-arctic-report-card.html\">suppression of scientific reports</a>, and proposed budget cuts of more than 25% for <a href=\"https://climate.law.columbia.edu/content/trump-proposes-17-billion-cut-noaa\">both FY 2026</a> and <a href=\"https://lofgren.house.gov/media/press-releases/ranking-member-lofgrens-opening-statement-noaa-budget-hearing\">2027</a>.</p>\n<p>Like many other agencies, NOAA terminated research and support grants <em>en masse</em> starting in April 2025 under the disastrous tenure of the \"Department of Government Efficiency\" (DOGE). Neither NOAA nor DOGE has published a reliable accounting of these terminations. Grant Witness, through <a href=\"https://grantwitness.org/noaa/updates/methodology\">reporting and data mining</a>, has identified 26 NOAA grants that have been terminated, only 4 of which have been reinstated.</p>\n<h2 id=\"cfda-programs-and-line-offices\">CFDA Programs and Line Offices</h2>\n<p>These grants span 13 government programs (CFDAs, <a class=\"quarto-xref\" href=\"https://grantwitness.org/noaa/updates/2026-08-24-NOAA-targeted-ncrs/#tbl-cfda\">Table\u00a01</a>) across 4 of the 6 line offices at NOAA (<a class=\"quarto-xref\" href=\"https://grantwitness.org/noaa/updates/2026-08-24-NOAA-targeted-ncrs/#tbl-line-office\">Table\u00a02</a>). Together, they represent a loss of $28,237,466 in funding to states, cities, nonprofits and universities. Climate research is the most affected area, but a variety of programs in coastal and marine management have been shuttered.</p>\n<div class=\"cell\">\n<div class=\"cell quarto-float quarto-figure quarto-figure-center\" id=\"tbl-cfda\">\n<figure class=\"quarto-float quarto-float-tbl\">\n<figcaption class=\"quarto-float-caption-top quarto-float-caption quarto-float-tbl\" id=\"tbl-cfda-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\nTable\u00a01: Terminated NOAA awards by assistance listing (CFDA)\n</figcaption>\n<div aria-describedby=\"tbl-cfda-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\n<div class=\"cell-output-display\">\n<table class=\"table\" style=\"margin-left: auto; margin-right: auto;\">\n<thead>\n<tr>\n<th style=\"text-align:left;\"> CFDA Program Title </th>\n<th style=\"text-align:right;\"> Disrupted Grants </th>\n<th style=\"text-align:right;\"> Amt Remaining at Disruption </th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:left;\"> Climate and Atmospheric Research </td>\n<td style=\"text-align:right;\"> 11 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $11,217,919 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Cooperative Institute Inter Agency Funded Activities </td>\n<td style=\"text-align:right;\"> 2 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $1,927,901 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Marine Sanctuary Program </td>\n<td style=\"text-align:right;\"> 2 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $235,000 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Office for Coastal Management </td>\n<td style=\"text-align:right;\"> 2 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $1,470,012 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Chesapeake Bay Studies </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $40,700 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Coastal Zone Management Administration Awards </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $179,600 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Coastal Zone Management Estuarine Research Reserves </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $8,486.71 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Cooperative Science and Education Program </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $11,600 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Habitat Conservation </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $15.51 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> National Oceanic and Atmospheric Administration Noaa Cooperative Institutes </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $2,757,930 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Noaa Mission Related Education Awards </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $364,360 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Pacific Fisheries Data Program </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $766,710 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Sea Grant Support </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $9,257,231 </td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n</figure>\n</div>\n</div>\n<div class=\"cell\">\n<div class=\"cell quarto-float quarto-figure quarto-figure-center\" id=\"tbl-line-office\">\n<figure class=\"quarto-float quarto-float-tbl\">\n<figcaption class=\"quarto-float-caption-top quarto-float-caption quarto-float-tbl\" id=\"tbl-line-office-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\nTable\u00a02: Terminated NOAA awards by line office\n</figcaption>\n<div aria-describedby=\"tbl-line-office-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\n<div class=\"cell-output-display\">\n<table class=\"table\" style=\"margin-left: auto; margin-right: auto;\">\n<thead>\n<tr>\n<th style=\"text-align:left;\"> Line Office Name </th>\n<th style=\"text-align:right;\"> Disrupted Grants </th>\n<th style=\"text-align:right;\"> Amt Remaining at Disruption </th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:left;\"> Office of Oceanic and Atmospheric Research </td>\n<td style=\"text-align:right;\"> 15 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $25,160,981 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> National Ocean Service </td>\n<td style=\"text-align:right;\"> 6 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $1,893,099 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> National Marine Fisheries Service </td>\n<td style=\"text-align:right;\"> 4 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $819,026 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Office of the Under Secretary </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $364,360 </td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n</figure>\n</div>\n</div>\n<h2 id=\"state-breakdown\">State Breakdown</h2>\n<p>As one would expect, coastal states have borne the brunt of these terminations. New York has the greatest number of disrupted NOAA grants followed by Washington, Massachusetts, and New Jersey (tied at three disrupted grants) (<a class=\"quarto-xref\" href=\"https://grantwitness.org/noaa/updates/2026-08-24-NOAA-targeted-ncrs/#tbl-state\">Table\u00a03</a>). The states with the greatest loss in funding include Washington, North Crolina, and New Jersey.</p>\n<div class=\"cell\">\n<div class=\"cell quarto-float quarto-figure quarto-figure-center\" id=\"tbl-state\">\n<figure class=\"quarto-float quarto-float-tbl\">\n<figcaption class=\"quarto-float-caption-top quarto-float-caption quarto-float-tbl quarto-uncaptioned\" id=\"tbl-state-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\nTable\u00a03\n</figcaption>\n<div aria-describedby=\"tbl-state-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\n<div class=\"cell-output-display\">\n<table class=\"table\" style=\"margin-left: auto; margin-right: auto;\">\n<thead>\n<tr>\n<th style=\"text-align:left;\"> State </th>\n<th style=\"text-align:right;\"> Disrupted Grants </th>\n<th style=\"text-align:right;\"> Remaining at Disruption </th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:left;\"> New York </td>\n<td style=\"text-align:right;\"> 4 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $787,780 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Washington </td>\n<td style=\"text-align:right;\"> 3 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $11,918,505 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> New Jersey </td>\n<td style=\"text-align:right;\"> 3 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $4,685,831 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Massachusetts </td>\n<td style=\"text-align:right;\"> 3 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $384,447 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> North Carolina </td>\n<td style=\"text-align:right;\"> 2 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $5,725,610 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Virginia </td>\n<td style=\"text-align:right;\"> 2 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $124,667 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> California </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $1,921,064 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Louisiana </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $1,126,012 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Oregon </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $766,710 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Rhode Island </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $344,000 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Wyoming </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $271,297 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Michigan </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $89,519 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Illinois </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $75,000 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Alaska </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $17,008 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Maine </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $16 </td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n</figure>\n</div>\n</div>\n<h2 id=\"new-grants-in-2025-and-2026\">New grants in 2025 and 2026</h2>\n<p>On our <a href=\"https://grantwitness.org/noaa/analyses/agency-pulse-noaa-grantmaking\">NOAA agency pulse page</a>, we are tracking the <em>new</em> awards made by the agency. Unlike many of the agencies we track, NOAA does not provide up-to-date grant listings, so we use USAspending data to track new awards, which can lag by over a month. Nonetheless, we can see NOAA is far behind in its distribution of Congressionally-appropriated funds. Unlike FY 2025, when many NOAA grants were distributed in the closing days of the Biden administration, NOAA was slow to start this year and has not made new grants since mid-August. It has distributed 61% fewer funds and 74% fewer grants than the 2021\u20132024 average. We will see if the agency can catch up in the remaining weeks of the fiscal year.</p>\n<p><a href=\"https://grantwitness.org/noaa/analyses/agency-pulse-noaa-grantmaking\"><img alt=\"Cumulative NOAA grant obligations by day of the fiscal year, FY2021 through FY2026. Every earlier year climbs steeply through August and September to finish between $1.4B and $3.3B. FY2026 (red) runs below all of them all year and stops at about $680M in mid-August.\" src=\"https://grantwitness.org/cms_media/noaa-obligations-curve-2026-09-25.png\"/></a></p>\n<p>We will continue to track the changes and disruptions at NOAA. Keep an eye on the <a href=\"https://grantwitness.org/noaa\">agency page</a>, or follow our <a href=\"https://grantwitness.org/noaa/updates/updates?type=updates\">updates</a> or <a href=\"https://buttondown.com/grantwitness\">newsletter</a>. As with all our work at Grant Witness, crowdsourced information is key to building and verifying our databases. Please continue to submit reports of grant terminations or reinstatements using <a href=\"https://airtable.com/appQRasGLMeZ4mpcl/pag4q0jeFfkL03wzU/form\">our web form</a>, and don't hesitate to <a href=\"mailto:info@grantwitness.org\">contact us</a>.</p>","doi":"https://doi.org/10.59350/zbrpd-kbv50","guid":"https://doi.org/10.59350/zbrpd-kbv50","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1790553600,"rid":"cyhts-3s181","summary":"At Grant Witness, we have been tracking the damage of funding terminations across federal agencies since March 2025. We have focused on our core research agencies (NIH and NSF) and expanded to other agencies in science and public health such as EPA and CDC.","tags":["Update","National Oceanic And Atmospheric Administration"],"title":"Grant Witness is tracking NOAA Terminations and Funding","updated_at":1790621961,"url":"https://grantwitness.org/noaa/updates/2026-08-24-NOAA-targeted-ncrs","version":"v1"}},{"document":{"authors":[{"contributor_roles":[],"family":"Jivkova","given":"Katrin"}],"blog":{"authors":null,"community_id":"1e54953c-587a-4743-89af-ebd2cb45660c","created":1789516800,"current_feed_url":null,"description":null,"doi":"https://doi.org/10.59350/pensoft","favicon":"https://rogue-scholar.org/api/communities/1e54953c-587a-4743-89af-ebd2cb45660c/logo","feed_format":"application/atom+xml","feed_url":"https://blog.pensoft.net/feed/atom/","filter":null,"generator":"WordPress","home_page_url":"https://blog.pensoft.net/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"pensoft","status":"active","subfield":"2303","title":"Pensoft Blog","updated":1790604504,"use_api":true},"blog_name":"Pensoft Blog","blog_slug":"pensoft","content_html":"<div class=\"twitter-share\"><a href=\"https://twitter.com/intent/tweet?via=Pensoft\" class=\"twitter-share-button\" data-size=\"large\">Tweet</a></div>\n\n<p>Pensoft Publishers is pleased to announce the publication of the first issue of the <a href=\"https://sti.pensoft.net/\"><em>Journal of Scientific and Technological Innovations</em></a> (STI), an international journal for cutting-edge research across the scientific and technological spectrum.&nbsp;</p>\n\n\n\n<p>The journal notably adopts Pensoft's <a href=\"https://arphahub.com/\">ARPHA</a> platform, an innovative end-to-end full-featured publishing solution that streamlines the entire publication workflow \u2013 from initial manuscript submission to indexing, distribution, hosting and archiving through one coordinated platform. To date, ARPHA provides \"a home\" to about <a href=\"https://arphahub.com/about/browse_journals/\">100 open-access journals</a> across scientific fields.</p>\n\n\n<div class=\"wp-block-essential-blocks-table-of-contents\"><div class=\"eb-parent-wrapper eb-parent-eb-toc-ua965 \"><div class=\"eb-toc-container eb-toc-ua965  eb-toc-is-not-sticky eb-toc-not-collapsible eb-toc-initially-not-collapsed eb-toc-scrollToTop style-1 list-style-none\" data-scroll-top=\"false\" data-scroll-top-icon=\"fas fa-angle-up\" data-collapsible=\"false\" data-sticky-hide-mobile=\"false\" data-sticky=\"false\" data-scroll-target=\"scroll_to_toc\" data-copy-link=\"false\" data-editor-type=\"\" data-hide-desktop=\"false\" data-hide-tab=\"false\" data-hide-mobile=\"false\" data-itemCollapsed=\"false\"><div class=\"eb-toc-header\"><div class=\"eb-toc-title\">Table of Contents</div></div><div class=\"eb-toc-wrapper \" data-headers=\"[{&quot;level&quot;:4,&quot;content&quot;:&quot;About the journal&quot;,&quot;text&quot;:&quot;About the journal&quot;,&quot;link&quot;:&quot;about-the-journal&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Editorial board&quot;,&quot;text&quot;:&quot;Editorial board&quot;,&quot;link&quot;:&quot;editorial-board&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Featured articles&quot;,&quot;text&quot;:&quot;Featured articles&quot;,&quot;link&quot;:&quot;featured-articles&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;A platform for scientific advancement&quot;,&quot;text&quot;:&quot;A platform for scientific advancement&quot;,&quot;link&quot;:&quot;a-platform-for-scientific-advancement&quot;}]\" data-visible=\"[true,true,true,true,true,true]\" data-delete-headers=\"[{&quot;label&quot;:&quot;About the journal&quot;,&quot;value&quot;:&quot;about-the-journal&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Editorial board&quot;,&quot;value&quot;:&quot;editorial-board&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Featured articles&quot;,&quot;value&quot;:&quot;featured-articles&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;A platform for scientific advancement&quot;,&quot;value&quot;:&quot;a-platform-for-scientific-advancement&quot;,&quot;isDelete&quot;:false}]\" data-smooth=\"true\" data-top-offset=\"\"><div class=\"eb-toc__list-wrap\"><ul class='eb-toc__list'><li><a href=\"#about-the-journal\">About the journal</a><li><a href=\"#editorial-board\">Editorial board</a><li><a href=\"#featured-articles\">Featured articles</a><li><a href=\"#a-platform-for-scientific-advancement\">A platform for scientific advancement</a></ul></div></div></div></div></div>\n\n\n<h4 class=\"wp-block-heading\">About the journal</h4>\n\n\n\n<p>The <em>Journal of Scientific and Technological Innovations</em> is an international, multidisciplinary academic journal supervised by <a href=\"https://huit.edu.vn/en\">Ho Chi Minh City University of Industry and Trade</a> (HUIT). The journal publishes original, peer-reviewed research contributions.</p>\n\n\n\n<p>Its editorial purview encompasses a broad range of scientific and technological domains:</p>\n\n\n\n<ul>\n<li><strong>Food Science</strong> &#8211; biotechnology, traceability, safety and quality assurance, chemistry and toxicology, packaging, nanotechnology, sensory evaluation, sustainability, health and nutrition, and product innovation</li>\n\n\n\n<li><strong>Environmental Science</strong> &#8211; catalysis and energy conversion, carbon capture and utilisation, hydrogen and biomass technologies, agricultural and environmental biotechnology, bioremediation and wastewater treatment, sustainable chemistry, and computational approaches</li>\n\n\n\n<li><strong>Chemical Engineering</strong> &#8211; green and sustainable chemistry, computational methods, analytical and synthetic chemistry, pharmaceutical chemistry, catalytic technologies, and process development</li>\n\n\n\n<li><strong>Materials Science</strong> &#8211; nanomaterials, biomaterials, ceramics and composites, electronic and optical materials, polymers, surface coatings, eco-materials, and semiconductors</li>\n</ul>\n\n\n\n<h4 class=\"wp-block-heading\">Editorial board</h4>\n\n\n\n<p>The journal is led by an international team of scholars:</p>\n\n\n\n<p><strong>Editor-in-Chief:</strong> Thi Hong Anh Le, <a href=\"https://huit.edu.vn/en\">Ho Chi Minh City University of Industry and Trade</a>, Vietnam</p>\n\n\n\n<p><strong>Deputy Editors-in-Chief:</strong> Tuyen Truong, <a href=\"https://www.rmit.edu.au/\">RMIT University</a>, Australia; Thanh-Binh Nguyen, <a href=\"https://eng.nkust.edu.tw/\">National Kaohsiung University of Science and Technology</a>, Taiwan</p>\n\n\n\n<h4 class=\"wp-block-heading\">Featured articles</h4>\n\n\n\n<p>The first issue of STI presents six contributions spanning food science, materials science, and applied food technology:</p>\n\n\n\n<p><strong>A cost-benefit analysis of small-holder floating-house fish farming in Chau Doc City, Vietnamese Mekong Delta&nbsp;</strong></p>\n\n\n\n<p>A study of 35 Mekong Delta fish farmers reveals significant disparities in farm profitability across different river reaches, with operations facing demographic vulnerabilities and heavy reliance on unpaid labour.&nbsp;</p>\n\n\n\n<p>Read more: Farzana H, Tran DD, Nguyen TD, Park E (2026) A cost-benefit analysis of small-holder floating-house fish farming in Chau Doc City, Vietnamese Mekong Delta. Journal of Scientific and Technological Innovations 1: e209236.<a href=\"https://doi.org/10.3897/sti.e209236\"> https://doi.org/10.3897/sti.e209236</a></p>\n\n\n\n<p><strong>Ultrasound-assisted pullulanase modification increases resistant starch content and alters the structure\u2013function properties of water caltrop starch&nbsp;</strong></p>\n\n\n\n<p>A combined ultrasound and enzymatic treatment increased resistant starch content in water caltrop starch from 21.72% to 28.15%, whilst enhancing its water and oil absorption capacities. The approach offers potential for developing resistant starch-enriched functional food ingredients.</p>\n\n\n\n<p>Read more: Phan VM, Ngo TMP, Do TTN, Luyen TTH, Duong TT, Tran NM, Tran CH (2026) Ultrasound-assisted pullulanase modification increases resistant starch content and alters the structure\u2013function properties of water caltrop starch. Journal of Scientific and Technological Innovations 1: e209539.<a href=\"https://doi.org/10.3897/sti.e209539\"> https://doi.org/10.3897/sti.e209539</a>&nbsp;</p>\n\n\n\n<p><strong>Effects of Melatonin/\u03b2-cyclodextrin Treatment on Physicochemical and Bioactive Attributes of Cherry Tomatoes during Storage</strong></p>\n\n\n\n<p>Melatonin complexed with \u03b2-cyclodextrin reduced cherry tomato weight loss by up to 56% during refrigerated storage and proved more effective than free melatonin in preserving colour, acidity, and polyphenol content. The complex formation provides a viable strategy for extending shelf-life in harvested produce.</p>\n\n\n\n<p>Read more: Tran THC, Dong TT, Nguyen PH,Le NH,Kuo C-H (2026) Effects of Melatonin/\u03b2-cyclodextrin Treatment on Physicochemical and Bioactive Attributes of Cherry Tomatoes during Storage. Journal of Scientific and Technological Innovations 1: e212043.<a href=\"https://doi.org/10.3897/sti.e212043\"> https://doi.org/10.3897/sti.e212043</a></p>\n\n\n\n<p><strong>Design, Functionalities, and Emerging Applications of Ti</strong><strong><sub>3</sub></strong><strong>C</strong><strong><sub>2</sub></strong><strong>T</strong><strong><sub>x</sub></strong><strong> MXene-Based Composites: A Review&nbsp;</strong></p>\n\n\n\n<p>This review synthesises current knowledge on titanium carbide-based MXenes, two-dimensional materials with exceptional conductivity and mechanical properties. MXene-based composites demonstrate applications in gas sensing, photocatalytic carbon dioxide reduction, and energy storage devices.</p>\n\n\n\n<p>Read more: Ta QTH, Pham NN, Tran QN, Lu TMT, Noh JS (2026) Design, Functionalities, and Emerging Applications of Ti<sub>3</sub>C<sub>2</sub>T<sub>x</sub> MXene-Based Composites: A Review. Journal of Scientific and Technological Innovations 1: e205045.<a href=\"https://doi.org/10.3897/sti.%D0%B5205045\"> https://doi.org/10.3897/sti.\u0435205045</a>&nbsp;</p>\n\n\n\n<p><strong>Chemical Composition, Bioactivities, and Cosmetic Applications of Coconut Oil and Its Derivatives</strong></p>\n\n\n\n<p>Recent evidence demonstrates that coconut oil, when appropriately applied, offers dermatological benefits, with antimicrobial, anti-inflammatory, and antioxidant properties. The research clarifies interactions between coconut oil and skin microflora and explains previous inconsistencies in published findings.</p>\n\n\n\n<p>Read more: Dat NM, Phong DT, Long HB, Dat NT, Thy LTM (2026) Chemical Composition, Bioactivities, and Cosmetic Applications of Coconut Oil and Its Derivatives. Journal of Scientific and Technological Innovations 1: e205088.<a href=\"https://doi.org/10.3897/sti.e205088\"> https://doi.org/10.3897/sti.e205088</a>&nbsp;</p>\n\n\n\n<p><strong>Retention of bilberry anthocyanins in wood hemicelluloses coated microcapsules under the impact of humidity and packaging conditions&nbsp;</strong></p>\n\n\n\n<p>Storage at 8% relative humidity limited bilberry anthocyanin degradation to 17-22% over 24 weeks, with wood hemicelluloses providing comparable protection to conventional gum Arabic. The findings establish moisture control as important for developing shelf-stable natural functional powders with sustainable coating materials.</p>\n\n\n\n<h4 class=\"wp-block-heading\">A platform for scientific advancement</h4>\n\n\n\n<p>The diversity of contributions in this first issue reflects STI&#8217;s multidisciplinary scope. Researchers interested in submitting manuscripts are invited to consult the journal's guidelines and submission portal.</p>\n\n\n\n<p>***</p>\n\n\n\n<p>Access the full first issue <a href=\"https://sti.pensoft.net/issue/5600/\">here</a>.</p>\n\n<div class=\"twitter-share\"><a href=\"https://twitter.com/intent/tweet?via=Pensoft\" class=\"twitter-share-button\" data-size=\"large\">Tweet</a></div>","doi":"https://doi.org/10.59350/12ke2-9s798","guid":"https://blog.pensoft.net/?p=21014","image":"https://blog.pensoft.net/wp-content/uploads/2026/09/SciComm-PR-2026-Instagram-2026-09-28T141749.018-1.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1790553600,"rid":"t1tqd-psc54","summary":"Tweet Pensoft Publishers is pleased to announce the publication of the first issue of the <em> Journal of Scientific and Technological Innovations </em> (STI), an international journal for cutting-edge research across the scientific and technological spectrum.","tags":["Academic Publishing","ARPHA Platform","Interdisciplinary Research","New Journal","Scientific Innovation"],"title":"New Journal of Scientific and Technological Innovations launches on ARPHA","updated_at":1790604910,"url":"https://blog.pensoft.net/2026/09/28/new-journal-of-scientific-and-technological-innovations-launches-on-arpha/","version":"v1"}},{"document":{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p>In these notes, I will show you how to use {ggplot} to create a waffle chart about the frequency of disease outbreaks in the world. The final output will look like this:</p>\n<p><a class=\"lightbox\" data-gallery=\"quarto-lightbox-gallery-1\" href=\"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks//waffle-pandemics.png\"><img class=\"img-fluid\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/waffle-pandemics.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:100.0%\"/></a></p>\n</section><section class=\"level2\" id=\"about-the-data\"><h2 class=\"anchored\" data-anchor-id=\"about-the-data\">About the data</h2>\n<p>The source of information is the global dataset of pandemic- and epidemic-prone disease outbreaks, whose data is freely available at the <a href=\"https://github.com/jatorresmunguia/disease_outbreak_news\" target=\"_blank\">GitHub repository</a> of the <strong>disease outbreaks project</strong>.</p>\n<p>The unit of analysis in the database is an outbreak, defined as the occurrence of at least one case of a specific disease in a country -or territory- during a particular year. Therefore, a country -or territory- cannot have more than one outbreak of the same disease in the same year, although it may experience outbreaks of different diseases within the same year. A country can only have multiple outbreaks of the same disease if they occur in different years.</p>\n<p>The dataset includes information on over 3,000 pandemic- and epidemic-prone disease outbreaks associated with more than 80 different infectious diseases, occurring globally from January 1996 to the present. The diseases are classified according to the International Classification of Diseases, 10th Revision (ICD-10), and the dataset contains information on the year, country, and disease for each outbreak.</p>\n<p>The dataset of pandemic- and epidemic-prone disease outbreaks is also part of the <a href=\"https://data.humdata.org/\">Humanitarian Data Exchange</a> coordinated by the United Nations Office for the Coordination of Humanitarian Affairs (OCHA).</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>To create the waffle chart, we will use the following R packages:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Tidy data analysis framework</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org\">readxl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read Excel files</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/\">httr</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Perform HTTP requests</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://github.com/yixuan/showtext\">showtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add custom fonts to plots</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/\">ggtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Use rich text elements in ggplot</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">waffle</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create waffle charts</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"loading-data-from-github\"><h2 class=\"anchored\" data-anchor-id=\"loading-data-from-github\">Loading data from GitHub</h2>\n<p>The dataset is stored in an Excel. We will download it from the <a href=\"https://github.com/jatorresmunguia/disease_outbreak_news/raw/refs/heads/main/Humanitarian%20Data%20Exchange/data_2_share/disease_outbreaks_HDX.xlsx\">GitHub repository</a> and load it into R:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define the GitHub raw content URL</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">link_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://github.com/jatorresmunguia/disease_outbreak_news/raw/refs/heads/main/Humanitarian%20Data%20Exchange/data_2_share/disease_outbreaks_HDX.xlsx\"</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a temporary file to store the data</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/tempfile.html\">tempfile</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fileext <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\".xlsx\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Download the data from GitHub using authentication</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">get_req</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/GET.html\">GET</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">link_data</span>,</span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/authenticate.html\">authenticate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/Sys.getenv.html\">Sys.getenv</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"GITHUB_PAT\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/write_disk.html\">write_disk</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>path <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read the Excel file into R</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org/reference/read_excel.html\">read_excel</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<section class=\"level3\" id=\"data-wrangling\"><h3 class=\"anchored\" data-anchor-id=\"data-wrangling\">Data wrangling</h3>\n<p>We will group the data by year and disease, and then filter the top 10 diseases from 1996 to 2024. We will also group the data by year and disease, and then filter the top 10 diseases from 2015 to 2024. Finally, we will create a factor variable for the top 10 diseases and the \"Other\" category:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Top 10 diseases 1996-2024</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">top_10_icd104n</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2025</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>freq <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/context.html\">n</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, .groups <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"drop\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/arrange.html\">arrange</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">freq</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/slice.html\">slice_head</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Only top-10 categories and Others</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks_year_disease_grouped</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2025</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&amp;</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&gt;</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2014</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>icd104n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/ifelse.html\">ifelse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/match.html\">%in%</a></span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">top_10_icd104n</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Other\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Group the diseases</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>freq <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/context.html\">n</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, .groups <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"drop\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Count the number of outbreaks</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/arrange.html\">arrange</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">freq</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a factor variable for the top 10 diseases and the \"Other\" category</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks_year_disease_grouped</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks_year_disease_grouped</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>icd104n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/factor.html\">factor</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span>,</span>\n<span>    levels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Acute poliomyelitis, unspecified\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Classical cholera\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"COVID-19, virus identified\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Dengue, unspecified\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Influenza due to identified zoonotic or pandemic influenza virus\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Measles\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Meningococcal meningitis\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Middle East respiratory syndrome coronavirus [MERS-CoV]\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Monkeypox\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Yellow fever, unspecified\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Other\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    labels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Acute poliomyelitis\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Cholera\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"COVID-19\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Dengue\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Influenza\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Measles\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Meningococcal meningitis\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"MERS-CoV\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Monkeypox\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Yellow fever\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Other\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section></section><section class=\"level2\" id=\"set-theme-settings-and-define-fonts-colors-and-text-to-be-used-in-the-waffle-chart\"><h2 class=\"anchored\" data-anchor-id=\"set-theme-settings-and-define-fonts-colors-and-text-to-be-used-in-the-waffle-chart\">Set theme settings and define fonts, colors, and text to be used in the waffle chart</h2>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add custom font</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/sysfonts/man/font_add_google.html\">font_add_google</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme for the waffle chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">theme_waffle_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\">function</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">{</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Base theme with custom font</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme settings</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Axis settings</span></span>\n<span>      axis.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Remove axis title</span></span>\n<span>      axis.line <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Remove axis line</span></span>\n<span>      </span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title settings</span></span>\n<span>      plot.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Position of the title</span></span>\n<span>      plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">24</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Top, right, bottom, left</span></span>\n<span>        width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Width of the title, npc == 1 corresponds to the full width of the plot</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      </span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Subtitle settings</span></span>\n<span>      plot.subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey50\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      </span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Legend settings</span></span>\n<span>      legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"top\"</span>,</span>\n<span>      legend.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.spacing.x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.2</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.spacing <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Spacing between legend keys</span></span>\n<span>      legend.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">9</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.direction <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"horizontal\"</span>,</span>\n<span>      legend.byrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span>,</span>\n<span>      </span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Caption settings</span></span>\n<span>      plot.caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_markdown.html\">element_markdown</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey70\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">8</span>,</span>\n<span>        hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span></span>\n<span>          <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.caption.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>,</span>\n<span></span>\n<span>      plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>,</span>\n<span>        fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">}</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title, subtitle, and caption for the waffle chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Pandemic- and epidemic-prone disease outbreaks in the world\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"In 2024, fewer countries reported public health events linked to COVID-19, while outbreaks of viral diseases transmitted by vectors increased\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Note:** Each square represents a country.\"</span>,</span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"&lt;br&gt;\"</span>, </span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Data:** A global dataset of pandemic- and epidemic-prone disease outbreaks (DOI: 10.1038/s41597-022-01797-2)\"</span>,</span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"&lt;br&gt;\"</span>, </span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Graphic:** Juan Torres Mungu\u00eda\"</span></span>\n<span>                        <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define the colors to be used in the waffle chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">colors</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#B66DFF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#7e0021\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#ff420e\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#579d1c\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#83caff\"</span>,</span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#0084d1\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#aecf00\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#4b1f6f\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FF86FF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#ffd320\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey80\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"create-the-waffle-chart\"><h2 class=\"anchored\" data-anchor-id=\"create-the-waffle-chart\">Create the waffle chart</h2>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks_year_disease_grouped</span>,</span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span>, values <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">freq</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/waffle/man/geom_waffle.html\">geom_waffle</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.25</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Size of the waffle squares</span></span>\n<span>    n_rows <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Number of rows in the waffle chart</span></span>\n<span>    flip <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Flip the waffle chart</span></span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Color of the border of the waffle squares</span></span>\n<span>    make_proportional <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Do not make the waffle chart proportional</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/facet_wrap.html\">facet_wrap</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Facet the waffle chart by year</span></span>\n<span>             nrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>             strip.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bottom\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Position of the facet strip</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_manual.html\">scale_fill_manual</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>values <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_discrete.html\">scale_x_discrete</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_continuous.html\">scale_y_continuous</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    labels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\">function</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>,</span>\n<span>    expand <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Expand the y-axis</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/coord_fixed.html\">coord_equal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Total number of outbreaks\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guides.html\">guides</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guide_legend.html\">guide_legend</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>nrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Number of rows in the legend</span></span>\n<span>                             <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> </span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">theme_waffle_chart</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"save-the-waffle-chart-as-an-image\"><h2 class=\"anchored\" data-anchor-id=\"save-the-waffle-chart-as-an-image\">Save the waffle chart as an image</h2>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb6\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_opts.html\">showtext_opts</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set the resolution of the image 320 dpi is for high-quality images (\"retina\")</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsave.html\">ggsave</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"waffle-pandemics.png\"</span>,</span>\n<span>  dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span>,</span>\n<span>  width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span>,</span>\n<span>  height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">7</span>,</span>\n<span>  units <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"in\"</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {A Waffle Chart of Disease Outbreaks in the World},\n  date = {2025-01-12},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"A Waffle Chart of Disease\nOutbreaks in the World.\"</span> January 12, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/\">https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/kg492-0rv24","guid":"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/","image":"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/waffle-pandemics.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1736640000,"rid":"28aw9-1vm92","summary":"Overview In these notes, I will show you how to use {ggplot} to create a waffle chart about the frequency of disease outbreaks in the world.","tags":["Data Visualization","Disease Outbreaks","Epidemics","Pandemics","Tidyverse"],"title":"A waffle chart of disease outbreaks in the world","updated_at":1790603826,"url":"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/","version":"v1"}},{"document":{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p>In this article, I will guide you through the process of analyzing Mexico's 2024 National Survey of Victimization and Perception of Public Safety (<em>Encuesta Nacional de Victimizaci\u00f3n y Percepci\u00f3n sobre Seguridad P\u00fablica</em>, ENVIPE) using the <a href=\"https://www.tidyverse.org/\">{tidyverse}</a> framework for survey analysis with the {srvyr} package. Specifically, we will calculate the <strong>crime prevalence rate per 100,000 inhabitants by state, according to the victim's sex</strong> ( <em>Tasa de prevalencia delictiva por entidad federativa por cada cien mil habitantes, seg\u00fan sexo de la v\u00edctima</em>).</p>\n<p>Official tables with this indicator can be found <a href=\"https://www.inegi.org.mx/programas/envipe/2024/#tabulados\">here</a>.</p>\n<p>By the end of this article, you will be able to use the {tidyverse} to:</p>\n<ul>\n<li>Load the survey microdata from INEGI's website.</li>\n<li>Specify the ENVIPE survey design.</li>\n<li>Calculate crime prevalence indicators.</li>\n</ul></section><section class=\"level2\" id=\"about-the-envipe\"><h2 class=\"anchored\" data-anchor-id=\"about-the-envipe\">About the ENVIPE</h2>\n<p>ENVIPE is an official survey that provides nationally and state-representative information on household crime victimization and perceptions of public safety in Mexico. Conducted annually since 2011 by the <a href=\"https://www.inegi.org.mx/default.html\">National Institute of Statistics and Geography (INEGI)</a>, ENVIPE collects data on the following crimes:</p>\n<div class=\"columns\">\n<div class=\"column\" style=\"width:50%;\">\n<ul>\n<li>Total vehicle theft (car, pickup truck, or truck).</li>\n<li>Theft of vehicle accessories, spare parts, or tools (car, pickup truck, or truck).</li>\n<li>Wall graffiti, intentional vehicle damage, and other types of vandalism.</li>\n<li>Burglary or attempted burglary.</li>\n<li>Kidnapping.</li>\n<li>Enforced disappearance.</li>\n<li>Homicide.</li>\n<li>Robbery or assault on the street or public transportation.</li>\n</ul>\n</div><div class=\"column\" style=\"width:50%;\">\n<ul>\n<li>Theft in a manner different from the above.</li>\n<li>Bank fraud.</li>\n<li>Consumer fraud.</li>\n<li>Extortion.</li>\n<li>Threats.</li>\n<li>Injuries.</li>\n<li>Kidnapping.</li>\n<li>Harassment or intimidation.</li>\n<li>Groping.</li>\n<li>Exhibitionism.</li>\n<li>Attempted rape.</li>\n<li>Sexual rape.</li>\n<li>Other crimes.</li>\n</ul>\n</div>\n</div>\n<p>All survey-related information, including questionnaires, methodology, glossaries, summaries, and microdata, is fully available at <a href=\"https://en.www.inegi.org.mx/programas/envipe/2024/\">INEGI's website</a>.</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>First, install and load the required packages:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Tidy data analysis framework</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://gdfe.co/srvyr/\">srvyr</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Tidy syntax for survey data analysis</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://archive.r-lib.org/\">archive</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Extract files from a ZIP archive</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://haozhu233.github.io/kableExtra/\">kableExtra</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create HTML table</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"loading-survey-microdata-from-inegi\"><h2 class=\"anchored\" data-anchor-id=\"loading-survey-microdata-from-inegi\">Loading survey microdata from INEGI</h2>\n<p>Microdata is available <a href=\"https://www.inegi.org.mx/programas/envipe/2024/#microdatos\">here</a> in various formats (CSV, DBF, DTA, SAV, and RData). In this post, we will use the RData files.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/load.html\">load</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://archive.r-lib.org/reference/archive_read.html\">archive_read</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  archive <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://www.inegi.org.mx/contenidos/programas/envipe/2024/microdatos/bd_envipe_2024_RData.zip\"</span>,</span>\n<span>  file <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"BD_ENVIPE_2024.RData\"</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<div class=\"callout callout-style-default callout-tip callout-titled\">\n<div class=\"callout-header d-flex align-content-center\">\n<div class=\"callout-icon-container\">\n<i class=\"callout-icon\"></i>\n</div>\n<div class=\"callout-title-container flex-fill\">\nTip\n</div>\n</div>\n<div class=\"callout-body-container callout-body\">\n<p>Using the {archive} package, we can directly extract the required file from <code>bd_envipe_2024_RData.zip</code>.</p>\n</div>\n</div>\n<p>This loads the following objects into the global environment:</p>\n<ul>\n<li><p><code>THogar</code>: This object contains the interview result, the row of the selected respondent, the household factor, and other household characteristics.</p></li>\n<li><p><code>TMod_Vic</code>: This object includes information on the crimes suffered by the selected respondent and their household during the reference year, specifically during 2023. Information comes from the victimization module of the survey.</p></li>\n<li><p><code>TPer_Vic1</code>: This object includes information related to the perception of public security within the respondent's geographic area, antisocial behaviors in their immediate surroundings, and changes in habits due to fear of becoming a crime victim in 2023. Additionally, it presents information regarding the performance of authorities and trust in them. In other words, this table covers Sections IV and V of the main questionnaire.</p></li>\n<li><p><code>TPer_Vic2</code>: This object consolidates information related to household and personal victimization, particularly focusing on high-impact crimes experienced by the household (such as kidnapping, enforced disappearance, or homicide) or by the selected respondent. This table includes Sections VI and VII of the main questionnaire.</p></li>\n<li><p><code>TSDem</code>: This object contains the socio-demographic characteristics of household members, corresponding to Section III of the main questionnaire.</p></li>\n<li><p><code>TSVivienda</code>: This object contains the characteristics of the households captured through the questionnaire cover page, as well as the count of household residents and the number of households. In other words, it includes Sections I and II of the main questionnaire.</p></li>\n</ul></section><section class=\"level2\" id=\"calculating-crime-prevalence-rate-per-100000-thousand-inhabitants-by-state-according-to-the-victims-sex\"><h2 class=\"anchored\" data-anchor-id=\"calculating-crime-prevalence-rate-per-100000-thousand-inhabitants-by-state-according-to-the-victims-sex\">Calculating crime prevalence rate per 100,000 thousand inhabitants by state, according to the victim's sex</h2>\n<p>To estimate the crime prevalence rate, we use information from <code>TPer_Vic2</code> (screening questions on victimization from the main questionnaire) and <code>TMod_Vic</code> (specific victimization module applied to the respondents who reported being a victim of at least one of the crimes included in the survey during the reference period). <code>TPer_Vic2</code> will serve to characterize the total population and <code>TMod_Vic</code> to describe the victims and the associated crimes.</p>\n<section class=\"level3\" id=\"specifying-the-envipe-survey-design\"><h3 class=\"anchored\" data-anchor-id=\"specifying-the-envipe-survey-design\">1. Specifying the ENVIPE survey design</h3>\n<p>ENVIPE follows a probabilistic, three-stage, stratified, and clustered sampling design. The sampling unit is the household, while the unit of analysis is the population aged 18 and older in selected households. More details on the sampling design can be found <a href=\"https://www.inegi.org.mx/contenidos/productos/prod_serv/contenidos/espanol/bvinegi/productos/nueva_estruc/889463920014.pdf\">here</a>(in Spanish).</p>\n<p>From the documentation on <a href=\"https://www.inegi.org.mx/contenidos/programas/envipe/2024/doc/fd_envipe2024.pdf\">data structure</a>(in Spanish), the key variables for specifying the survey design are:</p>\n<ul>\n<li><p><code>ID_PER</code>: Person identifier</p></li>\n<li><p><code>EST_DIS</code>: Stratum</p></li>\n<li><p><code>UPM_DIS</code>: Primary sampling unit</p></li>\n<li><p><code>FAC_ELE</code>: Weighting factor for public security perception and victimization estimates.</p></li>\n</ul>\n<p>We specify the survey design as follows:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Identify victims from TMod_Vic, excluding</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># \"Wall graffiti, intentional vehicle damage, and other vandalism\" (BPCOD != \"03\")</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">id_victims</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TMod_Vic</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">BPCOD</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">!=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"03\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/pull.html\">pull</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ID_PER</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create victimization variable in TPer_Vic2</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>victimization <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/ifelse.html\">ifelse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ID_PER</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/match.html\">%in%</a></span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">id_victims</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Convert FAC_ELE (weights) to numeric</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>FAC_ELE <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/numeric.html\">as.numeric</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">FAC_ELE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Label SEXO variable</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>SEXO <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/recode.html\">recode</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">SEXO</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"1\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Man\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"2\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Woman\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create survey object</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">envipe_design</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://gdfe.co/srvyr/reference/as_survey_design.html\">as_survey_design</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    weights <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">FAC_ELE</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Weights (inverse probability)</span></span>\n<span>    strata <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">EST_DIS</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Stratum</span></span>\n<span>    ids <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">UPM_DIS</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Primary sampling unit</span></span>\n<span>    nest <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Nesting within strata</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level3\" id=\"calculating-point-estimates-and-variablity-indicators\"><h3 class=\"anchored\" data-anchor-id=\"calculating-point-estimates-and-variablity-indicators\">2. Calculating point estimates and variablity indicators</h3>\n<p>To compute proportions from survey data, we use <code><a href=\"http://gdfe.co/srvyr/reference/survey_mean.html\">survey_mean()</a></code> from {srvyr} package. From ENVIPE's documentation, we know that <code>NOM_ENT</code> represents the state, while <code>SEXO</code> corresponds to the respondent's sex.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">envipe_design</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># `interact` function is used to calculate the proportion</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># over the interaction of state and sex</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://gdfe.co/srvyr/reference/interact.html\">interact</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">NOM_ENT</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">SEXO</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarize</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    Proportion <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://gdfe.co/srvyr/reference/survey_mean.html\">survey_mean</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">victimization</span>,</span>\n<span>      level <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.90</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Confidence level</span></span>\n<span>      vartype <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"se\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"ci\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cv\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Variability indicators</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">ungroup</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    `Prevalence rate` <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Proportion</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">100000</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rate per 100,000 people</span></span>\n<span>    `Standard error` <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Proportion_se</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">100000</span>,</span>\n<span>    `Low 90% CI` <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Proportion_low</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">100000</span>,</span>\n<span>    `Upper 90% CI` <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Proportion_upp</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">100000</span>,</span>\n<span>    `Coefficient of variation %` <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Proportion_cv</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">100</span>,</span>\n<span>    State <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/case.html\">str_to_sentence</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">NOM_ENT</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Capitalize only the first letter</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>Sex <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">SEXO</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">State</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Sex</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Prevalence rate`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Standard error`</span>,</span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Low 90% CI`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Upper 90% CI`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Coefficient of variation %`</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/kableExtra/man/kbl.html\">kbl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># HTML table</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/kableExtra/man/kable_styling.html\">kable_styling</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Apply bootstrap theme to the table</span></span></code></pre></div></div>\n</div>\n<p>The output table looks like this:</p>\n<div class=\"cell\">\n<div class=\"cell-output-display\">\n<table class=\"table caption-top table-sm table-striped small\">\n<thead><tr class=\"header\">\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: left;\">State</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: left;\">Sex</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Prevalence rate</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Standard error</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Low 90% CI</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Upper 90% CI</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Coefficient of variation %</th>\n</tr></thead>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Aguascalientes</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">33710.81</td>\n<td style=\"text-align: right;\">2172.7372</td>\n<td style=\"text-align: right;\">30136.71</td>\n<td style=\"text-align: right;\">37284.91</td>\n<td style=\"text-align: right;\">6.445224</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Aguascalientes</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">32041.57</td>\n<td style=\"text-align: right;\">1831.7081</td>\n<td style=\"text-align: right;\">29028.45</td>\n<td style=\"text-align: right;\">35054.68</td>\n<td style=\"text-align: right;\">5.716662</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Baja California</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">23043.35</td>\n<td style=\"text-align: right;\">1604.9769</td>\n<td style=\"text-align: right;\">20403.20</td>\n<td style=\"text-align: right;\">25683.50</td>\n<td style=\"text-align: right;\">6.965032</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Baja California</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">24480.64</td>\n<td style=\"text-align: right;\">1536.1771</td>\n<td style=\"text-align: right;\">21953.66</td>\n<td style=\"text-align: right;\">27007.61</td>\n<td style=\"text-align: right;\">6.275070</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Baja California Sur</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">19329.94</td>\n<td style=\"text-align: right;\">1244.1353</td>\n<td style=\"text-align: right;\">17283.36</td>\n<td style=\"text-align: right;\">21376.51</td>\n<td style=\"text-align: right;\">6.436314</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Baja California Sur</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">23817.58</td>\n<td style=\"text-align: right;\">1466.2963</td>\n<td style=\"text-align: right;\">21405.56</td>\n<td style=\"text-align: right;\">26229.60</td>\n<td style=\"text-align: right;\">6.156361</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Campeche</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">21832.87</td>\n<td style=\"text-align: right;\">1455.8508</td>\n<td style=\"text-align: right;\">19438.03</td>\n<td style=\"text-align: right;\">24227.71</td>\n<td style=\"text-align: right;\">6.668161</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Campeche</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">23213.74</td>\n<td style=\"text-align: right;\">1381.0933</td>\n<td style=\"text-align: right;\">20941.88</td>\n<td style=\"text-align: right;\">25485.61</td>\n<td style=\"text-align: right;\">5.949465</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Chiapas</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">16602.99</td>\n<td style=\"text-align: right;\">986.0052</td>\n<td style=\"text-align: right;\">14981.03</td>\n<td style=\"text-align: right;\">18224.94</td>\n<td style=\"text-align: right;\">5.938722</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Chiapas</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">12074.36</td>\n<td style=\"text-align: right;\">978.7862</td>\n<td style=\"text-align: right;\">10464.28</td>\n<td style=\"text-align: right;\">13684.44</td>\n<td style=\"text-align: right;\">8.106318</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Chihuahua</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">22303.22</td>\n<td style=\"text-align: right;\">1234.5065</td>\n<td style=\"text-align: right;\">20272.49</td>\n<td style=\"text-align: right;\">24333.96</td>\n<td style=\"text-align: right;\">5.535103</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Chihuahua</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">22804.31</td>\n<td style=\"text-align: right;\">1181.0327</td>\n<td style=\"text-align: right;\">20861.54</td>\n<td style=\"text-align: right;\">24747.08</td>\n<td style=\"text-align: right;\">5.178990</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Ciudad De Mexico</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">34562.66</td>\n<td style=\"text-align: right;\">1089.2714</td>\n<td style=\"text-align: right;\">32770.84</td>\n<td style=\"text-align: right;\">36354.49</td>\n<td style=\"text-align: right;\">3.151584</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Ciudad De Mexico</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">30746.76</td>\n<td style=\"text-align: right;\">990.3528</td>\n<td style=\"text-align: right;\">29117.66</td>\n<td style=\"text-align: right;\">32375.87</td>\n<td style=\"text-align: right;\">3.220999</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Coahuila De Zaragoza</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">18179.70</td>\n<td style=\"text-align: right;\">1249.1422</td>\n<td style=\"text-align: right;\">16124.89</td>\n<td style=\"text-align: right;\">20234.51</td>\n<td style=\"text-align: right;\">6.871084</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Coahuila De Zaragoza</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">20447.19</td>\n<td style=\"text-align: right;\">1238.7111</td>\n<td style=\"text-align: right;\">18409.54</td>\n<td style=\"text-align: right;\">22484.84</td>\n<td style=\"text-align: right;\">6.058099</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Colima</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">21106.85</td>\n<td style=\"text-align: right;\">1593.5970</td>\n<td style=\"text-align: right;\">18485.43</td>\n<td style=\"text-align: right;\">23728.28</td>\n<td style=\"text-align: right;\">7.550140</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Colima</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">21295.28</td>\n<td style=\"text-align: right;\">1351.1455</td>\n<td style=\"text-align: right;\">19072.68</td>\n<td style=\"text-align: right;\">23517.88</td>\n<td style=\"text-align: right;\">6.344813</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Durango</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">15240.74</td>\n<td style=\"text-align: right;\">1133.1868</td>\n<td style=\"text-align: right;\">13376.67</td>\n<td style=\"text-align: right;\">17104.80</td>\n<td style=\"text-align: right;\">7.435250</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Durango</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">17401.18</td>\n<td style=\"text-align: right;\">1166.0910</td>\n<td style=\"text-align: right;\">15482.99</td>\n<td style=\"text-align: right;\">19319.37</td>\n<td style=\"text-align: right;\">6.701219</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Guanajuato</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">20057.38</td>\n<td style=\"text-align: right;\">1428.0981</td>\n<td style=\"text-align: right;\">17708.20</td>\n<td style=\"text-align: right;\">22406.57</td>\n<td style=\"text-align: right;\">7.120063</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Guanajuato</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">18930.15</td>\n<td style=\"text-align: right;\">1287.0811</td>\n<td style=\"text-align: right;\">16812.93</td>\n<td style=\"text-align: right;\">21047.37</td>\n<td style=\"text-align: right;\">6.799107</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Guerrero</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">16981.89</td>\n<td style=\"text-align: right;\">1494.6554</td>\n<td style=\"text-align: right;\">14523.22</td>\n<td style=\"text-align: right;\">19440.56</td>\n<td style=\"text-align: right;\">8.801466</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Guerrero</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">14572.44</td>\n<td style=\"text-align: right;\">1238.6234</td>\n<td style=\"text-align: right;\">12534.93</td>\n<td style=\"text-align: right;\">16609.94</td>\n<td style=\"text-align: right;\">8.499769</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Hidalgo</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">22397.82</td>\n<td style=\"text-align: right;\">1338.0474</td>\n<td style=\"text-align: right;\">20196.77</td>\n<td style=\"text-align: right;\">24598.88</td>\n<td style=\"text-align: right;\">5.974006</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Hidalgo</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">20215.02</td>\n<td style=\"text-align: right;\">1157.0294</td>\n<td style=\"text-align: right;\">18311.73</td>\n<td style=\"text-align: right;\">22118.30</td>\n<td style=\"text-align: right;\">5.723613</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Jalisco</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">24390.13</td>\n<td style=\"text-align: right;\">1548.7916</td>\n<td style=\"text-align: right;\">21842.40</td>\n<td style=\"text-align: right;\">26937.85</td>\n<td style=\"text-align: right;\">6.350076</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Jalisco</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">25141.90</td>\n<td style=\"text-align: right;\">1438.5170</td>\n<td style=\"text-align: right;\">22775.58</td>\n<td style=\"text-align: right;\">27508.23</td>\n<td style=\"text-align: right;\">5.721592</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Mexico</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">32906.59</td>\n<td style=\"text-align: right;\">1632.3183</td>\n<td style=\"text-align: right;\">30221.47</td>\n<td style=\"text-align: right;\">35591.71</td>\n<td style=\"text-align: right;\">4.960460</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Mexico</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">33023.78</td>\n<td style=\"text-align: right;\">1483.3471</td>\n<td style=\"text-align: right;\">30583.71</td>\n<td style=\"text-align: right;\">35463.85</td>\n<td style=\"text-align: right;\">4.491755</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Michoacan De Ocampo</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">14405.17</td>\n<td style=\"text-align: right;\">1031.1125</td>\n<td style=\"text-align: right;\">12709.01</td>\n<td style=\"text-align: right;\">16101.32</td>\n<td style=\"text-align: right;\">7.157934</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Michoacan De Ocampo</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">15485.20</td>\n<td style=\"text-align: right;\">1036.3320</td>\n<td style=\"text-align: right;\">13780.46</td>\n<td style=\"text-align: right;\">17189.94</td>\n<td style=\"text-align: right;\">6.692401</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Morelos</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">26995.43</td>\n<td style=\"text-align: right;\">1517.6054</td>\n<td style=\"text-align: right;\">24499.00</td>\n<td style=\"text-align: right;\">29491.85</td>\n<td style=\"text-align: right;\">5.621713</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Morelos</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">24869.74</td>\n<td style=\"text-align: right;\">1688.5969</td>\n<td style=\"text-align: right;\">22092.04</td>\n<td style=\"text-align: right;\">27647.44</td>\n<td style=\"text-align: right;\">6.789765</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Nayarit</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">16075.56</td>\n<td style=\"text-align: right;\">1516.6195</td>\n<td style=\"text-align: right;\">13580.76</td>\n<td style=\"text-align: right;\">18570.36</td>\n<td style=\"text-align: right;\">9.434318</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Nayarit</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">18639.61</td>\n<td style=\"text-align: right;\">1597.1842</td>\n<td style=\"text-align: right;\">16012.28</td>\n<td style=\"text-align: right;\">21266.94</td>\n<td style=\"text-align: right;\">8.568766</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Nuevo Leon</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">23602.12</td>\n<td style=\"text-align: right;\">1261.9498</td>\n<td style=\"text-align: right;\">21526.25</td>\n<td style=\"text-align: right;\">25678.00</td>\n<td style=\"text-align: right;\">5.346764</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Nuevo Leon</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">21440.72</td>\n<td style=\"text-align: right;\">1211.6372</td>\n<td style=\"text-align: right;\">19447.60</td>\n<td style=\"text-align: right;\">23433.83</td>\n<td style=\"text-align: right;\">5.651104</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Oaxaca</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">12940.56</td>\n<td style=\"text-align: right;\">1158.2366</td>\n<td style=\"text-align: right;\">11035.29</td>\n<td style=\"text-align: right;\">14845.83</td>\n<td style=\"text-align: right;\">8.950434</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Oaxaca</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">13548.61</td>\n<td style=\"text-align: right;\">1017.7020</td>\n<td style=\"text-align: right;\">11874.51</td>\n<td style=\"text-align: right;\">15222.70</td>\n<td style=\"text-align: right;\">7.511489</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Puebla</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">26519.64</td>\n<td style=\"text-align: right;\">1342.0473</td>\n<td style=\"text-align: right;\">24312.00</td>\n<td style=\"text-align: right;\">28727.27</td>\n<td style=\"text-align: right;\">5.060579</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Puebla</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">24176.45</td>\n<td style=\"text-align: right;\">1124.4656</td>\n<td style=\"text-align: right;\">22326.73</td>\n<td style=\"text-align: right;\">26026.17</td>\n<td style=\"text-align: right;\">4.651078</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Queretaro</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">30297.50</td>\n<td style=\"text-align: right;\">1620.6534</td>\n<td style=\"text-align: right;\">27631.57</td>\n<td style=\"text-align: right;\">32963.44</td>\n<td style=\"text-align: right;\">5.349132</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Queretaro</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">25746.31</td>\n<td style=\"text-align: right;\">1260.3524</td>\n<td style=\"text-align: right;\">23673.06</td>\n<td style=\"text-align: right;\">27819.56</td>\n<td style=\"text-align: right;\">4.895273</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Quintana Roo</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">22592.04</td>\n<td style=\"text-align: right;\">1384.4250</td>\n<td style=\"text-align: right;\">20314.70</td>\n<td style=\"text-align: right;\">24869.39</td>\n<td style=\"text-align: right;\">6.127932</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Quintana Roo</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">21775.64</td>\n<td style=\"text-align: right;\">1237.8095</td>\n<td style=\"text-align: right;\">19739.48</td>\n<td style=\"text-align: right;\">23811.81</td>\n<td style=\"text-align: right;\">5.684376</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">San Luis Potosi</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">24019.02</td>\n<td style=\"text-align: right;\">1874.7438</td>\n<td style=\"text-align: right;\">20935.11</td>\n<td style=\"text-align: right;\">27102.93</td>\n<td style=\"text-align: right;\">7.805247</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">San Luis Potosi</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">23227.97</td>\n<td style=\"text-align: right;\">1491.3111</td>\n<td style=\"text-align: right;\">20774.80</td>\n<td style=\"text-align: right;\">25681.14</td>\n<td style=\"text-align: right;\">6.420324</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Sinaloa</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">21181.44</td>\n<td style=\"text-align: right;\">1122.0160</td>\n<td style=\"text-align: right;\">19335.76</td>\n<td style=\"text-align: right;\">23027.13</td>\n<td style=\"text-align: right;\">5.297165</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Sinaloa</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">20562.22</td>\n<td style=\"text-align: right;\">1086.2790</td>\n<td style=\"text-align: right;\">18775.32</td>\n<td style=\"text-align: right;\">22349.12</td>\n<td style=\"text-align: right;\">5.282887</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Sonora</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">26864.66</td>\n<td style=\"text-align: right;\">1816.2677</td>\n<td style=\"text-align: right;\">23876.94</td>\n<td style=\"text-align: right;\">29852.37</td>\n<td style=\"text-align: right;\">6.760808</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Sonora</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">25742.16</td>\n<td style=\"text-align: right;\">1902.0264</td>\n<td style=\"text-align: right;\">22613.37</td>\n<td style=\"text-align: right;\">28870.95</td>\n<td style=\"text-align: right;\">7.388759</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Tabasco</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">25881.72</td>\n<td style=\"text-align: right;\">1354.6212</td>\n<td style=\"text-align: right;\">23653.40</td>\n<td style=\"text-align: right;\">28110.04</td>\n<td style=\"text-align: right;\">5.233891</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Tabasco</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">25522.45</td>\n<td style=\"text-align: right;\">1091.8488</td>\n<td style=\"text-align: right;\">23726.38</td>\n<td style=\"text-align: right;\">27318.51</td>\n<td style=\"text-align: right;\">4.277994</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Tamaulipas</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">17788.15</td>\n<td style=\"text-align: right;\">1075.8038</td>\n<td style=\"text-align: right;\">16018.47</td>\n<td style=\"text-align: right;\">19557.82</td>\n<td style=\"text-align: right;\">6.047869</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Tamaulipas</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">18368.67</td>\n<td style=\"text-align: right;\">1017.1639</td>\n<td style=\"text-align: right;\">16695.46</td>\n<td style=\"text-align: right;\">20041.88</td>\n<td style=\"text-align: right;\">5.537493</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Tlaxcala</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">23968.33</td>\n<td style=\"text-align: right;\">1621.2198</td>\n<td style=\"text-align: right;\">21301.47</td>\n<td style=\"text-align: right;\">26635.20</td>\n<td style=\"text-align: right;\">6.764007</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Tlaxcala</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">22295.82</td>\n<td style=\"text-align: right;\">1473.2391</td>\n<td style=\"text-align: right;\">19872.38</td>\n<td style=\"text-align: right;\">24719.26</td>\n<td style=\"text-align: right;\">6.607692</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Veracruz De Ignacio De La Llave</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">16365.05</td>\n<td style=\"text-align: right;\">1055.8247</td>\n<td style=\"text-align: right;\">14628.24</td>\n<td style=\"text-align: right;\">18101.86</td>\n<td style=\"text-align: right;\">6.451705</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Veracruz De Ignacio De La Llave</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">14712.45</td>\n<td style=\"text-align: right;\">947.9121</td>\n<td style=\"text-align: right;\">13153.15</td>\n<td style=\"text-align: right;\">16271.74</td>\n<td style=\"text-align: right;\">6.442927</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Yucatan</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">20677.82</td>\n<td style=\"text-align: right;\">1239.0909</td>\n<td style=\"text-align: right;\">18639.55</td>\n<td style=\"text-align: right;\">22716.10</td>\n<td style=\"text-align: right;\">5.992366</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Yucatan</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">17805.62</td>\n<td style=\"text-align: right;\">1141.8291</td>\n<td style=\"text-align: right;\">15927.34</td>\n<td style=\"text-align: right;\">19683.90</td>\n<td style=\"text-align: right;\">6.412745</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Zacatecas</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">17328.49</td>\n<td style=\"text-align: right;\">1346.8466</td>\n<td style=\"text-align: right;\">15112.96</td>\n<td style=\"text-align: right;\">19544.02</td>\n<td style=\"text-align: right;\">7.772440</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Zacatecas</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">15690.25</td>\n<td style=\"text-align: right;\">1335.9463</td>\n<td style=\"text-align: right;\">13492.65</td>\n<td style=\"text-align: right;\">17887.85</td>\n<td style=\"text-align: right;\">8.514502</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n</section></section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {Using a Tidy Approach in {R} to Analyze {Mexico's} 2024\n    {ENVIPE}},\n  date = {2025-01-27},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"Using a Tidy Approach in R to\nAnalyze Mexico's 2024 ENVIPE.\"</span> January 27, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/\">https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/a1rrg-n4y36","guid":"https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/","image":"https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/table_envipe.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1737936000,"rid":"e08zs-w2m07","summary":"Overview In this article, I will guide you through the process of analyzing Mexico's 2024 National Survey of Victimization and Perception of Public Safety ( <em> Encuesta Nacional de Victimizaci\u00f3n y Percepci\u00f3n sobre Seguridad P\u00fablica </em> , ENVIPE) using the {tidyverse} framework for survey analysis with the {srvyr} package.","tags":["Data Analysis","Official Statistics","Mexico","Household Surveys","ENVIPE"],"title":"Using a tidy approach in R to analyze Mexico's 2024 ENVIPE","updated_at":1790603821,"url":"https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/","version":"v1"}},{"document":{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p>The Standardized Precipitation Index (SPI) quantifies how precipitation deviates from the historical average over multiple time scales (e.g., from 1 to 12 months), allowing for consistent monitoring of droughts and floods across regions and time, making it a valuable tool for early warning and risk assessment systems.</p>\n<p>In this tutorial, I will walk through the process of calculating the SPI for Somalia at the subnational level using the {SCI} package in R.</p>\n</section><section class=\"level2\" id=\"about-the-data\"><h2 class=\"anchored\" data-anchor-id=\"about-the-data\">About the data</h2>\n<p>The rainfall dataset used in this tutorial comes from the <a href=\"https://data.humdata.org/\">Humanitarian Data Exchange (HDX) initiative</a> of the United Nations Office for the Coordination of Humanitarian Affairs (OCHA) and provides monthly precipitation data for Somalia's subnational districts. It is derived from CHIRPS v2 (Climate Hazards Group InfraRed Precipitation with <em>in situ</em> Station data), using satellite imagery combined with ground-based observations.</p>\n<p>For each 10-day period (dekad), the dataset includes the following indicators:</p>\n<ul>\n<li>\n<code>rfh</code>: Total rainfall (mm) over 10 days</li>\n<li>\n<code>r1h</code>: 1-month rolling rainfall sum (mm)</li>\n<li>\n<code>r3h</code>: 3-month rolling rainfall sum (mm)</li>\n<li>\n<code>rfh_avg</code>: Long-term average rainfall for the dekad (mm)</li>\n<li>\n<code>r1h_avg</code>: Long-term average for 1-month rolling rainfall (mm)</li>\n<li>\n<code>r3h_avg</code>: Long-term average for 3-month rolling rainfall (mm)</li>\n<li>\n<code>rfq</code>: Rainfall anomaly (%)</li>\n<li>\n<code>r1q</code>: Rainfall anomaly (%)</li>\n<li>\n<code>r3q</code>: 3-month rainfall anomaly (%)</li>\n</ul>\n<p>The data is aggregated at the subnational level and follows administrative boundaries defined by the World Food Programme (WFP), with each unit assigned a unique code (<code>Pcode</code>).</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>Before we begin, we need to install and load the necessary R packages. We will be using the {tidyverse} package for data wrangling, as well as the {SCI} package for calculating the SPI.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">SCI</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For Standardized Precipitation Index calculations (climate analysis)</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://conflicted.r-lib.org/\">conflicted</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For resolving conflicts between function names in different packages</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://haozhu233.github.io/kableExtra/\">kableExtra</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org\">ggplot2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/\">ggtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://github.com/yixuan/showtext\">showtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://conflicted.r-lib.org/reference/conflicts_prefer.html\">conflicts_prefer</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">dplyr</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">::</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Prefer 'select' function from dplyr package</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://conflicted.r-lib.org/reference/conflicts_prefer.html\">conflicts_prefer</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">dplyr</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">::</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/lead-lag.html\">lag</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Prefer 'lag' function from dplyr package</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://conflicted.r-lib.org/reference/conflicts_prefer.html\">conflicts_prefer</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">dplyr</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">::</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Prefer 'filter' function from dplyr package</span></span></code></pre></div></div>\n</div>\n<div class=\"callout callout-style-default callout-warning callout-titled\">\n<div class=\"callout-header d-flex align-content-center\">\n<div class=\"callout-icon-container\">\n<i class=\"callout-icon\"></i>\n</div>\n<div class=\"callout-title-container flex-fill\">\nWarning\n</div>\n</div>\n<div class=\"callout-body-container callout-body\">\n<p>Important to use {conflicted} package to specify preferred functions to avoid naming conflicts between {tidyverse} and {SCI} packages.</p>\n</div>\n</div>\n</section><section class=\"level2\" id=\"loading-data-hdx\"><h2 class=\"anchored\" data-anchor-id=\"loading-data-hdx\">Loading data HDX</h2>\n<p>Data can be found <a href=\"https://data.humdata.org/dataset/som-rainfall-subnational\">here</a> in file <code>som-rainfall-adm2-full.csv</code>. For Somalia, data is available from January 1981.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read the rainfall data for Somalia`</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># You can also download the data from the HDX platform and read it locally</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/utils/read.table.html\">read.csv</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://data.humdata.org/dataset/ed6e1b4b-8094-47e6-bdf7-f6d56fa7abb9/resource/8b333d58-d69e-418c-b5e3-dd86f12eee05/download/som-rainfall-subnat-full.csv\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<section class=\"level3\" id=\"data-wrangling\"><h3 class=\"anchored\" data-anchor-id=\"data-wrangling\">Data wrangling</h3>\n<p>We preprocess the data to extract relevant information to calculate the SPI. We extract the year and month from the date column, calculate the rainfall anomaly, and group the data by year, month, and district_code.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/slice.html\">slice</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Remove the first row (metadata)</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm_level</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    year <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://lubridate.tidyverse.org/reference/year.html\">year</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">date</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Extract year from the 'date' column</span></span>\n<span>    month <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://lubridate.tidyverse.org/reference/month.html\">month</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">date</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Extract month from the 'date' column</span></span>\n<span>    district_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">PCODE</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename the 'ADM2_PCODE' column to 'district_code'</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2025</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Filter data up to 2024</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    rainfall_monthly_total <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rfh</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename the column 'rfh' to 'rainfall_monthly_total'</span></span>\n<span>    rainfall_monthly_lt_average <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rfh_avg</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename the column 'rfh_avg' to 'rainfall_monthly_lt_average'</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    rainfall_monthly_total <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/numeric.html\">as.numeric</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Convert rainfall total to numeric</span></span>\n<span>    rainfall_monthly_lt_average <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/numeric.html\">as.numeric</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_lt_average</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Convert long-term average to numeric</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">district_code</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_lt_average</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select relevant columns</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Group by year, month, and district_code, and calculate mean rainfall values by district</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">district_code</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    rainfall_monthly_total <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/mean.html\">mean</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>, na.rm <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Calculate the mean of rainfall total</span></span>\n<span>    rainfall_monthly_lt_average <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/mean.html\">mean</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_lt_average</span>, na.rm <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Calculate the mean of long-term average</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">ungroup</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Optionally, you can calculate rainfall anomaly as a percentage of the long-term average</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># rainfall_anomaly = 1, indicates no anomaly</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># &lt; 1 indicates below average</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># &gt; 1 indicates above average</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    rainfall_anomaly <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">/</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_lt_average</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section></section><section class=\"level2\" id=\"we-then-calculate-the-spi-for-different-time-scales-1-3-6-12-months.\"><h2 class=\"anchored\" data-anchor-id=\"we-then-calculate-the-spi-for-different-time-scales-1-3-6-12-months.\">We then calculate the SPI for different time scales (1, 3, 6, 12 months).</h2>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">district_code</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Group by district_code</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    spi1 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">transformSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>      first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Start month for SPI calculation</span></span>\n<span>      obj <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">fitSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>        first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Start month for SPI calculation</span></span>\n<span>        time.scale <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Time scale for SPI calculation</span></span>\n<span>        distr <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"gamma\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Distribution for fitting</span></span>\n<span>        p0 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Use initial parameter estimates</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    spi3 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">transformSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>      first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>      obj <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">fitSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>        first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>        time.scale <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>,</span>\n<span>        distr <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"gamma\"</span>,</span>\n<span>        p0 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    spi6 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">transformSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>      first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>      obj <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">fitSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>        first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>        time.scale <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">6</span>,</span>\n<span>        distr <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"gamma\"</span>,</span>\n<span>        p0 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    spi12 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">transformSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>      first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>      obj <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">fitSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>        first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>        time.scale <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>,</span>\n<span>        distr <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"gamma\"</span>,</span>\n<span>        p0 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">ungroup</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/arrange.html\">arrange</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">district_code</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>The output table looks like this:</p>\n<div class=\"cell\">\n<div class=\"cell-output-display\">\n<table class=\"table caption-top table-sm table-striped small\">\n<thead><tr class=\"header\">\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">year</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">month</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: left;\">district_code</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">rainfall_monthly_total</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">rainfall_monthly_lt_average</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">rainfall_anomaly</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">spi1</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">spi3</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">spi6</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">spi12</th>\n</tr></thead>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">1</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">0.9417476</td>\n<td style=\"text-align: right;\">1.744876</td>\n<td style=\"text-align: right;\">0.5397218</td>\n<td style=\"text-align: right;\">-1.1043463</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">2</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">2.0194174</td>\n<td style=\"text-align: right;\">2.027616</td>\n<td style=\"text-align: right;\">0.9959566</td>\n<td style=\"text-align: right;\">0.1537152</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">3</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">32.8349507</td>\n<td style=\"text-align: right;\">9.696980</td>\n<td style=\"text-align: right;\">3.3861008</td>\n<td style=\"text-align: right;\">2.0730688</td>\n<td style=\"text-align: right;\">2.0600381</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">4</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">18.3139157</td>\n<td style=\"text-align: right;\">24.722222</td>\n<td style=\"text-align: right;\">0.7407876</td>\n<td style=\"text-align: right;\">-0.3498783</td>\n<td style=\"text-align: right;\">0.9740066</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">5</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">6.7928803</td>\n<td style=\"text-align: right;\">17.754692</td>\n<td style=\"text-align: right;\">0.3825963</td>\n<td style=\"text-align: right;\">-1.1682128</td>\n<td style=\"text-align: right;\">0.3482195</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">6</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">2.7443365</td>\n<td style=\"text-align: right;\">4.763215</td>\n<td style=\"text-align: right;\">0.5761522</td>\n<td style=\"text-align: right;\">-1.1812731</td>\n<td style=\"text-align: right;\">-1.5032149</td>\n<td style=\"text-align: right;\">0.1598925</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">7</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">17.3592230</td>\n<td style=\"text-align: right;\">14.047789</td>\n<td style=\"text-align: right;\">1.2357264</td>\n<td style=\"text-align: right;\">0.7686934</td>\n<td style=\"text-align: right;\">-0.9048239</td>\n<td style=\"text-align: right;\">0.3881687</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">8</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">34.8381870</td>\n<td style=\"text-align: right;\">26.758146</td>\n<td style=\"text-align: right;\">1.3019657</td>\n<td style=\"text-align: right;\">0.8281462</td>\n<td style=\"text-align: right;\">0.7648482</td>\n<td style=\"text-align: right;\">0.7461252</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">9</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">29.1682857</td>\n<td style=\"text-align: right;\">19.003020</td>\n<td style=\"text-align: right;\">1.5349290</td>\n<td style=\"text-align: right;\">1.2521098</td>\n<td style=\"text-align: right;\">1.2306838</td>\n<td style=\"text-align: right;\">0.0193027</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">10</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">4.1974111</td>\n<td style=\"text-align: right;\">8.226213</td>\n<td style=\"text-align: right;\">0.5102483</td>\n<td style=\"text-align: right;\">-0.3816705</td>\n<td style=\"text-align: right;\">0.7653264</td>\n<td style=\"text-align: right;\">0.1559530</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n</section><section class=\"level2\" id=\"interpretation\"><h2 class=\"anchored\" data-anchor-id=\"interpretation\">Interpretation</h2>\n<p>Drought events are indicated by negative SPI values, with more negative values indicating more severe drought conditions. Conversely, positive SPI values indicate wetter-than-average conditions. For demonstrating purposes, let's visualize the SPI values for Laasqoray district in Sanaag region. One efficient way to visualize SPI values is by using a box plot with SPI categories.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/sysfonts/man/font_add_google.html\">font_add_google</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme for the chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">theme_boxplot_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\">function</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">{</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span> </span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme settings</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Axis settings</span></span>\n<span>      axis.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      axis.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title settings</span></span>\n<span>      plot.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>, </span>\n<span>      plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">24</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>        width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Legend settings</span></span>\n<span>      legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"top\"</span>,</span>\n<span>      legend.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.spacing.x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.2</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.spacing <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>      legend.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.direction <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"horizontal\"</span>,</span>\n<span>      legend.byrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span>,</span>\n<span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Caption settings</span></span>\n<span>      plot.caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_markdown.html\">element_markdown</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey70\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"italic\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>,</span>\n<span>        hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span></span>\n<span>        <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>,</span>\n<span>        fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">}</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"1-month Standardized Precipitation Index (SPI-1) in Laasqoray, Somalia for the period 1981-2024\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Data:** Own estimations using Somalia rainfall Indicators at Subnational Level (HDX)\"</span>,</span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"&lt;br&gt;\"</span>, </span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Graphic:** Juan Torres Mungu\u00eda\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">#</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/data.frame.html\">data.frame</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  ymin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  ymax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/factor.html\">factor</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extremely dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severely dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderately dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderately wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severely wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extremely wet\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    levels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extremely dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severely dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderately dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderately wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severely wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extremely wet\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#F76D5E\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFAD72\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFE099\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#99FF99\"</span>,</span>\n<span>    <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#99FF99\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#99EAFF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#75D3FF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#3D87FF\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">district_code</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"SO1503\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>month <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/factor.html\">factor</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span>, levels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">:</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>, labels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month.name</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Convert month to factor</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span>, y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add box plot with SPI categories</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_tile.html\">geom_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span>, <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>ymin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ymin</span>, ymax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ymax</span>, xmin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">Inf</span>, xmax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">Inf</span>, fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">label</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    alpha <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.2</span>, inherit.aes <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_boxplot.html\">geom_boxplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, outlier.size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, outlier.shape <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">16</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_manual.html\">scale_fill_manual</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>values <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/stats/setNames.html\">setNames</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fill</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">label</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"SPI-1\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guides.html\">guides</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guide_legend.html\">guide_legend</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>nrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Number of rows in the legend</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">theme_boxplot_chart</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb6\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_opts.html\">showtext_opts</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set the resolution of the image 320 dpi is for high-quality images (\"retina\")</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsave.html\">ggsave</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"spi-somalia.png\"</span>,</span>\n<span>  dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span>,</span>\n<span>  width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>,</span>\n<span>  height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">9</span>,</span>\n<span>  units <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"in\"</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Turn off the showtext functionality</span></span></code></pre></div></div>\n</div>\n<p><a class=\"lightbox\" data-gallery=\"quarto-lightbox-gallery-1\" href=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia//spi-somalia.png\"><img class=\"img-fluid\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/spi-somalia.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:100.0%\"/></a></p>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {How to Compute and Visualize the {Standardized}\n    {Precipitation} {Index} {(SPI)} for Drought Analysis},\n  date = {2025-02-08},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"How to Compute and Visualize\nthe Standardized Precipitation Index (SPI) for Drought Analysis.\"</span>\nFebruary 8, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/\">https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/v1x6c-fv074","guid":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/","image":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/spi-somalia.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1738972800,"rid":"zwhe7-d9z73","summary":"Overview The Standardized Precipitation Index (SPI) quantifies how precipitation deviates from the historical average over multiple time scales (e.g., from 1 to 12 months), allowing for consistent monitoring of droughts and floods across regions and time, making it a valuable tool for early warning and risk assessment systems.","tags":["Data Analysis","Drought","Tidyverse","Ggplot2","Box Plots"],"title":"How to compute and visualize the Standardized Precipitation Index (SPI) for drought analysis","updated_at":1790603817,"url":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/","version":"v1"}},{"document":{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p>Previously, in <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization//../../../blog/posts/spi_somalia/index.html\">Part 1 of this tutorial</a>, we calculated the Standardized Precipitation Index (SPI) for different time scales using the {SCI} package in R. Now, we will map the SPI values for the districts of Somalia using {sf} and {ggplot2} packages in R.</p>\n</section><section class=\"level2\" id=\"about-the-data\"><h2 class=\"anchored\" data-anchor-id=\"about-the-data\">About the data</h2>\n<p>The information of the Somalian sub national administrative boundaries is obtained from the <a href=\"https://data.humdata.org/\">Humanitarian Data Exchange (HDX) initiative</a> of the United Nations Office for the Coordination of Humanitarian Affairs (OCHA). The information comes as a shapefile <code>.shp</code> and is available <a href=\"https://data.humdata.org/dataset/cod-ab-som?\">here</a> in a zip file named <code>som_adm_ocha_20250108_AB_SHP.zip</code>. The shapefile contains the administrative boundaries of Somalia at the subnational level. In particular, we will use file <code>som_admbnda_ADM2_ocha_20250108.shp</code>, that contains the shapefile of Somalia at the district level. I downloaded this file and located it in <code>/shp</code> folder.</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>Before we begin, we need to install and load the necessary R packages.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/\">sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org\">ggplot2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/\">ggtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://github.com/yixuan/showtext\">showtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com\">patchwork</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"loading-data-hdx\"><h2 class=\"anchored\" data-anchor-id=\"loading-data-hdx\">Loading data HDX</h2>\n<p>Data can be found <a href=\"https://data.humdata.org/dataset/som-rainfall-subnational\">here</a> in file <code>som-rainfall-adm2-full.csv</code>. For Somalia, data is available from January 1981.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_read.html\">read_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"shp/som_admbnda_adm2_ocha_20250108.shp\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    district <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ADM2_EN</span>, </span>\n<span>    district_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ADM2_PCODE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<section class=\"level3\" id=\"data-wrangling\"><h3 class=\"anchored\" data-anchor-id=\"data-wrangling\">Data wrangling</h3>\n<p>I will add the SPI values previously calculated to the shapefile data frame. I saved the SPI values in a RData file named <code>rainfall_data.RData</code>.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/load.html\">load</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"rainfall_data.RData\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># First, we need to filter the SPI values for the last available month, i.e. December 2024</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># to have only one observation per district</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data_dec2024</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&amp;</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2024</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Merge the shapefile with the SPI values</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate-joins.html\">left_join</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data_dec2024</span>, by <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"district_code\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section></section><section class=\"level2\" id=\"set-theme-settings-and-define-fonts-colors-and-text-to-be-used-in-the-map\"><h2 class=\"anchored\" data-anchor-id=\"set-theme-settings-and-define-fonts-colors-and-text-to-be-used-in-the-map\">Set theme settings and define fonts, colors, and text to be used in the map</h2>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/sysfonts/man/font_add_google.html\">font_add_google</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">theme_spi_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\">function</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">{</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span> </span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme settings</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title settings</span></span>\n<span>      plot.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>, </span>\n<span>      plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>        width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey50\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span></span>\n<span>      legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"top\"</span>,</span>\n<span>      legend.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>      legend.key.width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>      legend.spacing.x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.spacing <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>      legend.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.direction <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"horizontal\"</span>,</span>\n<span>      legend.byrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span>,</span>\n<span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Caption settings</span></span>\n<span>      plot.caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_markdown.html\">element_markdown</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey70\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"italic\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>,</span>\n<span>        hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>,</span>\n<span>        fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">}</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title, subtitle, and caption for the waffle chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Standardized Precipitation Index (SPI) in Somalia\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"February 2024\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Data:** Somalia: Own estimations using Somalia Rainfall Indicators at Subnational Level (HDX) &lt;br&gt; **Graphic:** Juan Torres Mungu\u00eda\"</span></span></code></pre></div></div>\n</div>\n<p>Now, lets create a histogram of the SPI values for the districts of Somalia to use as a legend for the map.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/data.frame.html\">data.frame</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  ymin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  ymax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/factor.html\">factor</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severe dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderate dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderate wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severe wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme wet\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    levels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severe dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderate dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderate wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severe wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme wet\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#F76D5E\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFAD72\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFE099\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E5FFE5\"</span>,</span>\n<span>    <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E5FFE5\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#99EAFF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#75D3FF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#3D87FF\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://magrittr.tidyverse.org/reference/pipe.html\">%&gt;%</a></span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>spi_category <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/cut.html\">cut</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi1</span>,</span>\n<span>    breaks <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">Inf</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ymax</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    labels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">label</span>,</span>\n<span>    right <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># right = TRUE means that the intervals are closed on the right</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">!</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/NA.html\">is.na</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">histogram_spi</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">!</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/NA.html\">is.na</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_category</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_category</span>, fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_category</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_bar.html\">geom_bar</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_manual.html\">scale_fill_manual</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>values <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/stats/setNames.html\">setNames</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fill</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">label</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Number of districts\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">theme_spi_map</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"none\"</span>,</span>\n<span>    axis.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">7</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">7</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.line <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    panel.grid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/coord_flip.html\">coord_flip</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb6\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read the shapefile of Somalia with the interior region borders</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia_region</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_read.html\">read_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"shp/som_admbnda_adm1_ocha_20250108.shp\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia_region</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia_region</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3857</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Web Mercator projection</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3857</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_spi</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span>, <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_category</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey\"</span>, linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_manual.html\">scale_fill_manual</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>values <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/stats/setNames.html\">setNames</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fill</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">label</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia_region</span>, fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>, color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>, linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.9</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">theme_spi_map</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"none\"</span>,</span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Axis settings</span></span>\n<span>    axis.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.line <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.ticks <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    panel.grid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb7\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_spi</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com/reference/inset_element.html\">inset_element</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">histogram_spi</span>, left <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.4</span>, bottom <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, right <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, top <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.4</span>, on_top <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb8\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_opts.html\">showtext_opts</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsave.html\">ggsave</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"spi-somalia-map.png\"</span>,</span>\n<span>  dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span>,</span>\n<span>  width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>,</span>\n<span>  height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">9</span>,</span>\n<span>  units <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"in\"</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p><a class=\"lightbox\" data-gallery=\"quarto-lightbox-gallery-1\" href=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization//spi-somalia-map.png\"><img class=\"img-fluid\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/spi-somalia-map.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:100.0%\"/></a></p>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {How to Compute and Visualize the {Standardized}\n    {Precipitation} {Index} {(SPI)} for Drought Analysis},\n  date = {2025-02-14},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"How to Compute and Visualize\nthe Standardized Precipitation Index (SPI) for Drought Analysis.\"</span>\nFebruary 14, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/\">https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/4c24v-c9z61","guid":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/","image":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/spi-somalia-map.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1739491200,"rid":"xyk6p-57z32","summary":"Overview Previously, in Part 1 of this tutorial, we calculated the Standardized Precipitation Index (SPI) for different time scales using the {SCI} package in R. Now, we will map the SPI values for the districts of Somalia using {sf} and {ggplot2} packages in R. About the data The information of the Somalian sub national administrative boundaries is obtained from the Humanitarian Data Exchange (HDX) initiative of the United Nations Office","tags":["Data Visualization","Drought","Tidyverse","Ggplot2","Shapefiles"],"title":"How to compute and visualize the Standardized Precipitation Index (SPI) for drought analysis","updated_at":1790603811,"url":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/","version":"v1"}},{"document":{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p><a href=\"https://acleddata.com/\">ACLED (Armed Conflict Location &amp; Event Data Project)</a> provides detailed data on political violence and protest events across the globe. This blog post explores the visualization of armed conflict in the Lake Chad Basin, focusing on the dynamics of violence against civilians in the region. Using ACLED's data in combination with shapefiles from the <a href=\"https://data.humdata.org/\">Humanitarian Data Exchange (HDX) initiative</a> of the United Nations Office for the Coordination of Humanitarian Affairs (OCHA), we leverage {ggplot2}, {sf} and the {tidyverse} to create insightful maps that highlight the impact of armed conflict.</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>Load necessary libraries for data processing and visualization.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For data manipulation and visualization</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/\">sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For handling spatial data</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org\">ggplot2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For data visualization</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com\">patchwork</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For combining plots</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/\">ggtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Use rich text elements in ggplot</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://github.com/yixuan/showtext\">showtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add custom fonts to plots</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://paleolimbot.github.io/ggspatial/\">ggspatial</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For interacting with spatial data using ggplot2</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://docs.ropensci.org/rnaturalearth/\">rnaturalearth</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To provide map data that can be visualized using other R packages</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://docs.ropensci.org/rnaturalearthdata/\">rnaturalearthdata</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To store data for the rnaturalearth package</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set environment to English (useful for date/time formatting)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/invisible.html\">invisible</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/Sys.setenv.html\">Sys.setenv</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>LANG <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"en\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/invisible.html\">invisible</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/locales.html\">Sys.setlocale</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"LC_TIME\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"English\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"loading-data\"><h2 class=\"anchored\" data-anchor-id=\"loading-data\">Loading data</h2>\n<p>Accessing ACLED data requires registering on their <a href=\"https://developer.acleddata.com/\">ACLED Access Portal</a> to generate a unique access key. Once registered, you can download the data using their <a href=\"https://acleddata.com/data-export-tool/\">Data Export Tool</a>. I downloaded all the events occurred in Africa since 1997 and save them in file <code>acled_africa_1997-2025.csv</code>. To have a better understanding of their data, they provide a <a href=\"https://acleddata.com/acleddatanew/wp-content/uploads/dlm_uploads/2024/10/ACLED-Codebook-2024-7-Oct.-2024.pdf\">codebook</a>.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/utils/read.table.html\">read.csv</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"acled_africa_1997-2025.csv\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Information of the national and sub national administrative boundaries in the Lake Chad Basin is obtained from the HDX. The information comes as a shapefile <code>.shp</code> and is available <a href=\"https://data.humdata.org/dataset/lac-chad-basin-area?force_layout=desktop\">here</a> in a zip file named <code>lcb_admbnda_adm2_ocha.zip</code>. The shapefile contains the administrative boundaries of Lake Chad Basin region at the subnational level. In particular, we will use file <code>lcb_admbnda_adm2_ocha.shp</code>. I also downloaded the administrative boundaries of the West and Central Africa region available <a href=\"https://data.humdata.org/dataset/west-and-central-africa-administrative-boundaries-levels\">here</a>.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Lake Chad Basin Area - Administrative boundaries for Nigeria, Chad, Cameroon and Niger</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad_basin</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_read.html\">read_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"lcb_admbnda_adm2_ocha/lcb_admbnda_adm2_ocha.shp\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># West and Central Africa - Administrative boundaries levels 0 - 2 and Settlements</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">west_central_africa</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_read.html\">read_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"wca_admbnda_adm2_ocha/wca_admbnda_adm2_ocha.shp\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"data-processing\"><h2 class=\"anchored\" data-anchor-id=\"data-processing\">Data processing</h2>\n<p>As indicated in the <a href=\"https://acleddata.com/acleddatanew/wp-content/uploads/dlm_uploads/2024/10/ACLED-Codebook-2024-7-Oct.-2024.pdf\">ACLED's codebook</a>, geographic location of the events is specified in columns <code>latitude</code> and <code>longitude</code> in the <code>conflict_data</code> object and they are using the <a href=\"https://epsg.io/4326\">EPSG:4326</a> coordinate reference system. We have to ensure, that both <code>shp_lake_chad_basin</code> and <code>west_central_africa</code> have the same coordinate reference system. To achieve this, we use <code><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform()</a></code> from {sf} package.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># st_transform to convert coordinates to ACLED's data coordinate reference system</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad_basin</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad_basin</span>,</span>\n<span>  crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4326</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">west_central_africa</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">west_central_africa</span>,</span>\n<span>  crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4326</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Now, we subset the events to exclusively account for those occurred between 2020 and 2024 in the Lake Chad Basin. To achieve this, we use the {tidyverse} package for data wrangling and {sf} for spatial filtering. By applying the <code>st_filter</code> function, we retain only events located within the Lake Chad Basin area.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Keep only events from 2020 to 2024</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&gt;=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2020</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&amp;</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2025</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select only \"Violence against civilians\" events of type \"Attack\"</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">event_type</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Violence against civilians\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&amp;</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">sub_event_type</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Attack\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Keep events from Nigeria, Niger, Cameroon, and Chad</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/match.html\">%in%</a></span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Nigeria\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Niger\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Cameroon\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Chad\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Extract the month name from event_date</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    month <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://lubridate.tidyverse.org/reference/month.html\">month</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://lubridate.tidyverse.org/reference/ymd.html\">dmy</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">event_date</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select only relevant columns</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">event_id_cnty</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">event_date</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">event_type</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">sub_event_type</span>,</span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">actor1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">actor2</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">location</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">latitude</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">longitude</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fatalities</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">notes</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Convert the data to a spatial object using latitude and longitude (WGS 84 CRS)</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_as_sf.html\">st_as_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span>,</span>\n<span>  coords <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"longitude\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"latitude\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4326</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Filter events that fall within the Lake Chad Basin shapefile</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data_lake_chad</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_join.html\">st_filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad_basin</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>We then processes administrative boundary data to extract relevant regions in West and Central Africa, focusing on the Lake Chad Basin area.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb6\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Filter to include only countries in the Lake Chad Basin region</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># I included Central African Republic for visualization purposes</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">west_central_africa</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/match.html\">%in%</a></span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Nigeria\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Niger\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Chad\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Cameroon\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Central African Republic\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create country codes and format administrative division codes</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    country_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/case_when.html\">case_when</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Nigeria\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"NGA\"</span>,</span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Niger\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"NER\"</span>,</span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Chad\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"TCD\"</span>,</span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Cameroon\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"CMR\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Extract and format adm1 and adm2 codes</span></span>\n<span>    adm1_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_pad.html\">str_pad</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_extract.html\">str_extract</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin1Pcod</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\\\\d+\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>, pad <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"0\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    adm2_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_pad.html\">str_pad</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_sub.html\">str_sub</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin2Pcod</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">6</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>, pad <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"0\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a unique administrative code by combining country and division codes</span></span>\n<span>    adm_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country_code</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1_code</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm2_code</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename columns for clarity</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    country <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span>,</span>\n<span>    adm1 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin1Name</span>,</span>\n<span>    adm2 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin2Name</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select only relevant columns</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm_code</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm2</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Identify administrative units within the Lake Chad Basin</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>lake_chad_basin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/ifelse.html\">ifelse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm_code</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/match.html\">%in%</a></span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad_basin</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Rowcacode2</span>,</span>\n<span>    <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Yes\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"No\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Subset to retain only the administrative units inside the Lake Chad Basin</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_basin</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Yes\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Compute the bounding box for visualization</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">bbox</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_bbox.html\">st_bbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_min</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">bbox</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"xmin\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_max</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">bbox</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"xmax\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_min</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">bbox</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"ymin\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_max</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">bbox</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"ymax\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Aggregate administrative level 1 (regions/states) within the Lake Chad Basin</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_basin</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>geometry <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_combine.html\">st_union</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Keep only regions in the Lake Chad Basin and clean names</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_basin</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Yes\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>adm1 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_replace.html\">str_replace_all</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"_\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\" \"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Compute centroid coordinates for labeling</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_coordinates.html\">st_coordinates</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_unary.html\">st_centroid</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_coordinates.html\">st_coordinates</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_unary.html\">st_centroid</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Now, we create a hexagonal grid over the Lake Chad region with a cell size of approximately 10.69 km and fatalities and attack counts are aggregated per grid cell.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb7\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Reproject Lake Chad Basin shapefile to UTM Zone 33N (EPSG:32633)</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># This is important to set a cell size in km</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span>, crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">32633</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a hexagonal grid over the Lake Chad Basin with a cell size of ~10.69 km</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_make_grid.html\">st_make_grid</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span>,</span>\n<span>  cellsize <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10690</span>,</span>\n<span>  square <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Filter the grid to keep only hexagons intersecting the Lake Chad Basin</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid_filter</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/sf.html\">st_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_join.html\">st_filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Reproject the grid and Lake Chad Basin back to WGS84 (EPSG:4326)</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid_filter</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid_filter</span>, crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4326</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span>, crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4326</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Spatially join conflict data with the hexagonal grid</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data_grid</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_join.html\">st_join</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid_filter</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data_lake_chad</span>, left <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Aggregate conflict data by grid cell, summing fatalities and counting attacks</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fatalities_per_grid</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data_grid</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    fatalities <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/sum.html\">sum</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fatalities</span>, na.rm <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    num_attacks <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/context.html\">n</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_as_sf.html\">st_as_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Compute centroid coordinates for visualization</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_coordinates.html\">st_coordinates</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_unary.html\">st_centroid</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_coordinates.html\">st_coordinates</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_unary.html\">st_centroid</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>We need to relocate the coordinates of the labels for specific regions for better readability.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb8\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Adjust label positions for specific administrative regions to improve readability</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/case_when.html\">case_when</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme Nord\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.1</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Shift label slightly left</span></span>\n<span>      <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/case_when.html\">case_when</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme Nord\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Move label downward</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Adamawa\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.3</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Move label upward</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Borno\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.4</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Adjust label downward</span></span>\n<span>      <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Aggregate country geometries by merging administrative boundaries</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Dissolve some shapes</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>geometry <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_combine.html\">st_union</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_cast.html\">st_cast</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"POLYGON\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Retain the largest polygon for each country</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_measures.html\">st_area</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/Extremes.html\">max</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_measures.html\">st_area</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define manual label positions for country names</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country_labels</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tibble.tidyverse.org/reference/tibble.html\">tibble</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  country <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Nigeria\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Niger\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Chad\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Cameroon\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10.15</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">11</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">15</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">13.6</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># X-coordinates for label placement</span></span>\n<span>  y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">15</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14.2</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">9</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Y-coordinates for label placement</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>We first create an empty map of the countries and highlight the Lake Chad Basin area using {ggplot2}.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb9\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Automatically use showtext for handling fonts</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add Google font \"Voltaire\"</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/sysfonts/man/font_add_google.html\">font_add_google</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Voltaire\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Voltaire\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot country borders with a light fill color</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#ECEFF1\"</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>    inherit.aes <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot Lake Chad Basin area with a darker fill color</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E0E0E0\"</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>    inherit.aes <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Now, we add the fatalities information.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb10\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot fatalities per grid with a color gradient</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fatalities_per_grid</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fatalities</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    alpha <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_gradient.html\">scale_fill_gradient</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>name <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Fatalities\"</span>, </span>\n<span>                      low <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FCC5C0\"</span>, high <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#67001F\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>We add different color to subnational and national boundaries and add their corresponding labels.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb11\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot aggregated administrative region boundaries with white lines</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot country boundaries with black lines</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries_countries</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.25</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add labels for administrative regions (e.g., \"Extreme Nord\")</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_text.html\">geom_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span>, y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span>,</span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Wrap text if needed for long region names</span></span>\n<span>      label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_wrap.html\">str_wrap</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    colour <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#999\"</span>,</span>\n<span>    fontface <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>,</span>\n<span>    family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Voltaire\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  </span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add labels for countries with a larger font</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_text.html\">geom_label</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country_labels</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span>, y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span>, label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    colour <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    fontface <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4</span>,</span>\n<span>    family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Voltaire\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Finally, we center the map at the Lake Chad Basin area and add format for a better visualization.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb12\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title, subtitle, and caption for the waffle chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Armed conflict in the Lake Chad Basin, 2020-2024\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Fatalities in attacks perpetrated by organized armed actors against civilians\"</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Data:** Armed Conflict Location &amp; Event Data (ACLED) &lt;br&gt; **Graphic:** Juan Torres Mungu\u00eda\"</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set the map's coordinate limits and prevent expansion</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">coord_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    xlim <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_min</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_max</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    ylim <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_min</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_max</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    expand <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add a scale bar in the bottom left</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://paleolimbot.github.io/ggspatial/reference/annotation_scale.html\">annotation_scale</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>location <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bl\"</span>, width_hint <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add a north arrow in the top left corner</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://paleolimbot.github.io/ggspatial/reference/annotation_north_arrow.html\">annotation_north_arrow</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    location <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"tl\"</span>,</span>\n<span>    which_north <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"true\"</span>,</span>\n<span>    style <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">north_arrow_fancy_orienteering</span>,</span>\n<span>    height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Customize the legend</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guides.html\">guides</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guide_legend.html\">guide_legend</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bottom\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set the base theme without any background elements</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_void</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Voltaire\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Customize the map's text and legend styling</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title settings</span></span>\n<span>    plot.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Position of the title</span></span>\n<span>    plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Top, right, bottom, left</span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Width of the title, npc == 1 corresponds to the full width of the plot</span></span>\n<span>      width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    plot.subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey50\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span></span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Caption settings</span></span>\n<span>    plot.caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_markdown.html\">element_markdown</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey70\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>, face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>, face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.direction <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"horizontal\"</span>,</span>\n<span>    legend.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"top\"</span>,</span>\n<span>    legend.text.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bottom\"</span>,</span>\n<span>    legend.key.size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.65</span>, units <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>, color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>t <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, r <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, b <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, l <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#ECEFF1\"</span>, color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>We create a zoomed-in map of the Lake Chad Basin inset within the African continent, using ggplot2. It includes the ne_countries function from the {rnaturalearth} package to retrieve the map of Africa. The map of the Lake Chad Basin is overlaid on top of Africa, and a rectangle is drawn to highlight the region of interest (Lake Chad Basin). The map is customized with a white background and black borders.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb13\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Fetch African countries map from the rnaturalearth package</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">africa</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://docs.ropensci.org/rnaturalearth/reference/ne_countries.html\">ne_countries</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>continent <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Africa\"</span>, returnclass <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"sf\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a zoomed-in map of Lake Chad Basin within the African map</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map_zoom</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot the Africa map with a light fill color</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">africa</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#ECEFF1\"</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>    inherit.aes <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot Lake Chad Basin area with a darker fill color</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E0E0E0\"</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>    inherit.aes <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add a rectangle highlighting the Lake Chad Basin on the Africa map</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_tile.html\">geom_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>xmin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_min</span>, xmax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_max</span>, ymin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_min</span>, ymax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_max</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.2</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Remove grid and axes for a clean map appearance</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_void</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Customize borders and background of the map</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    panel.border <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>      fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.8</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Finally, we combine the main map of the Lake Chad Basin with an inset map of Africa showing the location of the Lake Chad Basin. The inset map is positioned within the main map using the <code><a href=\"https://patchwork.data-imaginist.com/reference/inset_element.html\">inset_element()</a></code> function of the {patchwork} package. Additionally, we set the resolution of the saved image to 320 dpi (high resolution) for better quality. Finally, the map is saved as a PNG file using <code><a href=\"https://ggplot2.tidyverse.org/reference/ggsave.html\">ggsave()</a></code></p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb14\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># locate main and inset map</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com/reference/inset_element.html\">inset_element</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    align_to <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>,</span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map_zoom</span>,</span>\n<span>    right <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>    left <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.84</span>,</span>\n<span>    top <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>    bottom <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.91</span>,</span>\n<span>    on_top <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb15\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set the resolution of the image 320 dpi is for high-quality images (\"retina\")</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_opts.html\">showtext_opts</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsave.html\">ggsave</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"lake-chad-map.png\"</span>,</span>\n<span>  dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span>,</span>\n<span>  width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>,</span>\n<span>  height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>,</span>\n<span>  units <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"in\"</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<div class=\"quarto-figure quarto-figure-center\">\n<figure class=\"figure\"><p><img class=\"img-fluid quarto-figure quarto-figure-center figure-img\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/lake-chad-map.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:30.0%\"/></p>\n</figure>\n</div>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {Visualizing Armed Conflict Using {ACLED's} Data and {HDX}\n    Shapefiles},\n  date = {2025-03-09},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"Visualizing Armed Conflict\nUsing ACLED's Data and HDX Shapefiles.\"</span> March 9, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/\">https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/cpzt6-efs07","guid":"https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/","image":"https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/lake-chad-map.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1741478400,"rid":"8n6ba-0p138","summary":"Overview ACLED (Armed Conflict Location &amp; Event Data Project) provides detailed data on political violence and protest events across the globe. This blog post explores the visualization of armed conflict in the Lake Chad Basin, focusing on the dynamics of violence against civilians in the region.","tags":["Data Visualization","Armed Conflict","ACLED","Lake Chad Basin","Nigeria"],"title":"Visualizing armed conflict using ACLED's data and HDX shapefiles","updated_at":1790603806,"url":"https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/","version":"v1"}},{"document":{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"setting-up-the-environment\"><h2 class=\"anchored\" data-anchor-id=\"setting-up-the-environment\">Setting Up the Environment</h2>\n<p>We begin by loading the necessary R packages:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Load required packages</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://jeroen.r-universe.dev/jsonlite\">jsonlite</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For working with JSON data</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/\">httr</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For HTTP requests</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org\">dplyr</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For data manipulation</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org\">readxl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For reading Excel files</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ropensci.r-universe.dev/writexl\">writexl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For writing Excel files</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"step-1-accessing-the-dataset\"><h2 class=\"anchored\" data-anchor-id=\"step-1-accessing-the-dataset\">Step 1: Accessing the Dataset</h2>\n<p>We retrieve the latest dataset of disease outbreaks from GitHub:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define the API URL from GitHub containing the latest dataset update</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">url_api</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://api.github.com/repos/jatorresmunguia/disease_outbreak_news/contents/Last%20update\"</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Retrieve the list of files in the \"Last update\" folder</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">file_list</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://jeroen.r-universe.dev/jsonlite/reference/fromJSON.html\">fromJSON</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/content.html\">content</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/GET.html\">GET</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">url_api</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, as <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"text\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">name</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Filter the most recent file that starts with \"outbreaks\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_file</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">file_list</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/grep.html\">grepl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">file_list</span>, pattern <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"^outbreaks\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select the file with a .csv extension</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rdata_file</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_file</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/grep.html\">grepl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\".csv$\"</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_file</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Construct the CSV file URL from GitHub and read the data into a dataframe</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/utils/read.table.html\">read.csv</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://raw.githubusercontent.com/jatorresmunguia/disease_outbreak_news/refs/heads/main/Last%20update/\"</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rdata_file</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, header <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Remove unnecessary ICD-11 classification columns</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11c1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11c2</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11c3</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11l1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11l2</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11l3</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"step-2-adding-who-and-unsd-regional-classifications\"><h2 class=\"anchored\" data-anchor-id=\"step-2-adding-who-and-unsd-regional-classifications\">Step 2: Adding WHO and UNSD Regional Classifications</h2>\n<p>We integrate additional geographic classifications from WHO and UNSD.</p>\n<section class=\"level3\" id=\"who-regions\"><h3 class=\"anchored\" data-anchor-id=\"who-regions\">WHO Regions</h3>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define the URL for the WHO regional classification dataset</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">url_who_class</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://cdn.who.int/media/docs/default-source/air-pollution-documents/air-quality-and-health/un-agencies-region-classification-for-country.xlsx?sfvrsn=289af35f_3\"</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a temporary file to store the downloaded Excel file</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp_file</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/tempfile.html\">tempfile</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fileext <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\".xlsx\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Download the WHO classification file and save it to the temporary file</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/GET.html\">GET</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">url_who_class</span>, <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/write_disk.html\">write_disk</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp_file</span>, overwrite <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"cell-output cell-output-stdout\">\n<pre><code>Response [https://cdn.who.int/media/docs/default-source/air-pollution-documents/air-quality-and-health/un-agencies-region-classification-for-country.xlsx?sfvrsn=289af35f_3]\n  Date: 2025-04-28 06:21\n  Status: 200\n  Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n  Size: 28.9 kB\n&lt;ON DISK&gt;  C:\\Users\\jator\\AppData\\Local\\Temp\\RtmpiGD1DX\\file990423923f25.xlsx</code></pre>\n</div>\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read the WHO classification data from the downloaded Excel file</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">who_class</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org/reference/read_excel.html\">read_excel</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp_file</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select relevant columns (ISO country code and WHO region name)</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename columns for consistency with the main dataset</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">who_class</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`ISO Country code`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`WHO Region name2`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>iso3 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`ISO Country code`</span>, who_region <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`WHO Region name2`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate-joins.html\">right_join</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span>, by <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"iso3\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Merge with the main dataset based on the ISO3 country code</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level3\" id=\"unsd-regions\"><h3 class=\"anchored\" data-anchor-id=\"unsd-regions\">UNSD Regions</h3>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb6\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read the UNSD regional classification dataset from an Excel file</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># The dataset is available at: https://unstats.un.org/unsd/methodology/m49/</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">unsd_class</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org/reference/read_excel.html\">read_excel</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>path <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"UNSD \u2014 Methodology.xlsx\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select relevant columns: ISO-alpha3 country code, region name, and sub-region name</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename columns to match the main dataset</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">unsd_class</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`ISO-alpha3 Code`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Region Name`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Sub-region Name`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    iso3 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`ISO-alpha3 Code`</span>,</span>\n<span>    unsd_region <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Region Name`</span>,</span>\n<span>    unsd_subregion <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Sub-region Name`</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate-joins.html\">right_join</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span>, by <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"iso3\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Merge with the main dataset based on the ISO3 country code</span></span></code></pre></div></div>\n</div>\n</section></section><section class=\"level2\" id=\"step-3-structuring-the-dataset\"><h2 class=\"anchored\" data-anchor-id=\"step-3-structuring-the-dataset\">Step 3: Structuring the Dataset</h2>\n<p>To facilitate better organization, we:</p>\n<ol type=\"1\">\n<li>Order the dataset by year, country, and disease code.</li>\n<li>Assign a unique outbreak ID.</li>\n<li>Insert an empty row for HXL headers.</li>\n</ol>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb7\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Arrange the dataset in descending order by Year, then by ISO3 country code, and ICD-10 4-character code</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/arrange.html\">arrange</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/desc.html\">desc</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">iso3</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104c</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a unique outbreak ID by concatenating Year, ISO3 country code, and ICD-10 4-character code</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>id_outbreak <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">iso3</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104c</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add an empty row at the beginning of the dataset (for later HXL hashtag insertion)</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tibble.tidyverse.org/reference/add_row.html\">add_row</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>.before <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"step-4-adding-hxl-hashtags\"><h2 class=\"anchored\" data-anchor-id=\"step-4-adding-hxl-hashtags\">Step 4: Adding HXL Hashtags</h2>\n<p>We define HXL hashtags for each relevant column:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb8\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define the mapping of column names to their corresponding HXL hashtags</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">cols2hxl</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  id_outbreak <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#Year+iso3+icd4\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Unique outbreak ID</span></span>\n<span>  Country <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#country+name\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Country name</span></span>\n<span>  iso2 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#country+code+iso2\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># ISO 2-letter country code</span></span>\n<span>  iso3 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#country+code+iso3\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># ISO 3-letter country code</span></span>\n<span>  unsd_region <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#region+unsd\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># UNSD region</span></span>\n<span>  unsd_subregion <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#subregion+unsd\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># UNSD subregion</span></span>\n<span>  who_region <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#region+who\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># WHO region</span></span>\n<span>  Year <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#date+year\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Year of the outbreak</span></span>\n<span>  icd10n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+name+icd\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease name (ICD-10)</span></span>\n<span>  icd103n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+name+icd3\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease name (ICD-10 3-character)</span></span>\n<span>  icd104n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+name+icd4\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease name (ICD-10 4-character)</span></span>\n<span>  icd10c <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+code+icd\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease code (ICD-10)</span></span>\n<span>  icd103c <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+code+icd3\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease code (ICD-10 3-character)</span></span>\n<span>  icd104c <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+code+icd4\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease code (ICD-10 4-character)</span></span>\n<span>  Disease <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+name\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease name</span></span>\n<span>  DONs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#news+id\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># News ID</span></span>\n<span>  Definition <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#x_disease+definition\"</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease definition</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add HXL hashtags to the relevant columns in the dataset</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/across.html\">across</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyselect.r-lib.org/reference/all_of.html\">all_of</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/names.html\">names</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">cols2hxl</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/replace.html\">replace</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">.</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">cols2hxl</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/context.html\">cur_column</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select the relevant columns for the final dataset</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">id_outbreak</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd10n</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd103n</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd10c</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd103c</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104c</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Disease</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Definition</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Country</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">iso2</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">iso3</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">unsd_region</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">unsd_subregion</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">who_region</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">DONs</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"step-5-exporting-the-final-dataset\"><h2 class=\"anchored\" data-anchor-id=\"step-5-exporting-the-final-dataset\">Step 5: Exporting the Final Dataset</h2>\n<p>Finally, we save the dataset as an Excel file:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb9\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://docs.ropensci.org/writexl//reference/write_xlsx.html\">write_xlsx</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/list.html\">list</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>Data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, path <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"disease_outbreaks_HDX.xlsx\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {Working with {Humanitarian} {Exchange} {Language} {(HXL)}\n    {Hashtags}},\n  date = {2025-03-26},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"Working with Humanitarian\nExchange Language (HXL) Hashtags.\"</span> March 26, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/\">https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/0dt7g-rr206","guid":"https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/","image":"https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/hdx_image.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1742947200,"rid":"s8zfb-cxz88","summary":"Setting Up the Environment We begin by loading the necessary R packages: # Load required packages library(jsonlite) # For working with JSON data library(httr) # For HTTP requests library(dplyr) # For data manipulation library(readxl) # For reading Excel files library(writexl) # For writing Excel files Step 1: Accessing the Dataset We retrieve the latest dataset of disease outbreaks from GitHub: # Define the API URL from GitHub containing the","tags":["Data Management","Humanitarian Data Exchange","Humanitarian Exchange Language","Disease Outbreaks","Epidemics"],"title":"Working with Humanitarian Exchange Language (HXL) Hashtags","updated_at":1790603800,"url":"https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/","version":"v1"}},{"document":{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p>According to the 2021-22 Domestic Violence module of the Kingdom of Cambodia's Demographic and Health Survey (CDHS), over 21% of Cambodian women aged 15\u201349 who have ever had a husband (or intimate partner), have experienced physical, sexual, economic, and/or emotional intimate partner violence in their lifetime. This figures varies significantly across the country, with some provinces reporting rates as high as 45% while others report rates as low as 6%.</p>\n<p>A better understanding of the geographical distribution of intimate partner violence (IPV) in Cambodia can help policymakers and organizations to target their efforts more effectively. In this blog post, I will show how to create choropleth maps using R and shapefiles to visualize the prevalence of IPV in Cambodia at the provincial level. Additionally, I will use the {patchwork} package to combine these maps into the same graphic. The result will look like this:</p>\n<p><a class=\"lightbox\" data-gallery=\"quarto-lightbox-gallery-1\" href=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia//ipv-cambodia-map.png\"><img class=\"img-fluid\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/ipv-cambodia-map.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:100.0%\"/></a></p>\n</section><section class=\"level2\" id=\"about-the-data\"><h2 class=\"anchored\" data-anchor-id=\"about-the-data\">About the data</h2>\n<p>Information comes from the document \"Further Data Analysis Report. From the Cambodia Demographic and Health Survey 2021-2022\", available <a href=\"https://nis.gov.kh/nis/CDHS_Further_Data/CDHS%20Domestic%20Violence%20Report%202024_En.pdf\">here</a>. In particular, I will use Table A.1: <em>Intimate-partner violence by background characteristics</em>.</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>First, we install and load the necessary R packages.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/\">sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For handling shapefiles</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org\">readxl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To read Excel files</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://haozhu233.github.io/kableExtra/\">kableExtra</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For data tables</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org\">ggplot2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/\">ggtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://github.com/yixuan/showtext\">showtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com\">patchwork</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To combine multiple ggplots</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://colorspace.R-Forge.R-project.org/\">colorspace</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For color palettes</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">grid</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To add lines and text elements to graphical objects</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"loading-data\"><h2 class=\"anchored\" data-anchor-id=\"loading-data\">Loading data</h2>\n<p>I saved the information from Table A.1: <em>Intimate-partner violence by background characteristics</em> in the Excel file <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia//../../..\\intimate-partner-violence-cambodia.xlsx\">intimate-partner-violence-cambodia.xlsx</a>.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ipv_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org/reference/read_excel.html\">read_excel</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"intimate-partner-violence-cambodia.xlsx\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>This information looks like this:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ipv_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/kableExtra/man/kbl.html\">kbl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Lifetime experience of specific acts of intimate partner physical violence committed by their current or most recent partner by provinces, Cambodia 2021-22\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/kableExtra/man/kable_classic.html\">kable_paper</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"hover\"</span>, full_width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">F</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"cell-output-display\">\n<table class=\"lightable-paper lightable-hover caption-top table table-sm table-striped small\">\n<caption>Lifetime experience of specific acts of intimate partner physical violence committed by their current or most recent partner by provinces, Cambodia 2021-22</caption>\n<thead><tr class=\"header\">\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: left;\">Region</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Emotional violence</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Physical violence</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Sexual violence</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Physical or sexual</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Physical or sexual or emotional</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Number of women who ever had a husband/intimate partner</th>\n</tr></thead>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Banteay Meanchey</td>\n<td style=\"text-align: right;\">31.3</td>\n<td style=\"text-align: right;\">18.2</td>\n<td style=\"text-align: right;\">4.6</td>\n<td style=\"text-align: right;\">20.2</td>\n<td style=\"text-align: right;\">34.9</td>\n<td style=\"text-align: right;\">235</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Battambang</td>\n<td style=\"text-align: right;\">24.9</td>\n<td style=\"text-align: right;\">16.1</td>\n<td style=\"text-align: right;\">6.3</td>\n<td style=\"text-align: right;\">19.8</td>\n<td style=\"text-align: right;\">30.4</td>\n<td style=\"text-align: right;\">378</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Kampong Cham</td>\n<td style=\"text-align: right;\">7.7</td>\n<td style=\"text-align: right;\">5.2</td>\n<td style=\"text-align: right;\">1.1</td>\n<td style=\"text-align: right;\">5.8</td>\n<td style=\"text-align: right;\">11.5</td>\n<td style=\"text-align: right;\">352</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Kampong Chhnang</td>\n<td style=\"text-align: right;\">19.2</td>\n<td style=\"text-align: right;\">6.7</td>\n<td style=\"text-align: right;\">1.7</td>\n<td style=\"text-align: right;\">6.7</td>\n<td style=\"text-align: right;\">19.2</td>\n<td style=\"text-align: right;\">213</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Kampong Speu</td>\n<td style=\"text-align: right;\">16.6</td>\n<td style=\"text-align: right;\">9.5</td>\n<td style=\"text-align: right;\">2.6</td>\n<td style=\"text-align: right;\">10.1</td>\n<td style=\"text-align: right;\">19.1</td>\n<td style=\"text-align: right;\">362</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Kampong Thom</td>\n<td style=\"text-align: right;\">32.4</td>\n<td style=\"text-align: right;\">12.1</td>\n<td style=\"text-align: right;\">5.0</td>\n<td style=\"text-align: right;\">14.4</td>\n<td style=\"text-align: right;\">35.1</td>\n<td style=\"text-align: right;\">242</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Kampot</td>\n<td style=\"text-align: right;\">20.8</td>\n<td style=\"text-align: right;\">6.4</td>\n<td style=\"text-align: right;\">4.0</td>\n<td style=\"text-align: right;\">9.0</td>\n<td style=\"text-align: right;\">23.0</td>\n<td style=\"text-align: right;\">218</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Kandal</td>\n<td style=\"text-align: right;\">23.9</td>\n<td style=\"text-align: right;\">6.2</td>\n<td style=\"text-align: right;\">2.0</td>\n<td style=\"text-align: right;\">6.5</td>\n<td style=\"text-align: right;\">23.9</td>\n<td style=\"text-align: right;\">423</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Koh Kong</td>\n<td style=\"text-align: right;\">5.4</td>\n<td style=\"text-align: right;\">3.8</td>\n<td style=\"text-align: right;\">0.4</td>\n<td style=\"text-align: right;\">3.8</td>\n<td style=\"text-align: right;\">6.2</td>\n<td style=\"text-align: right;\">41</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Kratie</td>\n<td style=\"text-align: right;\">13.7</td>\n<td style=\"text-align: right;\">9.1</td>\n<td style=\"text-align: right;\">2.8</td>\n<td style=\"text-align: right;\">10.2</td>\n<td style=\"text-align: right;\">15.9</td>\n<td style=\"text-align: right;\">138</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Mondul Kiri</td>\n<td style=\"text-align: right;\">42.7</td>\n<td style=\"text-align: right;\">19.0</td>\n<td style=\"text-align: right;\">3.6</td>\n<td style=\"text-align: right;\">19.4</td>\n<td style=\"text-align: right;\">45.2</td>\n<td style=\"text-align: right;\">34</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Phnom Penh</td>\n<td style=\"text-align: right;\">10.3</td>\n<td style=\"text-align: right;\">5.1</td>\n<td style=\"text-align: right;\">1.3</td>\n<td style=\"text-align: right;\">5.8</td>\n<td style=\"text-align: right;\">11.0</td>\n<td style=\"text-align: right;\">904</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Preah Vihear</td>\n<td style=\"text-align: right;\">38.1</td>\n<td style=\"text-align: right;\">20.2</td>\n<td style=\"text-align: right;\">8.5</td>\n<td style=\"text-align: right;\">22.4</td>\n<td style=\"text-align: right;\">40.0</td>\n<td style=\"text-align: right;\">108</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Prey Veng</td>\n<td style=\"text-align: right;\">25.0</td>\n<td style=\"text-align: right;\">7.2</td>\n<td style=\"text-align: right;\">1.7</td>\n<td style=\"text-align: right;\">8.6</td>\n<td style=\"text-align: right;\">26.3</td>\n<td style=\"text-align: right;\">366</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Pursat</td>\n<td style=\"text-align: right;\">10.8</td>\n<td style=\"text-align: right;\">3.6</td>\n<td style=\"text-align: right;\">0.7</td>\n<td style=\"text-align: right;\">3.6</td>\n<td style=\"text-align: right;\">10.8</td>\n<td style=\"text-align: right;\">111</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Ratanak Kiri</td>\n<td style=\"text-align: right;\">24.7</td>\n<td style=\"text-align: right;\">6.6</td>\n<td style=\"text-align: right;\">0.8</td>\n<td style=\"text-align: right;\">7.1</td>\n<td style=\"text-align: right;\">25.7</td>\n<td style=\"text-align: right;\">96</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Siemreap</td>\n<td style=\"text-align: right;\">21.5</td>\n<td style=\"text-align: right;\">12.0</td>\n<td style=\"text-align: right;\">2.9</td>\n<td style=\"text-align: right;\">13.5</td>\n<td style=\"text-align: right;\">24.6</td>\n<td style=\"text-align: right;\">482</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Preah Sihanouk</td>\n<td style=\"text-align: right;\">10.3</td>\n<td style=\"text-align: right;\">3.4</td>\n<td style=\"text-align: right;\">1.6</td>\n<td style=\"text-align: right;\">4.0</td>\n<td style=\"text-align: right;\">10.8</td>\n<td style=\"text-align: right;\">75</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Stung Treng</td>\n<td style=\"text-align: right;\">29.3</td>\n<td style=\"text-align: right;\">12.5</td>\n<td style=\"text-align: right;\">7.5</td>\n<td style=\"text-align: right;\">16.3</td>\n<td style=\"text-align: right;\">31.5</td>\n<td style=\"text-align: right;\">66</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Svay Rieng</td>\n<td style=\"text-align: right;\">10.9</td>\n<td style=\"text-align: right;\">8.3</td>\n<td style=\"text-align: right;\">2.1</td>\n<td style=\"text-align: right;\">8.8</td>\n<td style=\"text-align: right;\">13.6</td>\n<td style=\"text-align: right;\">217</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Takeo</td>\n<td style=\"text-align: right;\">18.4</td>\n<td style=\"text-align: right;\">7.4</td>\n<td style=\"text-align: right;\">1.2</td>\n<td style=\"text-align: right;\">8.0</td>\n<td style=\"text-align: right;\">19.3</td>\n<td style=\"text-align: right;\">344</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Otdar Meanchey</td>\n<td style=\"text-align: right;\">15.1</td>\n<td style=\"text-align: right;\">6.1</td>\n<td style=\"text-align: right;\">0.0</td>\n<td style=\"text-align: right;\">6.1</td>\n<td style=\"text-align: right;\">15.4</td>\n<td style=\"text-align: right;\">77</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Kep</td>\n<td style=\"text-align: right;\">8.0</td>\n<td style=\"text-align: right;\">7.2</td>\n<td style=\"text-align: right;\">1.2</td>\n<td style=\"text-align: right;\">7.7</td>\n<td style=\"text-align: right;\">11.0</td>\n<td style=\"text-align: right;\">18</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Pailin</td>\n<td style=\"text-align: right;\">11.3</td>\n<td style=\"text-align: right;\">9.5</td>\n<td style=\"text-align: right;\">1.7</td>\n<td style=\"text-align: right;\">9.5</td>\n<td style=\"text-align: right;\">14.2</td>\n<td style=\"text-align: right;\">29</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Tboung Khmum</td>\n<td style=\"text-align: right;\">11.1</td>\n<td style=\"text-align: right;\">7.3</td>\n<td style=\"text-align: right;\">2.3</td>\n<td style=\"text-align: right;\">7.3</td>\n<td style=\"text-align: right;\">14.0</td>\n<td style=\"text-align: right;\">252</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n<p>Now, we load geographical data of the administrative division of Cambodia. These data are obtained from the <a href=\"https://data.humdata.org/\">Humanitarian Data Exchange (HDX) initiative</a> of the United Nations Office for the Coordination of Humanitarian Affairs (OCHA). The information comes as a shapefile <code>.shp</code> and is available <a href=\"https://data.humdata.org/dataset/cod-ab-khm\">here</a> in a zip file named <code>som_adm_ocha_20250108_AB_SHP.zip</code>. I downloaded this file and located it in <code>/khmadm_gov_20181004_ab_shp</code> folder.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_read.html\">read_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"khmadm_gov_20181004_ab_shp/khm_admbnda_adm1_gov_20181004.shp\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<section class=\"level3\" id=\"data-wrangling\"><h3 class=\"anchored\" data-anchor-id=\"data-wrangling\">Data wrangling</h3>\n<p>Next step is to combine the geographic information from the shapefile, <code>shp_cambodia</code>, with the data frame with the information on IPV, <code>ipv_cambodia</code>. To achieve this goal, we need to make sure that both datasets have a common variable to merge them. In this case, we will use the province name <code>ADM1_EN</code> in the shapefile and <code>Region</code> in the data frame. Then, I compare if the names of the provinces in both datasets match:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://generics.r-lib.org/reference/setops.html\">setdiff</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ADM1_EN</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ipv_cambodia</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Region</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"cell-output cell-output-stdout\">\n<pre><code>[1] \"Oddar Meanchey\"</code></pre>\n</div>\n</div>\n<p>The output indicates that there is one discrepancy. In <code>shp_cambodia</code>, the name of the province \"Oddar Meanchey\" corresponds to \"Otdar Meanchey\" in <code>ipv_cambodia</code>. I will rename this province in the shapefile to match the name in the data from the official report.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb7\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>ADM1_EN <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/case_when.html\">case_when</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ADM1_EN</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Oddar Meanchey\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Otdar Meanchey\"</span>,</span>\n<span>    <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ADM1_EN</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>After this modification, I join both datasets using a left join to keep all the provinces in the shapefile and add the corresponding IPV values from the data frame:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb8\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate-joins.html\">left_join</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ipv_cambodia</span>, by <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"ADM1_EN\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Region\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section></section><section class=\"level2\" id=\"creating-the-map\"><h2 class=\"anchored\" data-anchor-id=\"creating-the-map\">Creating the map</h2>\n<p>My idea is to develop three maps, each representing one type of violence against women and girls: emotional, physical, and sexual. I will first create the map corresponding to emotional violence.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb9\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># More font alternatives can be found here https://fonts.google.com/</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/sysfonts/man/font_add_google.html\">font_add_google</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_emotional_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>, </span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Emotional violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Color of the province borders</span></span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Emotional violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    check_overlap <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To avoid overlaping text in the plot</span></span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    fontface <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_gradient.html\">scale_fill_gradient2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    low <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFFE9EB3\"</span>,</span>\n<span>    mid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#C53270B3\"</span>,</span>\n<span>    high <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#040404B3\"</span>,</span>\n<span>    midpoint <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22.5</span>,</span>\n<span>    limits <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">45</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    breaks <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">15</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">30</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">45</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    labels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"0\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"15\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"30\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"45\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Emotional\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title of this subplot</span></span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Percentage of victims (%)\"</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title of the legend</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    </span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># No color in the background</span></span>\n<span>    plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22</span>,</span>\n<span>      hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Now, I replicate the same format for physical and sexual violence.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb10\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_physical_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>, </span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Physical violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>, </span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Physical violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    check_overlap <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span>,</span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    fontface <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_gradient.html\">scale_fill_gradient2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    low <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFFE9EB3\"</span>,</span>\n<span>    mid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#C53270B3\"</span>,</span>\n<span>    high <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#040404B3\"</span>,</span>\n<span>    midpoint <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22.5</span>,</span>\n<span>    limits <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">45</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Physical\"</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> </span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guides.html\">guides</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"none\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    </span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22</span>,</span>\n<span>      hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_sexual_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>, </span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Sexual violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>, </span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Sexual violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    check_overlap <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span>,</span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    fontface <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_gradient.html\">scale_fill_gradient2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    low <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFFE9EB3\"</span>,</span>\n<span>    mid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#C53270B3\"</span>,</span>\n<span>    high <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#040404B3\"</span>,</span>\n<span>    midpoint <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22.5</span>,</span>\n<span>    limits <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">45</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Sexual\"</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> </span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guides.html\">guides</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"none\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    </span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22</span>,</span>\n<span>      hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Now, using {patchwork} package, I combine the three plots into one single representation. I also use <code><a href=\"https://patchwork.data-imaginist.com/reference/plot_annotation.html\">plot_annotation()</a></code> function to add a title, subtitle, and caption to the overall design.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb11\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Design display two rows, one with the three maps, and the second one only with the common guide</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_emotional_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_physical_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_sexual_cambodia</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">/</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com/reference/guide_area.html\">guide_area</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> </span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom title, subtitle, and caption</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com/reference/plot_annotation.html\">plot_annotation</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Intimate partner violence in Cambodia, 2021-22\"</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Proportion of ever-partnered women and girls aged 15-49 who have been victims of violence perpetrated by their intimate partner, by type of violence.\"</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Data:** 2021-22 Cambodia Demographic and Health Survey (CDHS) &lt;br&gt; **Chart:** Juan Torres Mungu\u00eda\"</span>,</span>\n<span>    theme <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title settings</span></span>\n<span>      plot.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>, </span>\n<span>      plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">30</span>,</span>\n<span>        hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">50</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      </span>\n<span>      plot.subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey20\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">25</span>,</span>\n<span>        hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">50</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>        <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        </span>\n<span>        <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Caption settings</span></span>\n<span>        <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># I use element_markdown() because the caption has markdown text</span></span>\n<span>        plot.caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_markdown.html\">element_markdown</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>          color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>          size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">15</span>,</span>\n<span>          hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>          margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">80</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">50</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>        <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com/reference/plot_layout.html\">plot_layout</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>guides <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"collect\"</span>,</span>\n<span>              heights <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">13</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>               <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">'cm'</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">'cm'</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>              <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> </span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&amp;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme settings</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    legend.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bottom\"</span>,</span>\n<span>    legend.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span>,</span>\n<span>      hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"top\"</span>,</span>\n<span>    legend.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.key.width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.4</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.key.height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.direction <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"horizontal\"</span>,</span>\n<span></span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E5E5E5\"</span>,</span>\n<span>      fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E5E5E5\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Axis settings</span></span>\n<span>    axis.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.line <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.ticks <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    panel.grid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    </span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Finally, I use <code><a href=\"https://rdrr.io/r/grid/grid.lines.html\">grid.lines()</a></code> from {grid} package to add a horizontal line after the subtitle.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb12\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_cambodia</span></span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/grid.lines.html\">grid.lines</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.04</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.96</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Values should be between 0 and 1</span></span>\n<span>  y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.88</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Value should be between 0 and 1</span></span>\n<span>  gp <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/gpar.html\">gpar</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>col <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#C53270B3\"</span>, </span>\n<span>            lwd <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p><a class=\"lightbox\" data-gallery=\"quarto-lightbox-gallery-2\" href=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia//ipv-cambodia-map.png\"><img class=\"img-fluid\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/ipv-cambodia-map.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:100.0%\"/></a></p>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {Three Maps to Examine the Prevalence of Intimate Partner\n    Violence {(IPV)} in {Cambodia}},\n  date = {2025-05-10},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"Three Maps to Examine the\nPrevalence of Intimate Partner Violence (IPV) in Cambodia.\"</span> May\n10, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/\">https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/xc58v-hjg76","guid":"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/","image":"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/ipv-cambodia-map.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1746835200,"rid":"pn84n-7h484","summary":"Overview According to the 2021-22 Domestic Violence module of the Kingdom of Cambodia's Demographic and Health Survey (CDHS), over 21% of Cambodian women aged 15\u201349 who have ever had a husband (or intimate partner), have experienced physical, sexual, economic, and/or emotional intimate partner violence in their lifetime.","tags":["Data Visualization","Intimate Partner Violence (IPV)","Tidyverse","Ggplot2","Shapefiles"],"title":"Three maps to examine the prevalence of intimate partner violence (IPV) in Cambodia","updated_at":1790603797,"url":"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/","version":"v1"}}],"items":[{"authors":[{"contributor_roles":[],"family":"Shan","given":"Mridula","url":"https://orcid.org/0000-0003-4613-2669"},{"affiliation":[{"id":"https://ror.org/03m2x1q45","name":"University of Arizona"}],"contributor_roles":[],"family":"Scott","given":"Eric","url":"https://orcid.org/0000-0002-7430-7879"}],"blog":{"authors":null,"community_id":"3446712e-ab03-4bb7-8641-571dcda8d8cd","created":1787702400,"current_feed_url":null,"description":"Tracking disruptions to U.S. federal science funding, grant by grant.","doi":"https://doi.org/10.59350/grantwitness","favicon":"https://rogue-scholar.org/api/communities/3446712e-ab03-4bb7-8641-571dcda8d8cd/logo","feed_format":"application/atom+xml","feed_url":"https://grantwitness.org/updates/rogue-scholar.xml","filter":null,"generator":"Other","home_page_url":"https://grantwitness.org/updates?type=updates","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"grantwitness","status":"active","subfield":"3321","title":"Grant Witness","updated":1790553600,"use_api":null},"blog_name":"Grant Witness","blog_slug":"grantwitness","content_html":"<p>Unlike some other agencies we track, NOAA grants lack an agency-specific data source for grants.\nFor NOAA, we rely primarily on USAspending, DOGE, and crowd-sourced information to make determinations on grant status.</p>\n<h2>Data Sources</h2>\n<h4>DOGE</h4>\n<p>DOGE provides data on terminated awards, although we have found that it is incomplete or occasionally incorrect, so we generally do manual review of DOGE data or use it only in combination with other sources.</p>\n<h4>USAspending awards data</h4>\n<p>We use this source primarily for metadata including grantee information, grant assistance listing (CFDA), grant notice of funding announcement (NOFO), and total obligated and total outlaid amounts.\nWe also track changes to project end dates (i.e. project end date moved earlier, a \"cutoff\", or later, a \"reextension\"), and deobligation events (i.e. a negative amount obligated) which we use in combination as signals of disruption.</p>\n<h4>USAspending account data (File C)</h4>\n<p>File C is released roughly once a month (except that Sep/Oct are combined into one release).\nWe use this source primarily for outlay actions which we use to confirm reinstatements.</p>\n<h2>Terminations</h2>\n<p>An award is marked as terminated if it has been reported as such directly to us by a PI or via a trusted source, if it was listed by DOGE as being terminated, or if we see both a project end date cutoff and a deobligation in USAspending data.</p>\n<h2>Reinstatements</h2>\n<p>An award is labeled as reinstated if it has been reported as such directly to us by a PI, or if there is a re-extension of project end date or a positive obligation after a deobligation in USAspending awards data.\nReinstatements are confirmed by verifying that an award has received outlays since the reinstatement.</p>\n<h2>Award value</h2>\n<p>The funds obligated and spent at time of earliest disruption are calculated using the current total obligated amount minus obligations since the earliest termination date and the total outlays minus outlays since the earliest termination date, respectively.\nThe outlay and obligation events come from File C, while the current total obligated and outlaid numbers are from the more regularly updating USAspending awards data.\nAs a result, these estimates may fluctuate week-to-week.</p>","doi":"https://doi.org/10.59350/74brw-em383","guid":"https://doi.org/10.59350/74brw-em383","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1790553600,"rid":"c2qz2-pwj80","summary":"Unlike some other agencies we track, NOAA grants lack an agency-specific data source for grants. For NOAA, we rely primarily on USAspending, DOGE, and crowd-sourced information to make determinations on grant status.","tags":["Methods","National Oceanic And Atmospheric Administration"],"title":"NOAA Grant Disruption Methodology","updated_at":1790621962,"url":"https://grantwitness.org/noaa/updates/methodology","version":"v1"},{"authors":[{"contributor_roles":[],"family":"Shan","given":"Mridula","url":"https://orcid.org/0000-0003-4613-2669"},{"affiliation":[{"id":"https://ror.org/019jywm96","name":"rOpenSci"}],"contributor_roles":[],"family":"Ross","given":"Noam","url":"https://orcid.org/0000-0002-2136-0000"}],"blog":{"authors":null,"community_id":"3446712e-ab03-4bb7-8641-571dcda8d8cd","created":1787702400,"current_feed_url":null,"description":"Tracking disruptions to U.S. federal science funding, grant by grant.","doi":"https://doi.org/10.59350/grantwitness","favicon":"https://rogue-scholar.org/api/communities/3446712e-ab03-4bb7-8641-571dcda8d8cd/logo","feed_format":"application/atom+xml","feed_url":"https://grantwitness.org/updates/rogue-scholar.xml","filter":null,"generator":"Other","home_page_url":"https://grantwitness.org/updates?type=updates","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"grantwitness","status":"active","subfield":"3321","title":"Grant Witness","updated":1790553600,"use_api":null},"blog_name":"Grant Witness","blog_slug":"grantwitness","content_html":"<p>At Grant Witness, we have been tracking the damage of funding terminations across federal agencies since March 2025. We have focused on our core research agencies (NIH and NSF) and expanded to other agencies in science and public health such as EPA and CDC. Yet scientific research, development, and application are core functions across the federal government, and we are always striving to expand our view to better understand how the current administration is upending the American science enterprise.</p>\n<p>Today we're expanding both our <a href=\"https://grantwitness.org/noaa\">termination</a> and <a href=\"https://grantwitness.org/noaa/analyses/agency-pulse-noaa-grantmaking\">grantmaking</a> trackers to include the National Oceanic and Atmospheric Administration (NOAA). NOAA is a scientific agency within the United States Department of Commerce. Its stated mission is \"to understand and predict our changing environment, from the deep sea to outer space, and to manage and conserve America's coastal marine resources.\" It includes the National Weather Service.</p>\n<p>NOAA's work has been targeted from the start of the administration. The Trump administration has engaged in <a href=\"https://www.pbs.org/newshour/politics/fired-rehired-and-fired-again-noaa-employees-are-caught-in-a-liminal-state\">staff firings</a>, <a href=\"https://www.nytimes.com/2026/08/11/climate/noaa-arctic-report-card.html\">suppression of scientific reports</a>, and proposed budget cuts of more than 25% for <a href=\"https://climate.law.columbia.edu/content/trump-proposes-17-billion-cut-noaa\">both FY 2026</a> and <a href=\"https://lofgren.house.gov/media/press-releases/ranking-member-lofgrens-opening-statement-noaa-budget-hearing\">2027</a>.</p>\n<p>Like many other agencies, NOAA terminated research and support grants <em>en masse</em> starting in April 2025 under the disastrous tenure of the \"Department of Government Efficiency\" (DOGE). Neither NOAA nor DOGE has published a reliable accounting of these terminations. Grant Witness, through <a href=\"https://grantwitness.org/noaa/updates/methodology\">reporting and data mining</a>, has identified 26 NOAA grants that have been terminated, only 4 of which have been reinstated.</p>\n<h2 id=\"cfda-programs-and-line-offices\">CFDA Programs and Line Offices</h2>\n<p>These grants span 13 government programs (CFDAs, <a class=\"quarto-xref\" href=\"https://grantwitness.org/noaa/updates/2026-08-24-NOAA-targeted-ncrs/#tbl-cfda\">Table\u00a01</a>) across 4 of the 6 line offices at NOAA (<a class=\"quarto-xref\" href=\"https://grantwitness.org/noaa/updates/2026-08-24-NOAA-targeted-ncrs/#tbl-line-office\">Table\u00a02</a>). Together, they represent a loss of $28,237,466 in funding to states, cities, nonprofits and universities. Climate research is the most affected area, but a variety of programs in coastal and marine management have been shuttered.</p>\n<div class=\"cell\">\n<div class=\"cell quarto-float quarto-figure quarto-figure-center\" id=\"tbl-cfda\">\n<figure class=\"quarto-float quarto-float-tbl\">\n<figcaption class=\"quarto-float-caption-top quarto-float-caption quarto-float-tbl\" id=\"tbl-cfda-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\nTable\u00a01: Terminated NOAA awards by assistance listing (CFDA)\n</figcaption>\n<div aria-describedby=\"tbl-cfda-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\n<div class=\"cell-output-display\">\n<table class=\"table\" style=\"margin-left: auto; margin-right: auto;\">\n<thead>\n<tr>\n<th style=\"text-align:left;\"> CFDA Program Title </th>\n<th style=\"text-align:right;\"> Disrupted Grants </th>\n<th style=\"text-align:right;\"> Amt Remaining at Disruption </th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:left;\"> Climate and Atmospheric Research </td>\n<td style=\"text-align:right;\"> 11 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $11,217,919 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Cooperative Institute Inter Agency Funded Activities </td>\n<td style=\"text-align:right;\"> 2 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $1,927,901 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Marine Sanctuary Program </td>\n<td style=\"text-align:right;\"> 2 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $235,000 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Office for Coastal Management </td>\n<td style=\"text-align:right;\"> 2 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $1,470,012 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Chesapeake Bay Studies </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $40,700 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Coastal Zone Management Administration Awards </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $179,600 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Coastal Zone Management Estuarine Research Reserves </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $8,486.71 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Cooperative Science and Education Program </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $11,600 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Habitat Conservation </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $15.51 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> National Oceanic and Atmospheric Administration Noaa Cooperative Institutes </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $2,757,930 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Noaa Mission Related Education Awards </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $364,360 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Pacific Fisheries Data Program </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $766,710 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Sea Grant Support </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $9,257,231 </td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n</figure>\n</div>\n</div>\n<div class=\"cell\">\n<div class=\"cell quarto-float quarto-figure quarto-figure-center\" id=\"tbl-line-office\">\n<figure class=\"quarto-float quarto-float-tbl\">\n<figcaption class=\"quarto-float-caption-top quarto-float-caption quarto-float-tbl\" id=\"tbl-line-office-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\nTable\u00a02: Terminated NOAA awards by line office\n</figcaption>\n<div aria-describedby=\"tbl-line-office-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\n<div class=\"cell-output-display\">\n<table class=\"table\" style=\"margin-left: auto; margin-right: auto;\">\n<thead>\n<tr>\n<th style=\"text-align:left;\"> Line Office Name </th>\n<th style=\"text-align:right;\"> Disrupted Grants </th>\n<th style=\"text-align:right;\"> Amt Remaining at Disruption </th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:left;\"> Office of Oceanic and Atmospheric Research </td>\n<td style=\"text-align:right;\"> 15 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $25,160,981 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> National Ocean Service </td>\n<td style=\"text-align:right;\"> 6 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $1,893,099 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> National Marine Fisheries Service </td>\n<td style=\"text-align:right;\"> 4 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $819,026 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Office of the Under Secretary </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $364,360 </td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n</figure>\n</div>\n</div>\n<h2 id=\"state-breakdown\">State Breakdown</h2>\n<p>As one would expect, coastal states have borne the brunt of these terminations. New York has the greatest number of disrupted NOAA grants followed by Washington, Massachusetts, and New Jersey (tied at three disrupted grants) (<a class=\"quarto-xref\" href=\"https://grantwitness.org/noaa/updates/2026-08-24-NOAA-targeted-ncrs/#tbl-state\">Table\u00a03</a>). The states with the greatest loss in funding include Washington, North Crolina, and New Jersey.</p>\n<div class=\"cell\">\n<div class=\"cell quarto-float quarto-figure quarto-figure-center\" id=\"tbl-state\">\n<figure class=\"quarto-float quarto-float-tbl\">\n<figcaption class=\"quarto-float-caption-top quarto-float-caption quarto-float-tbl quarto-uncaptioned\" id=\"tbl-state-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\nTable\u00a03\n</figcaption>\n<div aria-describedby=\"tbl-state-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca\">\n<div class=\"cell-output-display\">\n<table class=\"table\" style=\"margin-left: auto; margin-right: auto;\">\n<thead>\n<tr>\n<th style=\"text-align:left;\"> State </th>\n<th style=\"text-align:right;\"> Disrupted Grants </th>\n<th style=\"text-align:right;\"> Remaining at Disruption </th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td style=\"text-align:left;\"> New York </td>\n<td style=\"text-align:right;\"> 4 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $787,780 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Washington </td>\n<td style=\"text-align:right;\"> 3 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $11,918,505 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> New Jersey </td>\n<td style=\"text-align:right;\"> 3 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $4,685,831 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Massachusetts </td>\n<td style=\"text-align:right;\"> 3 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $384,447 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> North Carolina </td>\n<td style=\"text-align:right;\"> 2 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $5,725,610 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Virginia </td>\n<td style=\"text-align:right;\"> 2 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $124,667 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> California </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $1,921,064 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Louisiana </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $1,126,012 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Oregon </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $766,710 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Rhode Island </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $344,000 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Wyoming </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $271,297 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Michigan </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $89,519 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Illinois </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $75,000 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Alaska </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $17,008 </td>\n</tr>\n<tr>\n<td style=\"text-align:left;\"> Maine </td>\n<td style=\"text-align:right;\"> 1 </td>\n<td style=\"text-align:right;border-right:1px solid black;\"> $16 </td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n</figure>\n</div>\n</div>\n<h2 id=\"new-grants-in-2025-and-2026\">New grants in 2025 and 2026</h2>\n<p>On our <a href=\"https://grantwitness.org/noaa/analyses/agency-pulse-noaa-grantmaking\">NOAA agency pulse page</a>, we are tracking the <em>new</em> awards made by the agency. Unlike many of the agencies we track, NOAA does not provide up-to-date grant listings, so we use USAspending data to track new awards, which can lag by over a month. Nonetheless, we can see NOAA is far behind in its distribution of Congressionally-appropriated funds. Unlike FY 2025, when many NOAA grants were distributed in the closing days of the Biden administration, NOAA was slow to start this year and has not made new grants since mid-August. It has distributed 61% fewer funds and 74% fewer grants than the 2021\u20132024 average. We will see if the agency can catch up in the remaining weeks of the fiscal year.</p>\n<p><a href=\"https://grantwitness.org/noaa/analyses/agency-pulse-noaa-grantmaking\"><img alt=\"Cumulative NOAA grant obligations by day of the fiscal year, FY2021 through FY2026. Every earlier year climbs steeply through August and September to finish between $1.4B and $3.3B. FY2026 (red) runs below all of them all year and stops at about $680M in mid-August.\" src=\"https://grantwitness.org/cms_media/noaa-obligations-curve-2026-09-25.png\"/></a></p>\n<p>We will continue to track the changes and disruptions at NOAA. Keep an eye on the <a href=\"https://grantwitness.org/noaa\">agency page</a>, or follow our <a href=\"https://grantwitness.org/noaa/updates/updates?type=updates\">updates</a> or <a href=\"https://buttondown.com/grantwitness\">newsletter</a>. As with all our work at Grant Witness, crowdsourced information is key to building and verifying our databases. Please continue to submit reports of grant terminations or reinstatements using <a href=\"https://airtable.com/appQRasGLMeZ4mpcl/pag4q0jeFfkL03wzU/form\">our web form</a>, and don't hesitate to <a href=\"mailto:info@grantwitness.org\">contact us</a>.</p>","doi":"https://doi.org/10.59350/zbrpd-kbv50","guid":"https://doi.org/10.59350/zbrpd-kbv50","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1790553600,"rid":"cyhts-3s181","summary":"At Grant Witness, we have been tracking the damage of funding terminations across federal agencies since March 2025. We have focused on our core research agencies (NIH and NSF) and expanded to other agencies in science and public health such as EPA and CDC.","tags":["Update","National Oceanic And Atmospheric Administration"],"title":"Grant Witness is tracking NOAA Terminations and Funding","updated_at":1790621961,"url":"https://grantwitness.org/noaa/updates/2026-08-24-NOAA-targeted-ncrs","version":"v1"},{"authors":[{"contributor_roles":[],"family":"Jivkova","given":"Katrin"}],"blog":{"authors":null,"community_id":"1e54953c-587a-4743-89af-ebd2cb45660c","created":1789516800,"current_feed_url":null,"description":null,"doi":"https://doi.org/10.59350/pensoft","favicon":"https://rogue-scholar.org/api/communities/1e54953c-587a-4743-89af-ebd2cb45660c/logo","feed_format":"application/atom+xml","feed_url":"https://blog.pensoft.net/feed/atom/","filter":null,"generator":"WordPress","home_page_url":"https://blog.pensoft.net/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"pensoft","status":"active","subfield":"2303","title":"Pensoft Blog","updated":1790604504,"use_api":true},"blog_name":"Pensoft Blog","blog_slug":"pensoft","content_html":"<div class=\"twitter-share\"><a href=\"https://twitter.com/intent/tweet?via=Pensoft\" class=\"twitter-share-button\" data-size=\"large\">Tweet</a></div>\n\n<p>Pensoft Publishers is pleased to announce the publication of the first issue of the <a href=\"https://sti.pensoft.net/\"><em>Journal of Scientific and Technological Innovations</em></a> (STI), an international journal for cutting-edge research across the scientific and technological spectrum.&nbsp;</p>\n\n\n\n<p>The journal notably adopts Pensoft's <a href=\"https://arphahub.com/\">ARPHA</a> platform, an innovative end-to-end full-featured publishing solution that streamlines the entire publication workflow \u2013 from initial manuscript submission to indexing, distribution, hosting and archiving through one coordinated platform. To date, ARPHA provides \"a home\" to about <a href=\"https://arphahub.com/about/browse_journals/\">100 open-access journals</a> across scientific fields.</p>\n\n\n<div class=\"wp-block-essential-blocks-table-of-contents\"><div class=\"eb-parent-wrapper eb-parent-eb-toc-ua965 \"><div class=\"eb-toc-container eb-toc-ua965  eb-toc-is-not-sticky eb-toc-not-collapsible eb-toc-initially-not-collapsed eb-toc-scrollToTop style-1 list-style-none\" data-scroll-top=\"false\" data-scroll-top-icon=\"fas fa-angle-up\" data-collapsible=\"false\" data-sticky-hide-mobile=\"false\" data-sticky=\"false\" data-scroll-target=\"scroll_to_toc\" data-copy-link=\"false\" data-editor-type=\"\" data-hide-desktop=\"false\" data-hide-tab=\"false\" data-hide-mobile=\"false\" data-itemCollapsed=\"false\"><div class=\"eb-toc-header\"><div class=\"eb-toc-title\">Table of Contents</div></div><div class=\"eb-toc-wrapper \" data-headers=\"[{&quot;level&quot;:4,&quot;content&quot;:&quot;About the journal&quot;,&quot;text&quot;:&quot;About the journal&quot;,&quot;link&quot;:&quot;about-the-journal&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Editorial board&quot;,&quot;text&quot;:&quot;Editorial board&quot;,&quot;link&quot;:&quot;editorial-board&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;Featured articles&quot;,&quot;text&quot;:&quot;Featured articles&quot;,&quot;link&quot;:&quot;featured-articles&quot;},{&quot;level&quot;:4,&quot;content&quot;:&quot;A platform for scientific advancement&quot;,&quot;text&quot;:&quot;A platform for scientific advancement&quot;,&quot;link&quot;:&quot;a-platform-for-scientific-advancement&quot;}]\" data-visible=\"[true,true,true,true,true,true]\" data-delete-headers=\"[{&quot;label&quot;:&quot;About the journal&quot;,&quot;value&quot;:&quot;about-the-journal&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Editorial board&quot;,&quot;value&quot;:&quot;editorial-board&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Featured articles&quot;,&quot;value&quot;:&quot;featured-articles&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;A platform for scientific advancement&quot;,&quot;value&quot;:&quot;a-platform-for-scientific-advancement&quot;,&quot;isDelete&quot;:false}]\" data-smooth=\"true\" data-top-offset=\"\"><div class=\"eb-toc__list-wrap\"><ul class='eb-toc__list'><li><a href=\"#about-the-journal\">About the journal</a><li><a href=\"#editorial-board\">Editorial board</a><li><a href=\"#featured-articles\">Featured articles</a><li><a href=\"#a-platform-for-scientific-advancement\">A platform for scientific advancement</a></ul></div></div></div></div></div>\n\n\n<h4 class=\"wp-block-heading\">About the journal</h4>\n\n\n\n<p>The <em>Journal of Scientific and Technological Innovations</em> is an international, multidisciplinary academic journal supervised by <a href=\"https://huit.edu.vn/en\">Ho Chi Minh City University of Industry and Trade</a> (HUIT). The journal publishes original, peer-reviewed research contributions.</p>\n\n\n\n<p>Its editorial purview encompasses a broad range of scientific and technological domains:</p>\n\n\n\n<ul>\n<li><strong>Food Science</strong> &#8211; biotechnology, traceability, safety and quality assurance, chemistry and toxicology, packaging, nanotechnology, sensory evaluation, sustainability, health and nutrition, and product innovation</li>\n\n\n\n<li><strong>Environmental Science</strong> &#8211; catalysis and energy conversion, carbon capture and utilisation, hydrogen and biomass technologies, agricultural and environmental biotechnology, bioremediation and wastewater treatment, sustainable chemistry, and computational approaches</li>\n\n\n\n<li><strong>Chemical Engineering</strong> &#8211; green and sustainable chemistry, computational methods, analytical and synthetic chemistry, pharmaceutical chemistry, catalytic technologies, and process development</li>\n\n\n\n<li><strong>Materials Science</strong> &#8211; nanomaterials, biomaterials, ceramics and composites, electronic and optical materials, polymers, surface coatings, eco-materials, and semiconductors</li>\n</ul>\n\n\n\n<h4 class=\"wp-block-heading\">Editorial board</h4>\n\n\n\n<p>The journal is led by an international team of scholars:</p>\n\n\n\n<p><strong>Editor-in-Chief:</strong> Thi Hong Anh Le, <a href=\"https://huit.edu.vn/en\">Ho Chi Minh City University of Industry and Trade</a>, Vietnam</p>\n\n\n\n<p><strong>Deputy Editors-in-Chief:</strong> Tuyen Truong, <a href=\"https://www.rmit.edu.au/\">RMIT University</a>, Australia; Thanh-Binh Nguyen, <a href=\"https://eng.nkust.edu.tw/\">National Kaohsiung University of Science and Technology</a>, Taiwan</p>\n\n\n\n<h4 class=\"wp-block-heading\">Featured articles</h4>\n\n\n\n<p>The first issue of STI presents six contributions spanning food science, materials science, and applied food technology:</p>\n\n\n\n<p><strong>A cost-benefit analysis of small-holder floating-house fish farming in Chau Doc City, Vietnamese Mekong Delta&nbsp;</strong></p>\n\n\n\n<p>A study of 35 Mekong Delta fish farmers reveals significant disparities in farm profitability across different river reaches, with operations facing demographic vulnerabilities and heavy reliance on unpaid labour.&nbsp;</p>\n\n\n\n<p>Read more: Farzana H, Tran DD, Nguyen TD, Park E (2026) A cost-benefit analysis of small-holder floating-house fish farming in Chau Doc City, Vietnamese Mekong Delta. Journal of Scientific and Technological Innovations 1: e209236.<a href=\"https://doi.org/10.3897/sti.e209236\"> https://doi.org/10.3897/sti.e209236</a></p>\n\n\n\n<p><strong>Ultrasound-assisted pullulanase modification increases resistant starch content and alters the structure\u2013function properties of water caltrop starch&nbsp;</strong></p>\n\n\n\n<p>A combined ultrasound and enzymatic treatment increased resistant starch content in water caltrop starch from 21.72% to 28.15%, whilst enhancing its water and oil absorption capacities. The approach offers potential for developing resistant starch-enriched functional food ingredients.</p>\n\n\n\n<p>Read more: Phan VM, Ngo TMP, Do TTN, Luyen TTH, Duong TT, Tran NM, Tran CH (2026) Ultrasound-assisted pullulanase modification increases resistant starch content and alters the structure\u2013function properties of water caltrop starch. Journal of Scientific and Technological Innovations 1: e209539.<a href=\"https://doi.org/10.3897/sti.e209539\"> https://doi.org/10.3897/sti.e209539</a>&nbsp;</p>\n\n\n\n<p><strong>Effects of Melatonin/\u03b2-cyclodextrin Treatment on Physicochemical and Bioactive Attributes of Cherry Tomatoes during Storage</strong></p>\n\n\n\n<p>Melatonin complexed with \u03b2-cyclodextrin reduced cherry tomato weight loss by up to 56% during refrigerated storage and proved more effective than free melatonin in preserving colour, acidity, and polyphenol content. The complex formation provides a viable strategy for extending shelf-life in harvested produce.</p>\n\n\n\n<p>Read more: Tran THC, Dong TT, Nguyen PH,Le NH,Kuo C-H (2026) Effects of Melatonin/\u03b2-cyclodextrin Treatment on Physicochemical and Bioactive Attributes of Cherry Tomatoes during Storage. Journal of Scientific and Technological Innovations 1: e212043.<a href=\"https://doi.org/10.3897/sti.e212043\"> https://doi.org/10.3897/sti.e212043</a></p>\n\n\n\n<p><strong>Design, Functionalities, and Emerging Applications of Ti</strong><strong><sub>3</sub></strong><strong>C</strong><strong><sub>2</sub></strong><strong>T</strong><strong><sub>x</sub></strong><strong> MXene-Based Composites: A Review&nbsp;</strong></p>\n\n\n\n<p>This review synthesises current knowledge on titanium carbide-based MXenes, two-dimensional materials with exceptional conductivity and mechanical properties. MXene-based composites demonstrate applications in gas sensing, photocatalytic carbon dioxide reduction, and energy storage devices.</p>\n\n\n\n<p>Read more: Ta QTH, Pham NN, Tran QN, Lu TMT, Noh JS (2026) Design, Functionalities, and Emerging Applications of Ti<sub>3</sub>C<sub>2</sub>T<sub>x</sub> MXene-Based Composites: A Review. Journal of Scientific and Technological Innovations 1: e205045.<a href=\"https://doi.org/10.3897/sti.%D0%B5205045\"> https://doi.org/10.3897/sti.\u0435205045</a>&nbsp;</p>\n\n\n\n<p><strong>Chemical Composition, Bioactivities, and Cosmetic Applications of Coconut Oil and Its Derivatives</strong></p>\n\n\n\n<p>Recent evidence demonstrates that coconut oil, when appropriately applied, offers dermatological benefits, with antimicrobial, anti-inflammatory, and antioxidant properties. The research clarifies interactions between coconut oil and skin microflora and explains previous inconsistencies in published findings.</p>\n\n\n\n<p>Read more: Dat NM, Phong DT, Long HB, Dat NT, Thy LTM (2026) Chemical Composition, Bioactivities, and Cosmetic Applications of Coconut Oil and Its Derivatives. Journal of Scientific and Technological Innovations 1: e205088.<a href=\"https://doi.org/10.3897/sti.e205088\"> https://doi.org/10.3897/sti.e205088</a>&nbsp;</p>\n\n\n\n<p><strong>Retention of bilberry anthocyanins in wood hemicelluloses coated microcapsules under the impact of humidity and packaging conditions&nbsp;</strong></p>\n\n\n\n<p>Storage at 8% relative humidity limited bilberry anthocyanin degradation to 17-22% over 24 weeks, with wood hemicelluloses providing comparable protection to conventional gum Arabic. The findings establish moisture control as important for developing shelf-stable natural functional powders with sustainable coating materials.</p>\n\n\n\n<h4 class=\"wp-block-heading\">A platform for scientific advancement</h4>\n\n\n\n<p>The diversity of contributions in this first issue reflects STI&#8217;s multidisciplinary scope. Researchers interested in submitting manuscripts are invited to consult the journal's guidelines and submission portal.</p>\n\n\n\n<p>***</p>\n\n\n\n<p>Access the full first issue <a href=\"https://sti.pensoft.net/issue/5600/\">here</a>.</p>\n\n<div class=\"twitter-share\"><a href=\"https://twitter.com/intent/tweet?via=Pensoft\" class=\"twitter-share-button\" data-size=\"large\">Tweet</a></div>","doi":"https://doi.org/10.59350/12ke2-9s798","guid":"https://blog.pensoft.net/?p=21014","image":"https://blog.pensoft.net/wp-content/uploads/2026/09/SciComm-PR-2026-Instagram-2026-09-28T141749.018-1.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1790553600,"rid":"t1tqd-psc54","summary":"Tweet Pensoft Publishers is pleased to announce the publication of the first issue of the <em> Journal of Scientific and Technological Innovations </em> (STI), an international journal for cutting-edge research across the scientific and technological spectrum.","tags":["Academic Publishing","ARPHA Platform","Interdisciplinary Research","New Journal","Scientific Innovation"],"title":"New Journal of Scientific and Technological Innovations launches on ARPHA","updated_at":1790604910,"url":"https://blog.pensoft.net/2026/09/28/new-journal-of-scientific-and-technological-innovations-launches-on-arpha/","version":"v1"},{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p>In these notes, I will show you how to use {ggplot} to create a waffle chart about the frequency of disease outbreaks in the world. The final output will look like this:</p>\n<p><a class=\"lightbox\" data-gallery=\"quarto-lightbox-gallery-1\" href=\"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks//waffle-pandemics.png\"><img class=\"img-fluid\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/waffle-pandemics.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:100.0%\"/></a></p>\n</section><section class=\"level2\" id=\"about-the-data\"><h2 class=\"anchored\" data-anchor-id=\"about-the-data\">About the data</h2>\n<p>The source of information is the global dataset of pandemic- and epidemic-prone disease outbreaks, whose data is freely available at the <a href=\"https://github.com/jatorresmunguia/disease_outbreak_news\" target=\"_blank\">GitHub repository</a> of the <strong>disease outbreaks project</strong>.</p>\n<p>The unit of analysis in the database is an outbreak, defined as the occurrence of at least one case of a specific disease in a country -or territory- during a particular year. Therefore, a country -or territory- cannot have more than one outbreak of the same disease in the same year, although it may experience outbreaks of different diseases within the same year. A country can only have multiple outbreaks of the same disease if they occur in different years.</p>\n<p>The dataset includes information on over 3,000 pandemic- and epidemic-prone disease outbreaks associated with more than 80 different infectious diseases, occurring globally from January 1996 to the present. The diseases are classified according to the International Classification of Diseases, 10th Revision (ICD-10), and the dataset contains information on the year, country, and disease for each outbreak.</p>\n<p>The dataset of pandemic- and epidemic-prone disease outbreaks is also part of the <a href=\"https://data.humdata.org/\">Humanitarian Data Exchange</a> coordinated by the United Nations Office for the Coordination of Humanitarian Affairs (OCHA).</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>To create the waffle chart, we will use the following R packages:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Tidy data analysis framework</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org\">readxl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read Excel files</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/\">httr</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Perform HTTP requests</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://github.com/yixuan/showtext\">showtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add custom fonts to plots</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/\">ggtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Use rich text elements in ggplot</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">waffle</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create waffle charts</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"loading-data-from-github\"><h2 class=\"anchored\" data-anchor-id=\"loading-data-from-github\">Loading data from GitHub</h2>\n<p>The dataset is stored in an Excel. We will download it from the <a href=\"https://github.com/jatorresmunguia/disease_outbreak_news/raw/refs/heads/main/Humanitarian%20Data%20Exchange/data_2_share/disease_outbreaks_HDX.xlsx\">GitHub repository</a> and load it into R:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define the GitHub raw content URL</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">link_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://github.com/jatorresmunguia/disease_outbreak_news/raw/refs/heads/main/Humanitarian%20Data%20Exchange/data_2_share/disease_outbreaks_HDX.xlsx\"</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a temporary file to store the data</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/tempfile.html\">tempfile</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fileext <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\".xlsx\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Download the data from GitHub using authentication</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">get_req</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/GET.html\">GET</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">link_data</span>,</span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/authenticate.html\">authenticate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/Sys.getenv.html\">Sys.getenv</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"GITHUB_PAT\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/write_disk.html\">write_disk</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>path <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read the Excel file into R</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org/reference/read_excel.html\">read_excel</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<section class=\"level3\" id=\"data-wrangling\"><h3 class=\"anchored\" data-anchor-id=\"data-wrangling\">Data wrangling</h3>\n<p>We will group the data by year and disease, and then filter the top 10 diseases from 1996 to 2024. We will also group the data by year and disease, and then filter the top 10 diseases from 2015 to 2024. Finally, we will create a factor variable for the top 10 diseases and the \"Other\" category:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Top 10 diseases 1996-2024</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">top_10_icd104n</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2025</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>freq <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/context.html\">n</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, .groups <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"drop\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/arrange.html\">arrange</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">freq</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/slice.html\">slice_head</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Only top-10 categories and Others</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks_year_disease_grouped</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2025</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&amp;</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&gt;</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2014</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>icd104n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/ifelse.html\">ifelse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/match.html\">%in%</a></span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">top_10_icd104n</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Other\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Group the diseases</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>freq <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/context.html\">n</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, .groups <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"drop\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Count the number of outbreaks</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/arrange.html\">arrange</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">freq</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a factor variable for the top 10 diseases and the \"Other\" category</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks_year_disease_grouped</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks_year_disease_grouped</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>icd104n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/factor.html\">factor</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span>,</span>\n<span>    levels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Acute poliomyelitis, unspecified\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Classical cholera\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"COVID-19, virus identified\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Dengue, unspecified\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Influenza due to identified zoonotic or pandemic influenza virus\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Measles\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Meningococcal meningitis\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Middle East respiratory syndrome coronavirus [MERS-CoV]\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Monkeypox\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Yellow fever, unspecified\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Other\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    labels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Acute poliomyelitis\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Cholera\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"COVID-19\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Dengue\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Influenza\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Measles\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Meningococcal meningitis\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"MERS-CoV\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Monkeypox\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Yellow fever\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Other\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section></section><section class=\"level2\" id=\"set-theme-settings-and-define-fonts-colors-and-text-to-be-used-in-the-waffle-chart\"><h2 class=\"anchored\" data-anchor-id=\"set-theme-settings-and-define-fonts-colors-and-text-to-be-used-in-the-waffle-chart\">Set theme settings and define fonts, colors, and text to be used in the waffle chart</h2>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add custom font</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/sysfonts/man/font_add_google.html\">font_add_google</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme for the waffle chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">theme_waffle_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\">function</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">{</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Base theme with custom font</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme settings</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Axis settings</span></span>\n<span>      axis.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Remove axis title</span></span>\n<span>      axis.line <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Remove axis line</span></span>\n<span>      </span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title settings</span></span>\n<span>      plot.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Position of the title</span></span>\n<span>      plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">24</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Top, right, bottom, left</span></span>\n<span>        width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Width of the title, npc == 1 corresponds to the full width of the plot</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      </span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Subtitle settings</span></span>\n<span>      plot.subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey50\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      </span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Legend settings</span></span>\n<span>      legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"top\"</span>,</span>\n<span>      legend.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.spacing.x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.2</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.spacing <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Spacing between legend keys</span></span>\n<span>      legend.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">9</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.direction <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"horizontal\"</span>,</span>\n<span>      legend.byrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span>,</span>\n<span>      </span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Caption settings</span></span>\n<span>      plot.caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_markdown.html\">element_markdown</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey70\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">8</span>,</span>\n<span>        hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span></span>\n<span>          <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.caption.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>,</span>\n<span></span>\n<span>      plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>,</span>\n<span>        fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">}</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title, subtitle, and caption for the waffle chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Pandemic- and epidemic-prone disease outbreaks in the world\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"In 2024, fewer countries reported public health events linked to COVID-19, while outbreaks of viral diseases transmitted by vectors increased\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Note:** Each square represents a country.\"</span>,</span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"&lt;br&gt;\"</span>, </span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Data:** A global dataset of pandemic- and epidemic-prone disease outbreaks (DOI: 10.1038/s41597-022-01797-2)\"</span>,</span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"&lt;br&gt;\"</span>, </span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Graphic:** Juan Torres Mungu\u00eda\"</span></span>\n<span>                        <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define the colors to be used in the waffle chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">colors</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#B66DFF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#7e0021\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#ff420e\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#579d1c\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#83caff\"</span>,</span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#0084d1\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#aecf00\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#4b1f6f\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FF86FF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#ffd320\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey80\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"create-the-waffle-chart\"><h2 class=\"anchored\" data-anchor-id=\"create-the-waffle-chart\">Create the waffle chart</h2>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">outbreaks_year_disease_grouped</span>,</span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span>, values <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">freq</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/waffle/man/geom_waffle.html\">geom_waffle</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.25</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Size of the waffle squares</span></span>\n<span>    n_rows <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Number of rows in the waffle chart</span></span>\n<span>    flip <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Flip the waffle chart</span></span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Color of the border of the waffle squares</span></span>\n<span>    make_proportional <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Do not make the waffle chart proportional</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/facet_wrap.html\">facet_wrap</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Facet the waffle chart by year</span></span>\n<span>             nrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>             strip.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bottom\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Position of the facet strip</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_manual.html\">scale_fill_manual</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>values <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_discrete.html\">scale_x_discrete</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_continuous.html\">scale_y_continuous</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    labels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\">function</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>,</span>\n<span>    expand <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Expand the y-axis</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/coord_fixed.html\">coord_equal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Total number of outbreaks\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guides.html\">guides</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guide_legend.html\">guide_legend</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>nrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Number of rows in the legend</span></span>\n<span>                             <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> </span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">theme_waffle_chart</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"save-the-waffle-chart-as-an-image\"><h2 class=\"anchored\" data-anchor-id=\"save-the-waffle-chart-as-an-image\">Save the waffle chart as an image</h2>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb6\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_opts.html\">showtext_opts</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set the resolution of the image 320 dpi is for high-quality images (\"retina\")</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsave.html\">ggsave</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"waffle-pandemics.png\"</span>,</span>\n<span>  dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span>,</span>\n<span>  width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span>,</span>\n<span>  height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">7</span>,</span>\n<span>  units <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"in\"</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {A Waffle Chart of Disease Outbreaks in the World},\n  date = {2025-01-12},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"A Waffle Chart of Disease\nOutbreaks in the World.\"</span> January 12, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/\">https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/kg492-0rv24","guid":"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/","image":"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/waffle-pandemics.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1736640000,"rid":"28aw9-1vm92","summary":"Overview In these notes, I will show you how to use {ggplot} to create a waffle chart about the frequency of disease outbreaks in the world.","tags":["Data Visualization","Disease Outbreaks","Epidemics","Pandemics","Tidyverse"],"title":"A waffle chart of disease outbreaks in the world","updated_at":1790603826,"url":"https://juan-torresmunguia.netlify.app/blog/posts/waffle-chart-disease-outbreaks/","version":"v1"},{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p>In this article, I will guide you through the process of analyzing Mexico's 2024 National Survey of Victimization and Perception of Public Safety (<em>Encuesta Nacional de Victimizaci\u00f3n y Percepci\u00f3n sobre Seguridad P\u00fablica</em>, ENVIPE) using the <a href=\"https://www.tidyverse.org/\">{tidyverse}</a> framework for survey analysis with the {srvyr} package. Specifically, we will calculate the <strong>crime prevalence rate per 100,000 inhabitants by state, according to the victim's sex</strong> ( <em>Tasa de prevalencia delictiva por entidad federativa por cada cien mil habitantes, seg\u00fan sexo de la v\u00edctima</em>).</p>\n<p>Official tables with this indicator can be found <a href=\"https://www.inegi.org.mx/programas/envipe/2024/#tabulados\">here</a>.</p>\n<p>By the end of this article, you will be able to use the {tidyverse} to:</p>\n<ul>\n<li>Load the survey microdata from INEGI's website.</li>\n<li>Specify the ENVIPE survey design.</li>\n<li>Calculate crime prevalence indicators.</li>\n</ul></section><section class=\"level2\" id=\"about-the-envipe\"><h2 class=\"anchored\" data-anchor-id=\"about-the-envipe\">About the ENVIPE</h2>\n<p>ENVIPE is an official survey that provides nationally and state-representative information on household crime victimization and perceptions of public safety in Mexico. Conducted annually since 2011 by the <a href=\"https://www.inegi.org.mx/default.html\">National Institute of Statistics and Geography (INEGI)</a>, ENVIPE collects data on the following crimes:</p>\n<div class=\"columns\">\n<div class=\"column\" style=\"width:50%;\">\n<ul>\n<li>Total vehicle theft (car, pickup truck, or truck).</li>\n<li>Theft of vehicle accessories, spare parts, or tools (car, pickup truck, or truck).</li>\n<li>Wall graffiti, intentional vehicle damage, and other types of vandalism.</li>\n<li>Burglary or attempted burglary.</li>\n<li>Kidnapping.</li>\n<li>Enforced disappearance.</li>\n<li>Homicide.</li>\n<li>Robbery or assault on the street or public transportation.</li>\n</ul>\n</div><div class=\"column\" style=\"width:50%;\">\n<ul>\n<li>Theft in a manner different from the above.</li>\n<li>Bank fraud.</li>\n<li>Consumer fraud.</li>\n<li>Extortion.</li>\n<li>Threats.</li>\n<li>Injuries.</li>\n<li>Kidnapping.</li>\n<li>Harassment or intimidation.</li>\n<li>Groping.</li>\n<li>Exhibitionism.</li>\n<li>Attempted rape.</li>\n<li>Sexual rape.</li>\n<li>Other crimes.</li>\n</ul>\n</div>\n</div>\n<p>All survey-related information, including questionnaires, methodology, glossaries, summaries, and microdata, is fully available at <a href=\"https://en.www.inegi.org.mx/programas/envipe/2024/\">INEGI's website</a>.</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>First, install and load the required packages:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Tidy data analysis framework</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://gdfe.co/srvyr/\">srvyr</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Tidy syntax for survey data analysis</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://archive.r-lib.org/\">archive</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Extract files from a ZIP archive</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://haozhu233.github.io/kableExtra/\">kableExtra</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create HTML table</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"loading-survey-microdata-from-inegi\"><h2 class=\"anchored\" data-anchor-id=\"loading-survey-microdata-from-inegi\">Loading survey microdata from INEGI</h2>\n<p>Microdata is available <a href=\"https://www.inegi.org.mx/programas/envipe/2024/#microdatos\">here</a> in various formats (CSV, DBF, DTA, SAV, and RData). In this post, we will use the RData files.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/load.html\">load</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://archive.r-lib.org/reference/archive_read.html\">archive_read</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  archive <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://www.inegi.org.mx/contenidos/programas/envipe/2024/microdatos/bd_envipe_2024_RData.zip\"</span>,</span>\n<span>  file <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"BD_ENVIPE_2024.RData\"</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<div class=\"callout callout-style-default callout-tip callout-titled\">\n<div class=\"callout-header d-flex align-content-center\">\n<div class=\"callout-icon-container\">\n<i class=\"callout-icon\"></i>\n</div>\n<div class=\"callout-title-container flex-fill\">\nTip\n</div>\n</div>\n<div class=\"callout-body-container callout-body\">\n<p>Using the {archive} package, we can directly extract the required file from <code>bd_envipe_2024_RData.zip</code>.</p>\n</div>\n</div>\n<p>This loads the following objects into the global environment:</p>\n<ul>\n<li><p><code>THogar</code>: This object contains the interview result, the row of the selected respondent, the household factor, and other household characteristics.</p></li>\n<li><p><code>TMod_Vic</code>: This object includes information on the crimes suffered by the selected respondent and their household during the reference year, specifically during 2023. Information comes from the victimization module of the survey.</p></li>\n<li><p><code>TPer_Vic1</code>: This object includes information related to the perception of public security within the respondent's geographic area, antisocial behaviors in their immediate surroundings, and changes in habits due to fear of becoming a crime victim in 2023. Additionally, it presents information regarding the performance of authorities and trust in them. In other words, this table covers Sections IV and V of the main questionnaire.</p></li>\n<li><p><code>TPer_Vic2</code>: This object consolidates information related to household and personal victimization, particularly focusing on high-impact crimes experienced by the household (such as kidnapping, enforced disappearance, or homicide) or by the selected respondent. This table includes Sections VI and VII of the main questionnaire.</p></li>\n<li><p><code>TSDem</code>: This object contains the socio-demographic characteristics of household members, corresponding to Section III of the main questionnaire.</p></li>\n<li><p><code>TSVivienda</code>: This object contains the characteristics of the households captured through the questionnaire cover page, as well as the count of household residents and the number of households. In other words, it includes Sections I and II of the main questionnaire.</p></li>\n</ul></section><section class=\"level2\" id=\"calculating-crime-prevalence-rate-per-100000-thousand-inhabitants-by-state-according-to-the-victims-sex\"><h2 class=\"anchored\" data-anchor-id=\"calculating-crime-prevalence-rate-per-100000-thousand-inhabitants-by-state-according-to-the-victims-sex\">Calculating crime prevalence rate per 100,000 thousand inhabitants by state, according to the victim's sex</h2>\n<p>To estimate the crime prevalence rate, we use information from <code>TPer_Vic2</code> (screening questions on victimization from the main questionnaire) and <code>TMod_Vic</code> (specific victimization module applied to the respondents who reported being a victim of at least one of the crimes included in the survey during the reference period). <code>TPer_Vic2</code> will serve to characterize the total population and <code>TMod_Vic</code> to describe the victims and the associated crimes.</p>\n<section class=\"level3\" id=\"specifying-the-envipe-survey-design\"><h3 class=\"anchored\" data-anchor-id=\"specifying-the-envipe-survey-design\">1. Specifying the ENVIPE survey design</h3>\n<p>ENVIPE follows a probabilistic, three-stage, stratified, and clustered sampling design. The sampling unit is the household, while the unit of analysis is the population aged 18 and older in selected households. More details on the sampling design can be found <a href=\"https://www.inegi.org.mx/contenidos/productos/prod_serv/contenidos/espanol/bvinegi/productos/nueva_estruc/889463920014.pdf\">here</a>(in Spanish).</p>\n<p>From the documentation on <a href=\"https://www.inegi.org.mx/contenidos/programas/envipe/2024/doc/fd_envipe2024.pdf\">data structure</a>(in Spanish), the key variables for specifying the survey design are:</p>\n<ul>\n<li><p><code>ID_PER</code>: Person identifier</p></li>\n<li><p><code>EST_DIS</code>: Stratum</p></li>\n<li><p><code>UPM_DIS</code>: Primary sampling unit</p></li>\n<li><p><code>FAC_ELE</code>: Weighting factor for public security perception and victimization estimates.</p></li>\n</ul>\n<p>We specify the survey design as follows:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Identify victims from TMod_Vic, excluding</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># \"Wall graffiti, intentional vehicle damage, and other vandalism\" (BPCOD != \"03\")</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">id_victims</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TMod_Vic</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">BPCOD</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">!=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"03\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/pull.html\">pull</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ID_PER</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create victimization variable in TPer_Vic2</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>victimization <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/ifelse.html\">ifelse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ID_PER</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/match.html\">%in%</a></span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">id_victims</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Convert FAC_ELE (weights) to numeric</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>FAC_ELE <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/numeric.html\">as.numeric</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">FAC_ELE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Label SEXO variable</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>SEXO <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/recode.html\">recode</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">SEXO</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"1\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Man\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"2\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Woman\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create survey object</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">envipe_design</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">TPer_Vic2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://gdfe.co/srvyr/reference/as_survey_design.html\">as_survey_design</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    weights <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">FAC_ELE</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Weights (inverse probability)</span></span>\n<span>    strata <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">EST_DIS</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Stratum</span></span>\n<span>    ids <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">UPM_DIS</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Primary sampling unit</span></span>\n<span>    nest <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Nesting within strata</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level3\" id=\"calculating-point-estimates-and-variablity-indicators\"><h3 class=\"anchored\" data-anchor-id=\"calculating-point-estimates-and-variablity-indicators\">2. Calculating point estimates and variablity indicators</h3>\n<p>To compute proportions from survey data, we use <code><a href=\"http://gdfe.co/srvyr/reference/survey_mean.html\">survey_mean()</a></code> from {srvyr} package. From ENVIPE's documentation, we know that <code>NOM_ENT</code> represents the state, while <code>SEXO</code> corresponds to the respondent's sex.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">envipe_design</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># `interact` function is used to calculate the proportion</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># over the interaction of state and sex</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://gdfe.co/srvyr/reference/interact.html\">interact</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">NOM_ENT</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">SEXO</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarize</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    Proportion <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://gdfe.co/srvyr/reference/survey_mean.html\">survey_mean</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">victimization</span>,</span>\n<span>      level <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.90</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Confidence level</span></span>\n<span>      vartype <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"se\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"ci\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cv\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Variability indicators</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">ungroup</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    `Prevalence rate` <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Proportion</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">100000</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rate per 100,000 people</span></span>\n<span>    `Standard error` <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Proportion_se</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">100000</span>,</span>\n<span>    `Low 90% CI` <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Proportion_low</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">100000</span>,</span>\n<span>    `Upper 90% CI` <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Proportion_upp</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">100000</span>,</span>\n<span>    `Coefficient of variation %` <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Proportion_cv</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">*</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">100</span>,</span>\n<span>    State <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/case.html\">str_to_sentence</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">NOM_ENT</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Capitalize only the first letter</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>Sex <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">SEXO</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">State</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Sex</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Prevalence rate`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Standard error`</span>,</span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Low 90% CI`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Upper 90% CI`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Coefficient of variation %`</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/kableExtra/man/kbl.html\">kbl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># HTML table</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/kableExtra/man/kable_styling.html\">kable_styling</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Apply bootstrap theme to the table</span></span></code></pre></div></div>\n</div>\n<p>The output table looks like this:</p>\n<div class=\"cell\">\n<div class=\"cell-output-display\">\n<table class=\"table caption-top table-sm table-striped small\">\n<thead><tr class=\"header\">\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: left;\">State</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: left;\">Sex</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Prevalence rate</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Standard error</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Low 90% CI</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Upper 90% CI</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Coefficient of variation %</th>\n</tr></thead>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Aguascalientes</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">33710.81</td>\n<td style=\"text-align: right;\">2172.7372</td>\n<td style=\"text-align: right;\">30136.71</td>\n<td style=\"text-align: right;\">37284.91</td>\n<td style=\"text-align: right;\">6.445224</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Aguascalientes</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">32041.57</td>\n<td style=\"text-align: right;\">1831.7081</td>\n<td style=\"text-align: right;\">29028.45</td>\n<td style=\"text-align: right;\">35054.68</td>\n<td style=\"text-align: right;\">5.716662</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Baja California</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">23043.35</td>\n<td style=\"text-align: right;\">1604.9769</td>\n<td style=\"text-align: right;\">20403.20</td>\n<td style=\"text-align: right;\">25683.50</td>\n<td style=\"text-align: right;\">6.965032</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Baja California</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">24480.64</td>\n<td style=\"text-align: right;\">1536.1771</td>\n<td style=\"text-align: right;\">21953.66</td>\n<td style=\"text-align: right;\">27007.61</td>\n<td style=\"text-align: right;\">6.275070</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Baja California Sur</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">19329.94</td>\n<td style=\"text-align: right;\">1244.1353</td>\n<td style=\"text-align: right;\">17283.36</td>\n<td style=\"text-align: right;\">21376.51</td>\n<td style=\"text-align: right;\">6.436314</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Baja California Sur</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">23817.58</td>\n<td style=\"text-align: right;\">1466.2963</td>\n<td style=\"text-align: right;\">21405.56</td>\n<td style=\"text-align: right;\">26229.60</td>\n<td style=\"text-align: right;\">6.156361</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Campeche</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">21832.87</td>\n<td style=\"text-align: right;\">1455.8508</td>\n<td style=\"text-align: right;\">19438.03</td>\n<td style=\"text-align: right;\">24227.71</td>\n<td style=\"text-align: right;\">6.668161</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Campeche</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">23213.74</td>\n<td style=\"text-align: right;\">1381.0933</td>\n<td style=\"text-align: right;\">20941.88</td>\n<td style=\"text-align: right;\">25485.61</td>\n<td style=\"text-align: right;\">5.949465</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Chiapas</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">16602.99</td>\n<td style=\"text-align: right;\">986.0052</td>\n<td style=\"text-align: right;\">14981.03</td>\n<td style=\"text-align: right;\">18224.94</td>\n<td style=\"text-align: right;\">5.938722</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Chiapas</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">12074.36</td>\n<td style=\"text-align: right;\">978.7862</td>\n<td style=\"text-align: right;\">10464.28</td>\n<td style=\"text-align: right;\">13684.44</td>\n<td style=\"text-align: right;\">8.106318</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Chihuahua</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">22303.22</td>\n<td style=\"text-align: right;\">1234.5065</td>\n<td style=\"text-align: right;\">20272.49</td>\n<td style=\"text-align: right;\">24333.96</td>\n<td style=\"text-align: right;\">5.535103</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Chihuahua</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">22804.31</td>\n<td style=\"text-align: right;\">1181.0327</td>\n<td style=\"text-align: right;\">20861.54</td>\n<td style=\"text-align: right;\">24747.08</td>\n<td style=\"text-align: right;\">5.178990</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Ciudad De Mexico</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">34562.66</td>\n<td style=\"text-align: right;\">1089.2714</td>\n<td style=\"text-align: right;\">32770.84</td>\n<td style=\"text-align: right;\">36354.49</td>\n<td style=\"text-align: right;\">3.151584</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Ciudad De Mexico</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">30746.76</td>\n<td style=\"text-align: right;\">990.3528</td>\n<td style=\"text-align: right;\">29117.66</td>\n<td style=\"text-align: right;\">32375.87</td>\n<td style=\"text-align: right;\">3.220999</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Coahuila De Zaragoza</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">18179.70</td>\n<td style=\"text-align: right;\">1249.1422</td>\n<td style=\"text-align: right;\">16124.89</td>\n<td style=\"text-align: right;\">20234.51</td>\n<td style=\"text-align: right;\">6.871084</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Coahuila De Zaragoza</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">20447.19</td>\n<td style=\"text-align: right;\">1238.7111</td>\n<td style=\"text-align: right;\">18409.54</td>\n<td style=\"text-align: right;\">22484.84</td>\n<td style=\"text-align: right;\">6.058099</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Colima</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">21106.85</td>\n<td style=\"text-align: right;\">1593.5970</td>\n<td style=\"text-align: right;\">18485.43</td>\n<td style=\"text-align: right;\">23728.28</td>\n<td style=\"text-align: right;\">7.550140</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Colima</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">21295.28</td>\n<td style=\"text-align: right;\">1351.1455</td>\n<td style=\"text-align: right;\">19072.68</td>\n<td style=\"text-align: right;\">23517.88</td>\n<td style=\"text-align: right;\">6.344813</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Durango</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">15240.74</td>\n<td style=\"text-align: right;\">1133.1868</td>\n<td style=\"text-align: right;\">13376.67</td>\n<td style=\"text-align: right;\">17104.80</td>\n<td style=\"text-align: right;\">7.435250</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Durango</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">17401.18</td>\n<td style=\"text-align: right;\">1166.0910</td>\n<td style=\"text-align: right;\">15482.99</td>\n<td style=\"text-align: right;\">19319.37</td>\n<td style=\"text-align: right;\">6.701219</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Guanajuato</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">20057.38</td>\n<td style=\"text-align: right;\">1428.0981</td>\n<td style=\"text-align: right;\">17708.20</td>\n<td style=\"text-align: right;\">22406.57</td>\n<td style=\"text-align: right;\">7.120063</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Guanajuato</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">18930.15</td>\n<td style=\"text-align: right;\">1287.0811</td>\n<td style=\"text-align: right;\">16812.93</td>\n<td style=\"text-align: right;\">21047.37</td>\n<td style=\"text-align: right;\">6.799107</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Guerrero</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">16981.89</td>\n<td style=\"text-align: right;\">1494.6554</td>\n<td style=\"text-align: right;\">14523.22</td>\n<td style=\"text-align: right;\">19440.56</td>\n<td style=\"text-align: right;\">8.801466</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Guerrero</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">14572.44</td>\n<td style=\"text-align: right;\">1238.6234</td>\n<td style=\"text-align: right;\">12534.93</td>\n<td style=\"text-align: right;\">16609.94</td>\n<td style=\"text-align: right;\">8.499769</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Hidalgo</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">22397.82</td>\n<td style=\"text-align: right;\">1338.0474</td>\n<td style=\"text-align: right;\">20196.77</td>\n<td style=\"text-align: right;\">24598.88</td>\n<td style=\"text-align: right;\">5.974006</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Hidalgo</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">20215.02</td>\n<td style=\"text-align: right;\">1157.0294</td>\n<td style=\"text-align: right;\">18311.73</td>\n<td style=\"text-align: right;\">22118.30</td>\n<td style=\"text-align: right;\">5.723613</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Jalisco</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">24390.13</td>\n<td style=\"text-align: right;\">1548.7916</td>\n<td style=\"text-align: right;\">21842.40</td>\n<td style=\"text-align: right;\">26937.85</td>\n<td style=\"text-align: right;\">6.350076</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Jalisco</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">25141.90</td>\n<td style=\"text-align: right;\">1438.5170</td>\n<td style=\"text-align: right;\">22775.58</td>\n<td style=\"text-align: right;\">27508.23</td>\n<td style=\"text-align: right;\">5.721592</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Mexico</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">32906.59</td>\n<td style=\"text-align: right;\">1632.3183</td>\n<td style=\"text-align: right;\">30221.47</td>\n<td style=\"text-align: right;\">35591.71</td>\n<td style=\"text-align: right;\">4.960460</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Mexico</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">33023.78</td>\n<td style=\"text-align: right;\">1483.3471</td>\n<td style=\"text-align: right;\">30583.71</td>\n<td style=\"text-align: right;\">35463.85</td>\n<td style=\"text-align: right;\">4.491755</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Michoacan De Ocampo</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">14405.17</td>\n<td style=\"text-align: right;\">1031.1125</td>\n<td style=\"text-align: right;\">12709.01</td>\n<td style=\"text-align: right;\">16101.32</td>\n<td style=\"text-align: right;\">7.157934</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Michoacan De Ocampo</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">15485.20</td>\n<td style=\"text-align: right;\">1036.3320</td>\n<td style=\"text-align: right;\">13780.46</td>\n<td style=\"text-align: right;\">17189.94</td>\n<td style=\"text-align: right;\">6.692401</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Morelos</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">26995.43</td>\n<td style=\"text-align: right;\">1517.6054</td>\n<td style=\"text-align: right;\">24499.00</td>\n<td style=\"text-align: right;\">29491.85</td>\n<td style=\"text-align: right;\">5.621713</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Morelos</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">24869.74</td>\n<td style=\"text-align: right;\">1688.5969</td>\n<td style=\"text-align: right;\">22092.04</td>\n<td style=\"text-align: right;\">27647.44</td>\n<td style=\"text-align: right;\">6.789765</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Nayarit</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">16075.56</td>\n<td style=\"text-align: right;\">1516.6195</td>\n<td style=\"text-align: right;\">13580.76</td>\n<td style=\"text-align: right;\">18570.36</td>\n<td style=\"text-align: right;\">9.434318</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Nayarit</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">18639.61</td>\n<td style=\"text-align: right;\">1597.1842</td>\n<td style=\"text-align: right;\">16012.28</td>\n<td style=\"text-align: right;\">21266.94</td>\n<td style=\"text-align: right;\">8.568766</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Nuevo Leon</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">23602.12</td>\n<td style=\"text-align: right;\">1261.9498</td>\n<td style=\"text-align: right;\">21526.25</td>\n<td style=\"text-align: right;\">25678.00</td>\n<td style=\"text-align: right;\">5.346764</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Nuevo Leon</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">21440.72</td>\n<td style=\"text-align: right;\">1211.6372</td>\n<td style=\"text-align: right;\">19447.60</td>\n<td style=\"text-align: right;\">23433.83</td>\n<td style=\"text-align: right;\">5.651104</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Oaxaca</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">12940.56</td>\n<td style=\"text-align: right;\">1158.2366</td>\n<td style=\"text-align: right;\">11035.29</td>\n<td style=\"text-align: right;\">14845.83</td>\n<td style=\"text-align: right;\">8.950434</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Oaxaca</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">13548.61</td>\n<td style=\"text-align: right;\">1017.7020</td>\n<td style=\"text-align: right;\">11874.51</td>\n<td style=\"text-align: right;\">15222.70</td>\n<td style=\"text-align: right;\">7.511489</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Puebla</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">26519.64</td>\n<td style=\"text-align: right;\">1342.0473</td>\n<td style=\"text-align: right;\">24312.00</td>\n<td style=\"text-align: right;\">28727.27</td>\n<td style=\"text-align: right;\">5.060579</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Puebla</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">24176.45</td>\n<td style=\"text-align: right;\">1124.4656</td>\n<td style=\"text-align: right;\">22326.73</td>\n<td style=\"text-align: right;\">26026.17</td>\n<td style=\"text-align: right;\">4.651078</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Queretaro</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">30297.50</td>\n<td style=\"text-align: right;\">1620.6534</td>\n<td style=\"text-align: right;\">27631.57</td>\n<td style=\"text-align: right;\">32963.44</td>\n<td style=\"text-align: right;\">5.349132</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Queretaro</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">25746.31</td>\n<td style=\"text-align: right;\">1260.3524</td>\n<td style=\"text-align: right;\">23673.06</td>\n<td style=\"text-align: right;\">27819.56</td>\n<td style=\"text-align: right;\">4.895273</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Quintana Roo</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">22592.04</td>\n<td style=\"text-align: right;\">1384.4250</td>\n<td style=\"text-align: right;\">20314.70</td>\n<td style=\"text-align: right;\">24869.39</td>\n<td style=\"text-align: right;\">6.127932</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Quintana Roo</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">21775.64</td>\n<td style=\"text-align: right;\">1237.8095</td>\n<td style=\"text-align: right;\">19739.48</td>\n<td style=\"text-align: right;\">23811.81</td>\n<td style=\"text-align: right;\">5.684376</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">San Luis Potosi</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">24019.02</td>\n<td style=\"text-align: right;\">1874.7438</td>\n<td style=\"text-align: right;\">20935.11</td>\n<td style=\"text-align: right;\">27102.93</td>\n<td style=\"text-align: right;\">7.805247</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">San Luis Potosi</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">23227.97</td>\n<td style=\"text-align: right;\">1491.3111</td>\n<td style=\"text-align: right;\">20774.80</td>\n<td style=\"text-align: right;\">25681.14</td>\n<td style=\"text-align: right;\">6.420324</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Sinaloa</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">21181.44</td>\n<td style=\"text-align: right;\">1122.0160</td>\n<td style=\"text-align: right;\">19335.76</td>\n<td style=\"text-align: right;\">23027.13</td>\n<td style=\"text-align: right;\">5.297165</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Sinaloa</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">20562.22</td>\n<td style=\"text-align: right;\">1086.2790</td>\n<td style=\"text-align: right;\">18775.32</td>\n<td style=\"text-align: right;\">22349.12</td>\n<td style=\"text-align: right;\">5.282887</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Sonora</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">26864.66</td>\n<td style=\"text-align: right;\">1816.2677</td>\n<td style=\"text-align: right;\">23876.94</td>\n<td style=\"text-align: right;\">29852.37</td>\n<td style=\"text-align: right;\">6.760808</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Sonora</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">25742.16</td>\n<td style=\"text-align: right;\">1902.0264</td>\n<td style=\"text-align: right;\">22613.37</td>\n<td style=\"text-align: right;\">28870.95</td>\n<td style=\"text-align: right;\">7.388759</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Tabasco</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">25881.72</td>\n<td style=\"text-align: right;\">1354.6212</td>\n<td style=\"text-align: right;\">23653.40</td>\n<td style=\"text-align: right;\">28110.04</td>\n<td style=\"text-align: right;\">5.233891</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Tabasco</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">25522.45</td>\n<td style=\"text-align: right;\">1091.8488</td>\n<td style=\"text-align: right;\">23726.38</td>\n<td style=\"text-align: right;\">27318.51</td>\n<td style=\"text-align: right;\">4.277994</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Tamaulipas</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">17788.15</td>\n<td style=\"text-align: right;\">1075.8038</td>\n<td style=\"text-align: right;\">16018.47</td>\n<td style=\"text-align: right;\">19557.82</td>\n<td style=\"text-align: right;\">6.047869</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Tamaulipas</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">18368.67</td>\n<td style=\"text-align: right;\">1017.1639</td>\n<td style=\"text-align: right;\">16695.46</td>\n<td style=\"text-align: right;\">20041.88</td>\n<td style=\"text-align: right;\">5.537493</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Tlaxcala</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">23968.33</td>\n<td style=\"text-align: right;\">1621.2198</td>\n<td style=\"text-align: right;\">21301.47</td>\n<td style=\"text-align: right;\">26635.20</td>\n<td style=\"text-align: right;\">6.764007</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Tlaxcala</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">22295.82</td>\n<td style=\"text-align: right;\">1473.2391</td>\n<td style=\"text-align: right;\">19872.38</td>\n<td style=\"text-align: right;\">24719.26</td>\n<td style=\"text-align: right;\">6.607692</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Veracruz De Ignacio De La Llave</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">16365.05</td>\n<td style=\"text-align: right;\">1055.8247</td>\n<td style=\"text-align: right;\">14628.24</td>\n<td style=\"text-align: right;\">18101.86</td>\n<td style=\"text-align: right;\">6.451705</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Veracruz De Ignacio De La Llave</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">14712.45</td>\n<td style=\"text-align: right;\">947.9121</td>\n<td style=\"text-align: right;\">13153.15</td>\n<td style=\"text-align: right;\">16271.74</td>\n<td style=\"text-align: right;\">6.442927</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Yucatan</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">20677.82</td>\n<td style=\"text-align: right;\">1239.0909</td>\n<td style=\"text-align: right;\">18639.55</td>\n<td style=\"text-align: right;\">22716.10</td>\n<td style=\"text-align: right;\">5.992366</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Yucatan</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">17805.62</td>\n<td style=\"text-align: right;\">1141.8291</td>\n<td style=\"text-align: right;\">15927.34</td>\n<td style=\"text-align: right;\">19683.90</td>\n<td style=\"text-align: right;\">6.412745</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Zacatecas</td>\n<td style=\"text-align: left;\">Man</td>\n<td style=\"text-align: right;\">17328.49</td>\n<td style=\"text-align: right;\">1346.8466</td>\n<td style=\"text-align: right;\">15112.96</td>\n<td style=\"text-align: right;\">19544.02</td>\n<td style=\"text-align: right;\">7.772440</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Zacatecas</td>\n<td style=\"text-align: left;\">Woman</td>\n<td style=\"text-align: right;\">15690.25</td>\n<td style=\"text-align: right;\">1335.9463</td>\n<td style=\"text-align: right;\">13492.65</td>\n<td style=\"text-align: right;\">17887.85</td>\n<td style=\"text-align: right;\">8.514502</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n</section></section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {Using a Tidy Approach in {R} to Analyze {Mexico's} 2024\n    {ENVIPE}},\n  date = {2025-01-27},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"Using a Tidy Approach in R to\nAnalyze Mexico's 2024 ENVIPE.\"</span> January 27, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/\">https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/a1rrg-n4y36","guid":"https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/","image":"https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/table_envipe.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1737936000,"rid":"e08zs-w2m07","summary":"Overview In this article, I will guide you through the process of analyzing Mexico's 2024 National Survey of Victimization and Perception of Public Safety ( <em> Encuesta Nacional de Victimizaci\u00f3n y Percepci\u00f3n sobre Seguridad P\u00fablica </em> , ENVIPE) using the {tidyverse} framework for survey analysis with the {srvyr} package.","tags":["Data Analysis","Official Statistics","Mexico","Household Surveys","ENVIPE"],"title":"Using a tidy approach in R to analyze Mexico's 2024 ENVIPE","updated_at":1790603821,"url":"https://juan-torresmunguia.netlify.app/blog/posts/estimating-envipe-prevalence/","version":"v1"},{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p>The Standardized Precipitation Index (SPI) quantifies how precipitation deviates from the historical average over multiple time scales (e.g., from 1 to 12 months), allowing for consistent monitoring of droughts and floods across regions and time, making it a valuable tool for early warning and risk assessment systems.</p>\n<p>In this tutorial, I will walk through the process of calculating the SPI for Somalia at the subnational level using the {SCI} package in R.</p>\n</section><section class=\"level2\" id=\"about-the-data\"><h2 class=\"anchored\" data-anchor-id=\"about-the-data\">About the data</h2>\n<p>The rainfall dataset used in this tutorial comes from the <a href=\"https://data.humdata.org/\">Humanitarian Data Exchange (HDX) initiative</a> of the United Nations Office for the Coordination of Humanitarian Affairs (OCHA) and provides monthly precipitation data for Somalia's subnational districts. It is derived from CHIRPS v2 (Climate Hazards Group InfraRed Precipitation with <em>in situ</em> Station data), using satellite imagery combined with ground-based observations.</p>\n<p>For each 10-day period (dekad), the dataset includes the following indicators:</p>\n<ul>\n<li>\n<code>rfh</code>: Total rainfall (mm) over 10 days</li>\n<li>\n<code>r1h</code>: 1-month rolling rainfall sum (mm)</li>\n<li>\n<code>r3h</code>: 3-month rolling rainfall sum (mm)</li>\n<li>\n<code>rfh_avg</code>: Long-term average rainfall for the dekad (mm)</li>\n<li>\n<code>r1h_avg</code>: Long-term average for 1-month rolling rainfall (mm)</li>\n<li>\n<code>r3h_avg</code>: Long-term average for 3-month rolling rainfall (mm)</li>\n<li>\n<code>rfq</code>: Rainfall anomaly (%)</li>\n<li>\n<code>r1q</code>: Rainfall anomaly (%)</li>\n<li>\n<code>r3q</code>: 3-month rainfall anomaly (%)</li>\n</ul>\n<p>The data is aggregated at the subnational level and follows administrative boundaries defined by the World Food Programme (WFP), with each unit assigned a unique code (<code>Pcode</code>).</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>Before we begin, we need to install and load the necessary R packages. We will be using the {tidyverse} package for data wrangling, as well as the {SCI} package for calculating the SPI.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">SCI</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For Standardized Precipitation Index calculations (climate analysis)</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://conflicted.r-lib.org/\">conflicted</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For resolving conflicts between function names in different packages</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://haozhu233.github.io/kableExtra/\">kableExtra</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org\">ggplot2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/\">ggtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://github.com/yixuan/showtext\">showtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://conflicted.r-lib.org/reference/conflicts_prefer.html\">conflicts_prefer</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">dplyr</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">::</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Prefer 'select' function from dplyr package</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://conflicted.r-lib.org/reference/conflicts_prefer.html\">conflicts_prefer</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">dplyr</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">::</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/lead-lag.html\">lag</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Prefer 'lag' function from dplyr package</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://conflicted.r-lib.org/reference/conflicts_prefer.html\">conflicts_prefer</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">dplyr</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">::</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Prefer 'filter' function from dplyr package</span></span></code></pre></div></div>\n</div>\n<div class=\"callout callout-style-default callout-warning callout-titled\">\n<div class=\"callout-header d-flex align-content-center\">\n<div class=\"callout-icon-container\">\n<i class=\"callout-icon\"></i>\n</div>\n<div class=\"callout-title-container flex-fill\">\nWarning\n</div>\n</div>\n<div class=\"callout-body-container callout-body\">\n<p>Important to use {conflicted} package to specify preferred functions to avoid naming conflicts between {tidyverse} and {SCI} packages.</p>\n</div>\n</div>\n</section><section class=\"level2\" id=\"loading-data-hdx\"><h2 class=\"anchored\" data-anchor-id=\"loading-data-hdx\">Loading data HDX</h2>\n<p>Data can be found <a href=\"https://data.humdata.org/dataset/som-rainfall-subnational\">here</a> in file <code>som-rainfall-adm2-full.csv</code>. For Somalia, data is available from January 1981.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read the rainfall data for Somalia`</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># You can also download the data from the HDX platform and read it locally</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/utils/read.table.html\">read.csv</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://data.humdata.org/dataset/ed6e1b4b-8094-47e6-bdf7-f6d56fa7abb9/resource/8b333d58-d69e-418c-b5e3-dd86f12eee05/download/som-rainfall-subnat-full.csv\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<section class=\"level3\" id=\"data-wrangling\"><h3 class=\"anchored\" data-anchor-id=\"data-wrangling\">Data wrangling</h3>\n<p>We preprocess the data to extract relevant information to calculate the SPI. We extract the year and month from the date column, calculate the rainfall anomaly, and group the data by year, month, and district_code.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/slice.html\">slice</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Remove the first row (metadata)</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm_level</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    year <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://lubridate.tidyverse.org/reference/year.html\">year</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">date</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Extract year from the 'date' column</span></span>\n<span>    month <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://lubridate.tidyverse.org/reference/month.html\">month</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">date</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Extract month from the 'date' column</span></span>\n<span>    district_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">PCODE</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename the 'ADM2_PCODE' column to 'district_code'</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2025</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Filter data up to 2024</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    rainfall_monthly_total <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rfh</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename the column 'rfh' to 'rainfall_monthly_total'</span></span>\n<span>    rainfall_monthly_lt_average <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rfh_avg</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename the column 'rfh_avg' to 'rainfall_monthly_lt_average'</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    rainfall_monthly_total <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/numeric.html\">as.numeric</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Convert rainfall total to numeric</span></span>\n<span>    rainfall_monthly_lt_average <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/numeric.html\">as.numeric</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_lt_average</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Convert long-term average to numeric</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">district_code</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_lt_average</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select relevant columns</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Group by year, month, and district_code, and calculate mean rainfall values by district</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">district_code</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    rainfall_monthly_total <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/mean.html\">mean</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>, na.rm <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Calculate the mean of rainfall total</span></span>\n<span>    rainfall_monthly_lt_average <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/mean.html\">mean</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_lt_average</span>, na.rm <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Calculate the mean of long-term average</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">ungroup</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Optionally, you can calculate rainfall anomaly as a percentage of the long-term average</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># rainfall_anomaly = 1, indicates no anomaly</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># &lt; 1 indicates below average</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># &gt; 1 indicates above average</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    rainfall_anomaly <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">/</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_lt_average</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section></section><section class=\"level2\" id=\"we-then-calculate-the-spi-for-different-time-scales-1-3-6-12-months.\"><h2 class=\"anchored\" data-anchor-id=\"we-then-calculate-the-spi-for-different-time-scales-1-3-6-12-months.\">We then calculate the SPI for different time scales (1, 3, 6, 12 months).</h2>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">district_code</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Group by district_code</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    spi1 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">transformSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>      first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Start month for SPI calculation</span></span>\n<span>      obj <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">fitSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>        first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Start month for SPI calculation</span></span>\n<span>        time.scale <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Time scale for SPI calculation</span></span>\n<span>        distr <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"gamma\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Distribution for fitting</span></span>\n<span>        p0 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Use initial parameter estimates</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    spi3 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">transformSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>      first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>      obj <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">fitSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>        first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>        time.scale <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>,</span>\n<span>        distr <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"gamma\"</span>,</span>\n<span>        p0 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    spi6 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">transformSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>      first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>      obj <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">fitSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>        first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>        time.scale <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">6</span>,</span>\n<span>        distr <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"gamma\"</span>,</span>\n<span>        p0 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    spi12 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">transformSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>      first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>      obj <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/SCI/man/fitSCI.html\">fitSCI</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_monthly_total</span>,</span>\n<span>        first.mon <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>        time.scale <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>,</span>\n<span>        distr <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"gamma\"</span>,</span>\n<span>        p0 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">ungroup</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/arrange.html\">arrange</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">district_code</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>The output table looks like this:</p>\n<div class=\"cell\">\n<div class=\"cell-output-display\">\n<table class=\"table caption-top table-sm table-striped small\">\n<thead><tr class=\"header\">\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">year</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">month</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: left;\">district_code</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">rainfall_monthly_total</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">rainfall_monthly_lt_average</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">rainfall_anomaly</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">spi1</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">spi3</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">spi6</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">spi12</th>\n</tr></thead>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">1</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">0.9417476</td>\n<td style=\"text-align: right;\">1.744876</td>\n<td style=\"text-align: right;\">0.5397218</td>\n<td style=\"text-align: right;\">-1.1043463</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">2</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">2.0194174</td>\n<td style=\"text-align: right;\">2.027616</td>\n<td style=\"text-align: right;\">0.9959566</td>\n<td style=\"text-align: right;\">0.1537152</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">3</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">32.8349507</td>\n<td style=\"text-align: right;\">9.696980</td>\n<td style=\"text-align: right;\">3.3861008</td>\n<td style=\"text-align: right;\">2.0730688</td>\n<td style=\"text-align: right;\">2.0600381</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">4</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">18.3139157</td>\n<td style=\"text-align: right;\">24.722222</td>\n<td style=\"text-align: right;\">0.7407876</td>\n<td style=\"text-align: right;\">-0.3498783</td>\n<td style=\"text-align: right;\">0.9740066</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">5</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">6.7928803</td>\n<td style=\"text-align: right;\">17.754692</td>\n<td style=\"text-align: right;\">0.3825963</td>\n<td style=\"text-align: right;\">-1.1682128</td>\n<td style=\"text-align: right;\">0.3482195</td>\n<td style=\"text-align: right;\">NA</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">6</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">2.7443365</td>\n<td style=\"text-align: right;\">4.763215</td>\n<td style=\"text-align: right;\">0.5761522</td>\n<td style=\"text-align: right;\">-1.1812731</td>\n<td style=\"text-align: right;\">-1.5032149</td>\n<td style=\"text-align: right;\">0.1598925</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">7</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">17.3592230</td>\n<td style=\"text-align: right;\">14.047789</td>\n<td style=\"text-align: right;\">1.2357264</td>\n<td style=\"text-align: right;\">0.7686934</td>\n<td style=\"text-align: right;\">-0.9048239</td>\n<td style=\"text-align: right;\">0.3881687</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">8</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">34.8381870</td>\n<td style=\"text-align: right;\">26.758146</td>\n<td style=\"text-align: right;\">1.3019657</td>\n<td style=\"text-align: right;\">0.8281462</td>\n<td style=\"text-align: right;\">0.7648482</td>\n<td style=\"text-align: right;\">0.7461252</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">9</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">29.1682857</td>\n<td style=\"text-align: right;\">19.003020</td>\n<td style=\"text-align: right;\">1.5349290</td>\n<td style=\"text-align: right;\">1.2521098</td>\n<td style=\"text-align: right;\">1.2306838</td>\n<td style=\"text-align: right;\">0.0193027</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: right;\">1981</td>\n<td style=\"text-align: right;\">10</td>\n<td style=\"text-align: left;\">SO1101</td>\n<td style=\"text-align: right;\">4.1974111</td>\n<td style=\"text-align: right;\">8.226213</td>\n<td style=\"text-align: right;\">0.5102483</td>\n<td style=\"text-align: right;\">-0.3816705</td>\n<td style=\"text-align: right;\">0.7653264</td>\n<td style=\"text-align: right;\">0.1559530</td>\n<td style=\"text-align: right;\">NA</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n</section><section class=\"level2\" id=\"interpretation\"><h2 class=\"anchored\" data-anchor-id=\"interpretation\">Interpretation</h2>\n<p>Drought events are indicated by negative SPI values, with more negative values indicating more severe drought conditions. Conversely, positive SPI values indicate wetter-than-average conditions. For demonstrating purposes, let's visualize the SPI values for Laasqoray district in Sanaag region. One efficient way to visualize SPI values is by using a box plot with SPI categories.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/sysfonts/man/font_add_google.html\">font_add_google</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme for the chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">theme_boxplot_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\">function</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">{</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span> </span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme settings</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Axis settings</span></span>\n<span>      axis.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      axis.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title settings</span></span>\n<span>      plot.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>, </span>\n<span>      plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">24</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>        width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Legend settings</span></span>\n<span>      legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"top\"</span>,</span>\n<span>      legend.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.spacing.x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.2</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.spacing <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>      legend.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.direction <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"horizontal\"</span>,</span>\n<span>      legend.byrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span>,</span>\n<span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Caption settings</span></span>\n<span>      plot.caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_markdown.html\">element_markdown</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey70\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"italic\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>,</span>\n<span>        hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span></span>\n<span>        <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>,</span>\n<span>        fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">}</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"1-month Standardized Precipitation Index (SPI-1) in Laasqoray, Somalia for the period 1981-2024\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Data:** Own estimations using Somalia rainfall Indicators at Subnational Level (HDX)\"</span>,</span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"&lt;br&gt;\"</span>, </span>\n<span>                        <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Graphic:** Juan Torres Mungu\u00eda\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">#</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/data.frame.html\">data.frame</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  ymin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  ymax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/factor.html\">factor</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extremely dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severely dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderately dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderately wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severely wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extremely wet\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    levels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extremely dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severely dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderately dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderately wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severely wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extremely wet\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#F76D5E\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFAD72\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFE099\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#99FF99\"</span>,</span>\n<span>    <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#99FF99\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#99EAFF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#75D3FF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#3D87FF\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">district_code</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"SO1503\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>month <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/factor.html\">factor</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span>, levels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">:</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>, labels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month.name</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Convert month to factor</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span>, y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add box plot with SPI categories</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_tile.html\">geom_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span>, <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>ymin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ymin</span>, ymax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ymax</span>, xmin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">Inf</span>, xmax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">Inf</span>, fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">label</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    alpha <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.2</span>, inherit.aes <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_boxplot.html\">geom_boxplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, outlier.size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, outlier.shape <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">16</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_manual.html\">scale_fill_manual</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>values <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/stats/setNames.html\">setNames</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fill</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">label</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"SPI-1\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guides.html\">guides</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guide_legend.html\">guide_legend</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>nrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Number of rows in the legend</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">theme_boxplot_chart</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb6\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_opts.html\">showtext_opts</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set the resolution of the image 320 dpi is for high-quality images (\"retina\")</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsave.html\">ggsave</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"spi-somalia.png\"</span>,</span>\n<span>  dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span>,</span>\n<span>  width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>,</span>\n<span>  height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">9</span>,</span>\n<span>  units <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"in\"</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Turn off the showtext functionality</span></span></code></pre></div></div>\n</div>\n<p><a class=\"lightbox\" data-gallery=\"quarto-lightbox-gallery-1\" href=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia//spi-somalia.png\"><img class=\"img-fluid\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/spi-somalia.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:100.0%\"/></a></p>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {How to Compute and Visualize the {Standardized}\n    {Precipitation} {Index} {(SPI)} for Drought Analysis},\n  date = {2025-02-08},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"How to Compute and Visualize\nthe Standardized Precipitation Index (SPI) for Drought Analysis.\"</span>\nFebruary 8, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/\">https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/v1x6c-fv074","guid":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/","image":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/spi-somalia.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1738972800,"rid":"zwhe7-d9z73","summary":"Overview The Standardized Precipitation Index (SPI) quantifies how precipitation deviates from the historical average over multiple time scales (e.g., from 1 to 12 months), allowing for consistent monitoring of droughts and floods across regions and time, making it a valuable tool for early warning and risk assessment systems.","tags":["Data Analysis","Drought","Tidyverse","Ggplot2","Box Plots"],"title":"How to compute and visualize the Standardized Precipitation Index (SPI) for drought analysis","updated_at":1790603817,"url":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia/","version":"v1"},{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p>Previously, in <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization//../../../blog/posts/spi_somalia/index.html\">Part 1 of this tutorial</a>, we calculated the Standardized Precipitation Index (SPI) for different time scales using the {SCI} package in R. Now, we will map the SPI values for the districts of Somalia using {sf} and {ggplot2} packages in R.</p>\n</section><section class=\"level2\" id=\"about-the-data\"><h2 class=\"anchored\" data-anchor-id=\"about-the-data\">About the data</h2>\n<p>The information of the Somalian sub national administrative boundaries is obtained from the <a href=\"https://data.humdata.org/\">Humanitarian Data Exchange (HDX) initiative</a> of the United Nations Office for the Coordination of Humanitarian Affairs (OCHA). The information comes as a shapefile <code>.shp</code> and is available <a href=\"https://data.humdata.org/dataset/cod-ab-som?\">here</a> in a zip file named <code>som_adm_ocha_20250108_AB_SHP.zip</code>. The shapefile contains the administrative boundaries of Somalia at the subnational level. In particular, we will use file <code>som_admbnda_ADM2_ocha_20250108.shp</code>, that contains the shapefile of Somalia at the district level. I downloaded this file and located it in <code>/shp</code> folder.</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>Before we begin, we need to install and load the necessary R packages.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/\">sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org\">ggplot2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/\">ggtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://github.com/yixuan/showtext\">showtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com\">patchwork</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"loading-data-hdx\"><h2 class=\"anchored\" data-anchor-id=\"loading-data-hdx\">Loading data HDX</h2>\n<p>Data can be found <a href=\"https://data.humdata.org/dataset/som-rainfall-subnational\">here</a> in file <code>som-rainfall-adm2-full.csv</code>. For Somalia, data is available from January 1981.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_read.html\">read_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"shp/som_admbnda_adm2_ocha_20250108.shp\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    district <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ADM2_EN</span>, </span>\n<span>    district_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ADM2_PCODE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<section class=\"level3\" id=\"data-wrangling\"><h3 class=\"anchored\" data-anchor-id=\"data-wrangling\">Data wrangling</h3>\n<p>I will add the SPI values previously calculated to the shapefile data frame. I saved the SPI values in a RData file named <code>rainfall_data.RData</code>.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/load.html\">load</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"rainfall_data.RData\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># First, we need to filter the SPI values for the last available month, i.e. December 2024</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># to have only one observation per district</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data_dec2024</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&amp;</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2024</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Merge the shapefile with the SPI values</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate-joins.html\">left_join</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rainfall_data_dec2024</span>, by <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"district_code\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section></section><section class=\"level2\" id=\"set-theme-settings-and-define-fonts-colors-and-text-to-be-used-in-the-map\"><h2 class=\"anchored\" data-anchor-id=\"set-theme-settings-and-define-fonts-colors-and-text-to-be-used-in-the-map\">Set theme settings and define fonts, colors, and text to be used in the map</h2>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/sysfonts/man/font_add_google.html\">font_add_google</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">theme_spi_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\">function</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">{</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Roboto Condensed\"</span> </span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme settings</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title settings</span></span>\n<span>      plot.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>, </span>\n<span>      plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>        width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey50\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span></span>\n<span>      legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"top\"</span>,</span>\n<span>      legend.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>      legend.key.width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>      legend.spacing.x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.key.spacing <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>      legend.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      legend.direction <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"horizontal\"</span>,</span>\n<span>      legend.byrow <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span>,</span>\n<span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Caption settings</span></span>\n<span>      plot.caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_markdown.html\">element_markdown</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey70\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"italic\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>,</span>\n<span>        hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>,</span>\n<span>        fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">}</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title, subtitle, and caption for the waffle chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Standardized Precipitation Index (SPI) in Somalia\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"February 2024\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Data:** Somalia: Own estimations using Somalia Rainfall Indicators at Subnational Level (HDX) &lt;br&gt; **Graphic:** Juan Torres Mungu\u00eda\"</span></span></code></pre></div></div>\n</div>\n<p>Now, lets create a histogram of the SPI values for the districts of Somalia to use as a legend for the map.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/data.frame.html\">data.frame</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  ymin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  ymax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/factor.html\">factor</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severe dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderate dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderate wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severe wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme wet\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    levels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severe dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderate dry\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Near normal\"</span>,</span>\n<span>      <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Moderate wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Severe wet\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme wet\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#F76D5E\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFAD72\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFE099\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E5FFE5\"</span>,</span>\n<span>    <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E5FFE5\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#99EAFF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#75D3FF\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#3D87FF\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://magrittr.tidyverse.org/reference/pipe.html\">%&gt;%</a></span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>spi_category <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/cut.html\">cut</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi1</span>,</span>\n<span>    breaks <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">Inf</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ymax</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    labels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">label</span>,</span>\n<span>    right <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># right = TRUE means that the intervals are closed on the right</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">!</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/NA.html\">is.na</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">histogram_spi</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">!</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/NA.html\">is.na</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_category</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_category</span>, fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_category</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_bar.html\">geom_bar</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_manual.html\">scale_fill_manual</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>values <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/stats/setNames.html\">setNames</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fill</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">label</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Number of districts\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">theme_spi_map</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"none\"</span>,</span>\n<span>    axis.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">7</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">7</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.line <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    panel.grid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/coord_flip.html\">coord_flip</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb6\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read the shapefile of Somalia with the interior region borders</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia_region</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_read.html\">read_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"shp/som_admbnda_adm1_ocha_20250108.shp\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia_region</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia_region</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3857</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Web Mercator projection</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3857</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_spi</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia</span>, <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_category</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey\"</span>, linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_manual.html\">scale_fill_manual</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>values <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/stats/setNames.html\">setNames</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fill</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">spi_colors</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">label</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_somalia_region</span>, fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>, color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>, linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.9</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">caption_chart</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\">theme_spi_map</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"none\"</span>,</span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Axis settings</span></span>\n<span>    axis.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.line <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.ticks <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    panel.grid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb7\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_spi</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com/reference/inset_element.html\">inset_element</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">histogram_spi</span>, left <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.4</span>, bottom <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, right <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, top <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.4</span>, on_top <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb8\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_opts.html\">showtext_opts</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsave.html\">ggsave</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"spi-somalia-map.png\"</span>,</span>\n<span>  dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span>,</span>\n<span>  width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>,</span>\n<span>  height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">9</span>,</span>\n<span>  units <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"in\"</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p><a class=\"lightbox\" data-gallery=\"quarto-lightbox-gallery-1\" href=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization//spi-somalia-map.png\"><img class=\"img-fluid\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/spi-somalia-map.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:100.0%\"/></a></p>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {How to Compute and Visualize the {Standardized}\n    {Precipitation} {Index} {(SPI)} for Drought Analysis},\n  date = {2025-02-14},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"How to Compute and Visualize\nthe Standardized Precipitation Index (SPI) for Drought Analysis.\"</span>\nFebruary 14, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/\">https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/4c24v-c9z61","guid":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/","image":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/spi-somalia-map.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1739491200,"rid":"xyk6p-57z32","summary":"Overview Previously, in Part 1 of this tutorial, we calculated the Standardized Precipitation Index (SPI) for different time scales using the {SCI} package in R. Now, we will map the SPI values for the districts of Somalia using {sf} and {ggplot2} packages in R. About the data The information of the Somalian sub national administrative boundaries is obtained from the Humanitarian Data Exchange (HDX) initiative of the United Nations Office","tags":["Data Visualization","Drought","Tidyverse","Ggplot2","Shapefiles"],"title":"How to compute and visualize the Standardized Precipitation Index (SPI) for drought analysis","updated_at":1790603811,"url":"https://juan-torresmunguia.netlify.app/blog/posts/spi_somalia_visualization/","version":"v1"},{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p><a href=\"https://acleddata.com/\">ACLED (Armed Conflict Location &amp; Event Data Project)</a> provides detailed data on political violence and protest events across the globe. This blog post explores the visualization of armed conflict in the Lake Chad Basin, focusing on the dynamics of violence against civilians in the region. Using ACLED's data in combination with shapefiles from the <a href=\"https://data.humdata.org/\">Humanitarian Data Exchange (HDX) initiative</a> of the United Nations Office for the Coordination of Humanitarian Affairs (OCHA), we leverage {ggplot2}, {sf} and the {tidyverse} to create insightful maps that highlight the impact of armed conflict.</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>Load necessary libraries for data processing and visualization.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For data manipulation and visualization</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/\">sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For handling spatial data</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org\">ggplot2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For data visualization</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com\">patchwork</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For combining plots</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/\">ggtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Use rich text elements in ggplot</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://github.com/yixuan/showtext\">showtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add custom fonts to plots</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://paleolimbot.github.io/ggspatial/\">ggspatial</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For interacting with spatial data using ggplot2</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://docs.ropensci.org/rnaturalearth/\">rnaturalearth</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To provide map data that can be visualized using other R packages</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://docs.ropensci.org/rnaturalearthdata/\">rnaturalearthdata</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To store data for the rnaturalearth package</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set environment to English (useful for date/time formatting)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/invisible.html\">invisible</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/Sys.setenv.html\">Sys.setenv</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>LANG <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"en\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/invisible.html\">invisible</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/locales.html\">Sys.setlocale</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"LC_TIME\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"English\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"loading-data\"><h2 class=\"anchored\" data-anchor-id=\"loading-data\">Loading data</h2>\n<p>Accessing ACLED data requires registering on their <a href=\"https://developer.acleddata.com/\">ACLED Access Portal</a> to generate a unique access key. Once registered, you can download the data using their <a href=\"https://acleddata.com/data-export-tool/\">Data Export Tool</a>. I downloaded all the events occurred in Africa since 1997 and save them in file <code>acled_africa_1997-2025.csv</code>. To have a better understanding of their data, they provide a <a href=\"https://acleddata.com/acleddatanew/wp-content/uploads/dlm_uploads/2024/10/ACLED-Codebook-2024-7-Oct.-2024.pdf\">codebook</a>.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/utils/read.table.html\">read.csv</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"acled_africa_1997-2025.csv\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Information of the national and sub national administrative boundaries in the Lake Chad Basin is obtained from the HDX. The information comes as a shapefile <code>.shp</code> and is available <a href=\"https://data.humdata.org/dataset/lac-chad-basin-area?force_layout=desktop\">here</a> in a zip file named <code>lcb_admbnda_adm2_ocha.zip</code>. The shapefile contains the administrative boundaries of Lake Chad Basin region at the subnational level. In particular, we will use file <code>lcb_admbnda_adm2_ocha.shp</code>. I also downloaded the administrative boundaries of the West and Central Africa region available <a href=\"https://data.humdata.org/dataset/west-and-central-africa-administrative-boundaries-levels\">here</a>.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Lake Chad Basin Area - Administrative boundaries for Nigeria, Chad, Cameroon and Niger</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad_basin</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_read.html\">read_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"lcb_admbnda_adm2_ocha/lcb_admbnda_adm2_ocha.shp\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># West and Central Africa - Administrative boundaries levels 0 - 2 and Settlements</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">west_central_africa</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_read.html\">read_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"wca_admbnda_adm2_ocha/wca_admbnda_adm2_ocha.shp\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"data-processing\"><h2 class=\"anchored\" data-anchor-id=\"data-processing\">Data processing</h2>\n<p>As indicated in the <a href=\"https://acleddata.com/acleddatanew/wp-content/uploads/dlm_uploads/2024/10/ACLED-Codebook-2024-7-Oct.-2024.pdf\">ACLED's codebook</a>, geographic location of the events is specified in columns <code>latitude</code> and <code>longitude</code> in the <code>conflict_data</code> object and they are using the <a href=\"https://epsg.io/4326\">EPSG:4326</a> coordinate reference system. We have to ensure, that both <code>shp_lake_chad_basin</code> and <code>west_central_africa</code> have the same coordinate reference system. To achieve this, we use <code><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform()</a></code> from {sf} package.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># st_transform to convert coordinates to ACLED's data coordinate reference system</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad_basin</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad_basin</span>,</span>\n<span>  crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4326</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">west_central_africa</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">west_central_africa</span>,</span>\n<span>  crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4326</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Now, we subset the events to exclusively account for those occurred between 2020 and 2024 in the Lake Chad Basin. To achieve this, we use the {tidyverse} package for data wrangling and {sf} for spatial filtering. By applying the <code>st_filter</code> function, we retain only events located within the Lake Chad Basin area.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Keep only events from 2020 to 2024</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&gt;=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2020</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&amp;</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2025</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select only \"Violence against civilians\" events of type \"Attack\"</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">event_type</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Violence against civilians\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&amp;</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">sub_event_type</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Attack\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Keep events from Nigeria, Niger, Cameroon, and Chad</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/match.html\">%in%</a></span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Nigeria\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Niger\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Cameroon\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Chad\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Extract the month name from event_date</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    month <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://lubridate.tidyverse.org/reference/month.html\">month</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://lubridate.tidyverse.org/reference/ymd.html\">dmy</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">event_date</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select only relevant columns</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">event_id_cnty</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">event_date</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">month</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">event_type</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">sub_event_type</span>,</span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">actor1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">actor2</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">location</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">latitude</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">longitude</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fatalities</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">notes</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Convert the data to a spatial object using latitude and longitude (WGS 84 CRS)</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_as_sf.html\">st_as_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span>,</span>\n<span>  coords <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"longitude\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"latitude\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4326</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Filter events that fall within the Lake Chad Basin shapefile</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data_lake_chad</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_join.html\">st_filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad_basin</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>We then processes administrative boundary data to extract relevant regions in West and Central Africa, focusing on the Lake Chad Basin area.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb6\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Filter to include only countries in the Lake Chad Basin region</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># I included Central African Republic for visualization purposes</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">west_central_africa</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/match.html\">%in%</a></span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Nigeria\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Niger\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Chad\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Cameroon\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Central African Republic\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create country codes and format administrative division codes</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    country_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/case_when.html\">case_when</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Nigeria\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"NGA\"</span>,</span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Niger\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"NER\"</span>,</span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Chad\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"TCD\"</span>,</span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Cameroon\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"CMR\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Extract and format adm1 and adm2 codes</span></span>\n<span>    adm1_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_pad.html\">str_pad</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_extract.html\">str_extract</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin1Pcod</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\\\\d+\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>, pad <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"0\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    adm2_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_pad.html\">str_pad</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_sub.html\">str_sub</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin2Pcod</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">6</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>, pad <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"0\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a unique administrative code by combining country and division codes</span></span>\n<span>    adm_code <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country_code</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1_code</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm2_code</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename columns for clarity</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    country <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin0Name</span>,</span>\n<span>    adm1 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin1Name</span>,</span>\n<span>    adm2 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">admin2Name</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select only relevant columns</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm_code</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm2</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Identify administrative units within the Lake Chad Basin</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>lake_chad_basin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/ifelse.html\">ifelse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm_code</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/match.html\">%in%</a></span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad_basin</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Rowcacode2</span>,</span>\n<span>    <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Yes\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"No\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Subset to retain only the administrative units inside the Lake Chad Basin</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_basin</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Yes\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Compute the bounding box for visualization</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">bbox</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_bbox.html\">st_bbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_min</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">bbox</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"xmin\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_max</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">bbox</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"xmax\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_min</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">bbox</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"ymin\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_max</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">bbox</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"ymax\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Aggregate administrative level 1 (regions/states) within the Lake Chad Basin</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_basin</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>geometry <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_combine.html\">st_union</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Keep only regions in the Lake Chad Basin and clean names</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_basin</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Yes\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>adm1 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_replace.html\">str_replace_all</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"_\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\" \"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Compute centroid coordinates for labeling</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_coordinates.html\">st_coordinates</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_unary.html\">st_centroid</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_coordinates.html\">st_coordinates</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_unary.html\">st_centroid</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Now, we create a hexagonal grid over the Lake Chad region with a cell size of approximately 10.69 km and fatalities and attack counts are aggregated per grid cell.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb7\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Reproject Lake Chad Basin shapefile to UTM Zone 33N (EPSG:32633)</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># This is important to set a cell size in km</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span>, crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">32633</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a hexagonal grid over the Lake Chad Basin with a cell size of ~10.69 km</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_make_grid.html\">st_make_grid</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span>,</span>\n<span>  cellsize <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10690</span>,</span>\n<span>  square <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Filter the grid to keep only hexagons intersecting the Lake Chad Basin</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid_filter</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/sf.html\">st_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_join.html\">st_filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Reproject the grid and Lake Chad Basin back to WGS84 (EPSG:4326)</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid_filter</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid_filter</span>, crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4326</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_transform.html\">st_transform</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span>, crs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4326</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Spatially join conflict data with the hexagonal grid</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data_grid</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_join.html\">st_join</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid_filter</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data_lake_chad</span>, left <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Aggregate conflict data by grid cell, summing fatalities and counting attacks</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fatalities_per_grid</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">conflict_data_grid</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    fatalities <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/sum.html\">sum</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fatalities</span>, na.rm <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    num_attacks <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/context.html\">n</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_as_sf.html\">st_as_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Compute centroid coordinates for visualization</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_coordinates.html\">st_coordinates</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_unary.html\">st_centroid</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_coordinates.html\">st_coordinates</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_unary.html\">st_centroid</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">nc_grid</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>We need to relocate the coordinates of the labels for specific regions for better readability.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb8\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Adjust label positions for specific administrative regions to improve readability</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/case_when.html\">case_when</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme Nord\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.1</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Shift label slightly left</span></span>\n<span>      <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/case_when.html\">case_when</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Extreme Nord\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Move label downward</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Adamawa\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.3</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Move label upward</span></span>\n<span>      <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Borno\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.4</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Adjust label downward</span></span>\n<span>      <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Aggregate country geometries by merging administrative boundaries</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Dissolve some shapes</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/summarise.html\">summarise</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>geometry <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_combine.html\">st_union</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_cast.html\">st_cast</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"POLYGON\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/group_by.html\">group_by</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Retain the largest polygon for each country</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/filter.html\">filter</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_measures.html\">st_area</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/Extremes.html\">max</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/geos_measures.html\">st_area</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">geometry</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define manual label positions for country names</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country_labels</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tibble.tidyverse.org/reference/tibble.html\">tibble</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  country <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Nigeria\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Niger\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Chad\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Cameroon\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>  x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10.15</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">11</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">15</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">13.6</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># X-coordinates for label placement</span></span>\n<span>  y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">15</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14.2</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">9</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Y-coordinates for label placement</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>We first create an empty map of the countries and highlight the Lake Chad Basin area using {ggplot2}.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb9\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Automatically use showtext for handling fonts</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add Google font \"Voltaire\"</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/sysfonts/man/font_add_google.html\">font_add_google</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Voltaire\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Voltaire\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot country borders with a light fill color</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#ECEFF1\"</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>    inherit.aes <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot Lake Chad Basin area with a darker fill color</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E0E0E0\"</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>    inherit.aes <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Now, we add the fatalities information.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb10\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot fatalities per grid with a color gradient</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fatalities_per_grid</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">fatalities</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    alpha <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_gradient.html\">scale_fill_gradient</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>name <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Fatalities\"</span>, </span>\n<span>                      low <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FCC5C0\"</span>, high <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#67001F\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>We add different color to subnational and national boundaries and add their corresponding labels.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb11\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot aggregated administrative region boundaries with white lines</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot country boundaries with black lines</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_countries_countries</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.25</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add labels for administrative regions (e.g., \"Extreme Nord\")</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_text.html\">geom_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_adm1_aggregated</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span>, y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span>,</span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Wrap text if needed for long region names</span></span>\n<span>      label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://stringr.tidyverse.org/reference/str_wrap.html\">str_wrap</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">adm1</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    colour <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#999\"</span>,</span>\n<span>    fontface <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>,</span>\n<span>    family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Voltaire\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  </span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add labels for countries with a larger font</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_text.html\">geom_label</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country_labels</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x</span>, y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y</span>, label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">country</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    colour <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    fontface <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4</span>,</span>\n<span>    family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Voltaire\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Finally, we center the map at the Lake Chad Basin area and add format for a better visualization.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb12\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title, subtitle, and caption for the waffle chart</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Armed conflict in the Lake Chad Basin, 2020-2024\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Fatalities in attacks perpetrated by organized armed actors against civilians\"</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">title_chart</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">subtitle_chart</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Data:** Armed Conflict Location &amp; Event Data (ACLED) &lt;br&gt; **Graphic:** Juan Torres Mungu\u00eda\"</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set the map's coordinate limits and prevent expansion</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">coord_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    xlim <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_min</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_max</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    ylim <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_min</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_max</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    expand <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add a scale bar in the bottom left</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://paleolimbot.github.io/ggspatial/reference/annotation_scale.html\">annotation_scale</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>location <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bl\"</span>, width_hint <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.2</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add a north arrow in the top left corner</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://paleolimbot.github.io/ggspatial/reference/annotation_north_arrow.html\">annotation_north_arrow</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    location <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"tl\"</span>,</span>\n<span>    which_north <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"true\"</span>,</span>\n<span>    style <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">north_arrow_fancy_orienteering</span>,</span>\n<span>    height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Customize the legend</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guides.html\">guides</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guide_legend.html\">guide_legend</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bottom\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set the base theme without any background elements</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_void</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Voltaire\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Customize the map's text and legend styling</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title settings</span></span>\n<span>    plot.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Position of the title</span></span>\n<span>    plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Top, right, bottom, left</span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Width of the title, npc == 1 corresponds to the full width of the plot</span></span>\n<span>      width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    plot.subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_textbox.html\">element_textbox</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey50\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">20</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"npc\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span></span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Caption settings</span></span>\n<span>    plot.caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_markdown.html\">element_markdown</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey70\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">3</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>, color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>, face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>, face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.direction <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"horizontal\"</span>,</span>\n<span>    legend.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"top\"</span>,</span>\n<span>    legend.text.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bottom\"</span>,</span>\n<span>    legend.key.size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.65</span>, units <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>, color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>t <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, r <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, b <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, l <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#ECEFF1\"</span>, color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>We create a zoomed-in map of the Lake Chad Basin inset within the African continent, using ggplot2. It includes the ne_countries function from the {rnaturalearth} package to retrieve the map of Africa. The map of the Lake Chad Basin is overlaid on top of Africa, and a rectangle is drawn to highlight the region of interest (Lake Chad Basin). The map is customized with a white background and black borders.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb13\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Fetch African countries map from the rnaturalearth package</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">africa</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://docs.ropensci.org/rnaturalearth/reference/ne_countries.html\">ne_countries</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>continent <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Africa\"</span>, returnclass <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"sf\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a zoomed-in map of Lake Chad Basin within the African map</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map_zoom</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot the Africa map with a light fill color</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">africa</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#ECEFF1\"</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>    inherit.aes <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Plot Lake Chad Basin area with a darker fill color</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_lake_chad</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E0E0E0\"</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>    inherit.aes <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add a rectangle highlighting the Lake Chad Basin on the Africa map</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/geom_tile.html\">geom_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>xmin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_min</span>, xmax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">x_max</span>, ymin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_min</span>, ymax <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">y_max</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.2</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Remove grid and axes for a clean map appearance</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_void</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Customize borders and background of the map</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    panel.border <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>      fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">NA</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.8</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Finally, we combine the main map of the Lake Chad Basin with an inset map of Africa showing the location of the Lake Chad Basin. The inset map is positioned within the main map using the <code><a href=\"https://patchwork.data-imaginist.com/reference/inset_element.html\">inset_element()</a></code> function of the {patchwork} package. Additionally, we set the resolution of the saved image to 320 dpi (high resolution) for better quality. Finally, the map is saved as a PNG file using <code><a href=\"https://ggplot2.tidyverse.org/reference/ggsave.html\">ggsave()</a></code></p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb14\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># locate main and inset map</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com/reference/inset_element.html\">inset_element</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    align_to <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>,</span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">lake_chad_map_zoom</span>,</span>\n<span>    right <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>    left <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.84</span>,</span>\n<span>    top <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>,</span>\n<span>    bottom <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.91</span>,</span>\n<span>    on_top <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb15\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Set the resolution of the image 320 dpi is for high-quality images (\"retina\")</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_opts.html\">showtext_opts</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsave.html\">ggsave</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"lake-chad-map.png\"</span>,</span>\n<span>  dpi <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">320</span>,</span>\n<span>  width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>,</span>\n<span>  height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">12</span>,</span>\n<span>  units <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"in\"</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">FALSE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<div class=\"quarto-figure quarto-figure-center\">\n<figure class=\"figure\"><p><img class=\"img-fluid quarto-figure quarto-figure-center figure-img\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/lake-chad-map.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:30.0%\"/></p>\n</figure>\n</div>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {Visualizing Armed Conflict Using {ACLED's} Data and {HDX}\n    Shapefiles},\n  date = {2025-03-09},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"Visualizing Armed Conflict\nUsing ACLED's Data and HDX Shapefiles.\"</span> March 9, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/\">https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/cpzt6-efs07","guid":"https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/","image":"https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/lake-chad-map.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1741478400,"rid":"8n6ba-0p138","summary":"Overview ACLED (Armed Conflict Location &amp; Event Data Project) provides detailed data on political violence and protest events across the globe. This blog post explores the visualization of armed conflict in the Lake Chad Basin, focusing on the dynamics of violence against civilians in the region.","tags":["Data Visualization","Armed Conflict","ACLED","Lake Chad Basin","Nigeria"],"title":"Visualizing armed conflict using ACLED's data and HDX shapefiles","updated_at":1790603806,"url":"https://juan-torresmunguia.netlify.app/blog/posts/visualizing-conflict-lake-chad-basin/","version":"v1"},{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"setting-up-the-environment\"><h2 class=\"anchored\" data-anchor-id=\"setting-up-the-environment\">Setting Up the Environment</h2>\n<p>We begin by loading the necessary R packages:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Load required packages</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://jeroen.r-universe.dev/jsonlite\">jsonlite</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For working with JSON data</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/\">httr</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For HTTP requests</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org\">dplyr</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For data manipulation</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org\">readxl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For reading Excel files</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ropensci.r-universe.dev/writexl\">writexl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For writing Excel files</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"step-1-accessing-the-dataset\"><h2 class=\"anchored\" data-anchor-id=\"step-1-accessing-the-dataset\">Step 1: Accessing the Dataset</h2>\n<p>We retrieve the latest dataset of disease outbreaks from GitHub:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define the API URL from GitHub containing the latest dataset update</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">url_api</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://api.github.com/repos/jatorresmunguia/disease_outbreak_news/contents/Last%20update\"</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Retrieve the list of files in the \"Last update\" folder</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">file_list</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://jeroen.r-universe.dev/jsonlite/reference/fromJSON.html\">fromJSON</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/content.html\">content</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/GET.html\">GET</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">url_api</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, as <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"text\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">name</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Filter the most recent file that starts with \"outbreaks\"</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_file</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">file_list</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/grep.html\">grepl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">file_list</span>, pattern <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"^outbreaks\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select the file with a .csv extension</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rdata_file</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_file</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/grep.html\">grepl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\".csv$\"</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_file</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Construct the CSV file URL from GitHub and read the data into a dataframe</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/utils/read.table.html\">read.csv</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://raw.githubusercontent.com/jatorresmunguia/disease_outbreak_news/refs/heads/main/Last%20update/\"</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">rdata_file</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, header <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Remove unnecessary ICD-11 classification columns</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">-</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11c1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11c2</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11c3</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11l1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11l2</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd11l3</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"step-2-adding-who-and-unsd-regional-classifications\"><h2 class=\"anchored\" data-anchor-id=\"step-2-adding-who-and-unsd-regional-classifications\">Step 2: Adding WHO and UNSD Regional Classifications</h2>\n<p>We integrate additional geographic classifications from WHO and UNSD.</p>\n<section class=\"level3\" id=\"who-regions\"><h3 class=\"anchored\" data-anchor-id=\"who-regions\">WHO Regions</h3>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define the URL for the WHO regional classification dataset</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">url_who_class</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"https://cdn.who.int/media/docs/default-source/air-pollution-documents/air-quality-and-health/un-agencies-region-classification-for-country.xlsx?sfvrsn=289af35f_3\"</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a temporary file to store the downloaded Excel file</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp_file</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/tempfile.html\">tempfile</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fileext <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\".xlsx\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Download the WHO classification file and save it to the temporary file</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/GET.html\">GET</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">url_who_class</span>, <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://httr.r-lib.org/reference/write_disk.html\">write_disk</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp_file</span>, overwrite <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"cell-output cell-output-stdout\">\n<pre><code>Response [https://cdn.who.int/media/docs/default-source/air-pollution-documents/air-quality-and-health/un-agencies-region-classification-for-country.xlsx?sfvrsn=289af35f_3]\n  Date: 2025-04-28 06:21\n  Status: 200\n  Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n  Size: 28.9 kB\n&lt;ON DISK&gt;  C:\\Users\\jator\\AppData\\Local\\Temp\\RtmpiGD1DX\\file990423923f25.xlsx</code></pre>\n</div>\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read the WHO classification data from the downloaded Excel file</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">who_class</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org/reference/read_excel.html\">read_excel</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">temp_file</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select relevant columns (ISO country code and WHO region name)</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename columns for consistency with the main dataset</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">who_class</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`ISO Country code`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`WHO Region name2`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>iso3 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`ISO Country code`</span>, who_region <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`WHO Region name2`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate-joins.html\">right_join</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span>, by <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"iso3\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Merge with the main dataset based on the ISO3 country code</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level3\" id=\"unsd-regions\"><h3 class=\"anchored\" data-anchor-id=\"unsd-regions\">UNSD Regions</h3>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb6\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Read the UNSD regional classification dataset from an Excel file</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># The dataset is available at: https://unstats.un.org/unsd/methodology/m49/</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">unsd_class</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org/reference/read_excel.html\">read_excel</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>path <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"UNSD \u2014 Methodology.xlsx\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select relevant columns: ISO-alpha3 country code, region name, and sub-region name</span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Rename columns to match the main dataset</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">unsd_class</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`ISO-alpha3 Code`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Region Name`</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Sub-region Name`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/rename.html\">rename</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    iso3 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`ISO-alpha3 Code`</span>,</span>\n<span>    unsd_region <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Region Name`</span>,</span>\n<span>    unsd_subregion <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Sub-region Name`</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate-joins.html\">right_join</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span>, by <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"iso3\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Merge with the main dataset based on the ISO3 country code</span></span></code></pre></div></div>\n</div>\n</section></section><section class=\"level2\" id=\"step-3-structuring-the-dataset\"><h2 class=\"anchored\" data-anchor-id=\"step-3-structuring-the-dataset\">Step 3: Structuring the Dataset</h2>\n<p>To facilitate better organization, we:</p>\n<ol type=\"1\">\n<li>Order the dataset by year, country, and disease code.</li>\n<li>Assign a unique outbreak ID.</li>\n<li>Insert an empty row for HXL headers.</li>\n</ol>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb7\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Arrange the dataset in descending order by Year, then by ISO3 country code, and ICD-10 4-character code</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/arrange.html\">arrange</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/desc.html\">desc</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">iso3</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104c</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Create a unique outbreak ID by concatenating Year, ISO3 country code, and ICD-10 4-character code</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>id_outbreak <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/paste.html\">paste0</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">iso3</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104c</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add an empty row at the beginning of the dataset (for later HXL hashtag insertion)</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tibble.tidyverse.org/reference/add_row.html\">add_row</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>.before <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"step-4-adding-hxl-hashtags\"><h2 class=\"anchored\" data-anchor-id=\"step-4-adding-hxl-hashtags\">Step 4: Adding HXL Hashtags</h2>\n<p>We define HXL hashtags for each relevant column:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb8\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Define the mapping of column names to their corresponding HXL hashtags</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">cols2hxl</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  id_outbreak <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#Year+iso3+icd4\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Unique outbreak ID</span></span>\n<span>  Country <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#country+name\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Country name</span></span>\n<span>  iso2 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#country+code+iso2\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># ISO 2-letter country code</span></span>\n<span>  iso3 <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#country+code+iso3\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># ISO 3-letter country code</span></span>\n<span>  unsd_region <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#region+unsd\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># UNSD region</span></span>\n<span>  unsd_subregion <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#subregion+unsd\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># UNSD subregion</span></span>\n<span>  who_region <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#region+who\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># WHO region</span></span>\n<span>  Year <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#date+year\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Year of the outbreak</span></span>\n<span>  icd10n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+name+icd\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease name (ICD-10)</span></span>\n<span>  icd103n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+name+icd3\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease name (ICD-10 3-character)</span></span>\n<span>  icd104n <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+name+icd4\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease name (ICD-10 4-character)</span></span>\n<span>  icd10c <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+code+icd\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease code (ICD-10)</span></span>\n<span>  icd103c <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+code+icd3\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease code (ICD-10 3-character)</span></span>\n<span>  icd104c <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+code+icd4\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease code (ICD-10 4-character)</span></span>\n<span>  Disease <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#disease+name\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease name</span></span>\n<span>  DONs <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#news+id\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># News ID</span></span>\n<span>  Definition <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#x_disease+definition\"</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Disease definition</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Add HXL hashtags to the relevant columns in the dataset</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/across.html\">across</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyselect.r-lib.org/reference/all_of.html\">all_of</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/names.html\">names</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">cols2hxl</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/replace.html\">replace</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">.</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">cols2hxl</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">[</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/context.html\">cur_column</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">]</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Select the relevant columns for the final dataset</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/select.html\">select</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">id_outbreak</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Year</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd10n</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd103n</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104n</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd10c</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd103c</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">icd104c</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Disease</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Definition</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Country</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">iso2</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">iso3</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">unsd_region</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">unsd_subregion</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">who_region</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">DONs</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"step-5-exporting-the-final-dataset\"><h2 class=\"anchored\" data-anchor-id=\"step-5-exporting-the-final-dataset\">Step 5: Exporting the Final Dataset</h2>\n<p>Finally, we save the dataset as an Excel file:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb9\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://docs.ropensci.org/writexl//reference/write_xlsx.html\">write_xlsx</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/list.html\">list</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>Data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">last_version</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, path <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"disease_outbreaks_HDX.xlsx\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {Working with {Humanitarian} {Exchange} {Language} {(HXL)}\n    {Hashtags}},\n  date = {2025-03-26},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"Working with Humanitarian\nExchange Language (HXL) Hashtags.\"</span> March 26, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/\">https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/0dt7g-rr206","guid":"https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/","image":"https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/hdx_image.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1742947200,"rid":"s8zfb-cxz88","summary":"Setting Up the Environment We begin by loading the necessary R packages: # Load required packages library(jsonlite) # For working with JSON data library(httr) # For HTTP requests library(dplyr) # For data manipulation library(readxl) # For reading Excel files library(writexl) # For writing Excel files Step 1: Accessing the Dataset We retrieve the latest dataset of disease outbreaks from GitHub: # Define the API URL from GitHub containing the","tags":["Data Management","Humanitarian Data Exchange","Humanitarian Exchange Language","Disease Outbreaks","Epidemics"],"title":"Working with Humanitarian Exchange Language (HXL) Hashtags","updated_at":1790603800,"url":"https://juan-torresmunguia.netlify.app/blog/posts/hdx-tags-to-outbreaks-data/","version":"v1"},{"authors":[{"contributor_roles":[],"family":"Torres Munguia","given":"Juan Armando","url":"https://orcid.org/0000-0003-3432-6941"}],"blog":{"authors":null,"community_id":"ae893dd4-41e3-426b-8b48-6c9c75639805","created":1761523200,"current_feed_url":null,"description":"Exploring the art and science of working with development and humanitarian data","doi":"https://doi.org/10.59350/juan_torresmunguia","favicon":"https://rogue-scholar.org/api/communities/ae893dd4-41e3-426b-8b48-6c9c75639805/logo","feed_format":"application/rss+xml","feed_url":"https://juan-torresmunguia.netlify.app/blog/index.xml","filter":null,"generator":"Quarto","home_page_url":"https://juan-torresmunguia.netlify.app/blog/","issn":null,"language":"eng","license":"https://creativecommons.org/licenses/by/4.0/legalcode","prefix":"10.59350","relative_url":null,"secure":true,"slug":"juan_torresmunguia","status":"active","subfield":"1804","title":"Data Art & Science Blog","updated":1783172007,"use_api":null},"blog_name":"Data Art & Science Blog","blog_slug":"juan_torresmunguia","content_html":"<section class=\"level2\" id=\"overview\"><h2 class=\"anchored\" data-anchor-id=\"overview\">Overview</h2>\n<p>According to the 2021-22 Domestic Violence module of the Kingdom of Cambodia's Demographic and Health Survey (CDHS), over 21% of Cambodian women aged 15\u201349 who have ever had a husband (or intimate partner), have experienced physical, sexual, economic, and/or emotional intimate partner violence in their lifetime. This figures varies significantly across the country, with some provinces reporting rates as high as 45% while others report rates as low as 6%.</p>\n<p>A better understanding of the geographical distribution of intimate partner violence (IPV) in Cambodia can help policymakers and organizations to target their efforts more effectively. In this blog post, I will show how to create choropleth maps using R and shapefiles to visualize the prevalence of IPV in Cambodia at the provincial level. Additionally, I will use the {patchwork} package to combine these maps into the same graphic. The result will look like this:</p>\n<p><a class=\"lightbox\" data-gallery=\"quarto-lightbox-gallery-1\" href=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia//ipv-cambodia-map.png\"><img class=\"img-fluid\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/ipv-cambodia-map.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:100.0%\"/></a></p>\n</section><section class=\"level2\" id=\"about-the-data\"><h2 class=\"anchored\" data-anchor-id=\"about-the-data\">About the data</h2>\n<p>Information comes from the document \"Further Data Analysis Report. From the Cambodia Demographic and Health Survey 2021-2022\", available <a href=\"https://nis.gov.kh/nis/CDHS_Further_Data/CDHS%20Domestic%20Violence%20Report%202024_En.pdf\">here</a>. In particular, I will use Table A.1: <em>Intimate-partner violence by background characteristics</em>.</p>\n</section><section class=\"level2\" id=\"set-up\"><h2 class=\"anchored\" data-anchor-id=\"set-up\">Set-up</h2>\n<p>First, we install and load the necessary R packages.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb1\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://tidyverse.tidyverse.org\">tidyverse</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/\">sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For handling shapefiles</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org\">readxl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To read Excel files</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"http://haozhu233.github.io/kableExtra/\">kableExtra</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For data tables</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org\">ggplot2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/\">ggtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://github.com/yixuan/showtext\">showtext</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com\">patchwork</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To combine multiple ggplots</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://colorspace.R-Forge.R-project.org/\">colorspace</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># For color palettes</span></span>\n<span><span class=\"kw\" style=\"color: #003B4F;\nbackground-color: null;\nfont-weight: bold;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/library.html\">library</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">grid</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To add lines and text elements to graphical objects</span></span></code></pre></div></div>\n</div>\n</section><section class=\"level2\" id=\"loading-data\"><h2 class=\"anchored\" data-anchor-id=\"loading-data\">Loading data</h2>\n<p>I saved the information from Table A.1: <em>Intimate-partner violence by background characteristics</em> in the Excel file <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia//../../..\\intimate-partner-violence-cambodia.xlsx\">intimate-partner-violence-cambodia.xlsx</a>.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb2\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ipv_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://readxl.tidyverse.org/reference/read_excel.html\">read_excel</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"intimate-partner-violence-cambodia.xlsx\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>This information looks like this:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb3\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ipv_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/kableExtra/man/kbl.html\">kbl</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Lifetime experience of specific acts of intimate partner physical violence committed by their current or most recent partner by provinces, Cambodia 2021-22\"</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/kableExtra/man/kable_classic.html\">kable_paper</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"hover\"</span>, full_width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">F</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"cell-output-display\">\n<table class=\"lightable-paper lightable-hover caption-top table table-sm table-striped small\">\n<caption>Lifetime experience of specific acts of intimate partner physical violence committed by their current or most recent partner by provinces, Cambodia 2021-22</caption>\n<thead><tr class=\"header\">\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: left;\">Region</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Emotional violence</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Physical violence</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Sexual violence</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Physical or sexual</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Physical or sexual or emotional</th>\n<th data-quarto-table-cell-role=\"th\" style=\"text-align: right;\">Number of women who ever had a husband/intimate partner</th>\n</tr></thead>\n<tbody>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Banteay Meanchey</td>\n<td style=\"text-align: right;\">31.3</td>\n<td style=\"text-align: right;\">18.2</td>\n<td style=\"text-align: right;\">4.6</td>\n<td style=\"text-align: right;\">20.2</td>\n<td style=\"text-align: right;\">34.9</td>\n<td style=\"text-align: right;\">235</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Battambang</td>\n<td style=\"text-align: right;\">24.9</td>\n<td style=\"text-align: right;\">16.1</td>\n<td style=\"text-align: right;\">6.3</td>\n<td style=\"text-align: right;\">19.8</td>\n<td style=\"text-align: right;\">30.4</td>\n<td style=\"text-align: right;\">378</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Kampong Cham</td>\n<td style=\"text-align: right;\">7.7</td>\n<td style=\"text-align: right;\">5.2</td>\n<td style=\"text-align: right;\">1.1</td>\n<td style=\"text-align: right;\">5.8</td>\n<td style=\"text-align: right;\">11.5</td>\n<td style=\"text-align: right;\">352</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Kampong Chhnang</td>\n<td style=\"text-align: right;\">19.2</td>\n<td style=\"text-align: right;\">6.7</td>\n<td style=\"text-align: right;\">1.7</td>\n<td style=\"text-align: right;\">6.7</td>\n<td style=\"text-align: right;\">19.2</td>\n<td style=\"text-align: right;\">213</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Kampong Speu</td>\n<td style=\"text-align: right;\">16.6</td>\n<td style=\"text-align: right;\">9.5</td>\n<td style=\"text-align: right;\">2.6</td>\n<td style=\"text-align: right;\">10.1</td>\n<td style=\"text-align: right;\">19.1</td>\n<td style=\"text-align: right;\">362</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Kampong Thom</td>\n<td style=\"text-align: right;\">32.4</td>\n<td style=\"text-align: right;\">12.1</td>\n<td style=\"text-align: right;\">5.0</td>\n<td style=\"text-align: right;\">14.4</td>\n<td style=\"text-align: right;\">35.1</td>\n<td style=\"text-align: right;\">242</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Kampot</td>\n<td style=\"text-align: right;\">20.8</td>\n<td style=\"text-align: right;\">6.4</td>\n<td style=\"text-align: right;\">4.0</td>\n<td style=\"text-align: right;\">9.0</td>\n<td style=\"text-align: right;\">23.0</td>\n<td style=\"text-align: right;\">218</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Kandal</td>\n<td style=\"text-align: right;\">23.9</td>\n<td style=\"text-align: right;\">6.2</td>\n<td style=\"text-align: right;\">2.0</td>\n<td style=\"text-align: right;\">6.5</td>\n<td style=\"text-align: right;\">23.9</td>\n<td style=\"text-align: right;\">423</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Koh Kong</td>\n<td style=\"text-align: right;\">5.4</td>\n<td style=\"text-align: right;\">3.8</td>\n<td style=\"text-align: right;\">0.4</td>\n<td style=\"text-align: right;\">3.8</td>\n<td style=\"text-align: right;\">6.2</td>\n<td style=\"text-align: right;\">41</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Kratie</td>\n<td style=\"text-align: right;\">13.7</td>\n<td style=\"text-align: right;\">9.1</td>\n<td style=\"text-align: right;\">2.8</td>\n<td style=\"text-align: right;\">10.2</td>\n<td style=\"text-align: right;\">15.9</td>\n<td style=\"text-align: right;\">138</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Mondul Kiri</td>\n<td style=\"text-align: right;\">42.7</td>\n<td style=\"text-align: right;\">19.0</td>\n<td style=\"text-align: right;\">3.6</td>\n<td style=\"text-align: right;\">19.4</td>\n<td style=\"text-align: right;\">45.2</td>\n<td style=\"text-align: right;\">34</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Phnom Penh</td>\n<td style=\"text-align: right;\">10.3</td>\n<td style=\"text-align: right;\">5.1</td>\n<td style=\"text-align: right;\">1.3</td>\n<td style=\"text-align: right;\">5.8</td>\n<td style=\"text-align: right;\">11.0</td>\n<td style=\"text-align: right;\">904</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Preah Vihear</td>\n<td style=\"text-align: right;\">38.1</td>\n<td style=\"text-align: right;\">20.2</td>\n<td style=\"text-align: right;\">8.5</td>\n<td style=\"text-align: right;\">22.4</td>\n<td style=\"text-align: right;\">40.0</td>\n<td style=\"text-align: right;\">108</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Prey Veng</td>\n<td style=\"text-align: right;\">25.0</td>\n<td style=\"text-align: right;\">7.2</td>\n<td style=\"text-align: right;\">1.7</td>\n<td style=\"text-align: right;\">8.6</td>\n<td style=\"text-align: right;\">26.3</td>\n<td style=\"text-align: right;\">366</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Pursat</td>\n<td style=\"text-align: right;\">10.8</td>\n<td style=\"text-align: right;\">3.6</td>\n<td style=\"text-align: right;\">0.7</td>\n<td style=\"text-align: right;\">3.6</td>\n<td style=\"text-align: right;\">10.8</td>\n<td style=\"text-align: right;\">111</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Ratanak Kiri</td>\n<td style=\"text-align: right;\">24.7</td>\n<td style=\"text-align: right;\">6.6</td>\n<td style=\"text-align: right;\">0.8</td>\n<td style=\"text-align: right;\">7.1</td>\n<td style=\"text-align: right;\">25.7</td>\n<td style=\"text-align: right;\">96</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Siemreap</td>\n<td style=\"text-align: right;\">21.5</td>\n<td style=\"text-align: right;\">12.0</td>\n<td style=\"text-align: right;\">2.9</td>\n<td style=\"text-align: right;\">13.5</td>\n<td style=\"text-align: right;\">24.6</td>\n<td style=\"text-align: right;\">482</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Preah Sihanouk</td>\n<td style=\"text-align: right;\">10.3</td>\n<td style=\"text-align: right;\">3.4</td>\n<td style=\"text-align: right;\">1.6</td>\n<td style=\"text-align: right;\">4.0</td>\n<td style=\"text-align: right;\">10.8</td>\n<td style=\"text-align: right;\">75</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Stung Treng</td>\n<td style=\"text-align: right;\">29.3</td>\n<td style=\"text-align: right;\">12.5</td>\n<td style=\"text-align: right;\">7.5</td>\n<td style=\"text-align: right;\">16.3</td>\n<td style=\"text-align: right;\">31.5</td>\n<td style=\"text-align: right;\">66</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Svay Rieng</td>\n<td style=\"text-align: right;\">10.9</td>\n<td style=\"text-align: right;\">8.3</td>\n<td style=\"text-align: right;\">2.1</td>\n<td style=\"text-align: right;\">8.8</td>\n<td style=\"text-align: right;\">13.6</td>\n<td style=\"text-align: right;\">217</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Takeo</td>\n<td style=\"text-align: right;\">18.4</td>\n<td style=\"text-align: right;\">7.4</td>\n<td style=\"text-align: right;\">1.2</td>\n<td style=\"text-align: right;\">8.0</td>\n<td style=\"text-align: right;\">19.3</td>\n<td style=\"text-align: right;\">344</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Otdar Meanchey</td>\n<td style=\"text-align: right;\">15.1</td>\n<td style=\"text-align: right;\">6.1</td>\n<td style=\"text-align: right;\">0.0</td>\n<td style=\"text-align: right;\">6.1</td>\n<td style=\"text-align: right;\">15.4</td>\n<td style=\"text-align: right;\">77</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Kep</td>\n<td style=\"text-align: right;\">8.0</td>\n<td style=\"text-align: right;\">7.2</td>\n<td style=\"text-align: right;\">1.2</td>\n<td style=\"text-align: right;\">7.7</td>\n<td style=\"text-align: right;\">11.0</td>\n<td style=\"text-align: right;\">18</td>\n</tr>\n<tr class=\"even\">\n<td style=\"text-align: left;\">Pailin</td>\n<td style=\"text-align: right;\">11.3</td>\n<td style=\"text-align: right;\">9.5</td>\n<td style=\"text-align: right;\">1.7</td>\n<td style=\"text-align: right;\">9.5</td>\n<td style=\"text-align: right;\">14.2</td>\n<td style=\"text-align: right;\">29</td>\n</tr>\n<tr class=\"odd\">\n<td style=\"text-align: left;\">Tboung Khmum</td>\n<td style=\"text-align: right;\">11.1</td>\n<td style=\"text-align: right;\">7.3</td>\n<td style=\"text-align: right;\">2.3</td>\n<td style=\"text-align: right;\">7.3</td>\n<td style=\"text-align: right;\">14.0</td>\n<td style=\"text-align: right;\">252</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n<p>Now, we load geographical data of the administrative division of Cambodia. These data are obtained from the <a href=\"https://data.humdata.org/\">Humanitarian Data Exchange (HDX) initiative</a> of the United Nations Office for the Coordination of Humanitarian Affairs (OCHA). The information comes as a shapefile <code>.shp</code> and is available <a href=\"https://data.humdata.org/dataset/cod-ab-khm\">here</a> in a zip file named <code>som_adm_ocha_20250108_AB_SHP.zip</code>. I downloaded this file and located it in <code>/khmadm_gov_20181004_ab_shp</code> folder.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb4\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://r-spatial.github.io/sf/reference/st_read.html\">read_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"khmadm_gov_20181004_ab_shp/khm_admbnda_adm1_gov_20181004.shp\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<section class=\"level3\" id=\"data-wrangling\"><h3 class=\"anchored\" data-anchor-id=\"data-wrangling\">Data wrangling</h3>\n<p>Next step is to combine the geographic information from the shapefile, <code>shp_cambodia</code>, with the data frame with the information on IPV, <code>ipv_cambodia</code>. To achieve this goal, we need to make sure that both datasets have a common variable to merge them. In this case, we will use the province name <code>ADM1_EN</code> in the shapefile and <code>Region</code> in the data frame. Then, I compare if the names of the provinces in both datasets match:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb5\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://generics.r-lib.org/reference/setops.html\">setdiff</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ADM1_EN</span>, <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ipv_cambodia</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">$</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">Region</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n<div class=\"cell-output cell-output-stdout\">\n<pre><code>[1] \"Oddar Meanchey\"</code></pre>\n</div>\n</div>\n<p>The output indicates that there is one discrepancy. In <code>shp_cambodia</code>, the name of the province \"Oddar Meanchey\" corresponds to \"Otdar Meanchey\" in <code>ipv_cambodia</code>. I will rename this province in the shapefile to match the name in the data from the official report.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb7\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate.html\">mutate</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>ADM1_EN <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/case_when.html\">case_when</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ADM1_EN</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">==</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Oddar Meanchey\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Otdar Meanchey\"</span>,</span>\n<span>    <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">~</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ADM1_EN</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>After this modification, I join both datasets using a left join to keep all the provinces in the shapefile and add the corresponding IPV values from the data frame:</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb8\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">|&gt;</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://dplyr.tidyverse.org/reference/mutate-joins.html\">left_join</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">ipv_cambodia</span>, by <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"ADM1_EN\"</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Region\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n</section></section><section class=\"level2\" id=\"creating-the-map\"><h2 class=\"anchored\" data-anchor-id=\"creating-the-map\">Creating the map</h2>\n<p>My idea is to develop three maps, each representing one type of violence against women and girls: emotional, physical, and sexual. I will first create the map corresponding to emotional violence.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb9\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># More font alternatives can be found here https://fonts.google.com/</span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/sysfonts/man/font_add_google.html\">font_add_google</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> </span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/pkg/showtext/man/showtext_auto.html\">showtext_auto</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_emotional_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>, </span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Emotional violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Color of the province borders</span></span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Emotional violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    check_overlap <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># To avoid overlaping text in the plot</span></span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    fontface <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_gradient.html\">scale_fill_gradient2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    low <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFFE9EB3\"</span>,</span>\n<span>    mid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#C53270B3\"</span>,</span>\n<span>    high <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#040404B3\"</span>,</span>\n<span>    midpoint <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22.5</span>,</span>\n<span>    limits <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">45</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    breaks <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">15</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">30</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">45</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    labels <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"0\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"15\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"30\"</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"45\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Emotional\"</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title of this subplot</span></span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Percentage of victims (%)\"</span> <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title of the legend</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    </span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># No color in the background</span></span>\n<span>    plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22</span>,</span>\n<span>      hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Now, I replicate the same format for physical and sexual violence.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb10\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_physical_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>, </span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Physical violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>, </span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Physical violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    check_overlap <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span>,</span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    fontface <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_gradient.html\">scale_fill_gradient2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    low <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFFE9EB3\"</span>,</span>\n<span>    mid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#C53270B3\"</span>,</span>\n<span>    high <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#040404B3\"</span>,</span>\n<span>    midpoint <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22.5</span>,</span>\n<span>    limits <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">45</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Physical\"</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> </span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guides.html\">guides</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"none\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    </span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22</span>,</span>\n<span>      hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_sexual_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggplot.html\">ggplot</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>, </span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Sexual violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"white\"</span>, </span>\n<span>    linewidth <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggsf.html\">geom_sf_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    data <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">shp_cambodia</span>,</span>\n<span>    <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/aes.html\">aes</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>label <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">`Sexual violence`</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    check_overlap <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"cn\" style=\"color: #8f5902;\nbackground-color: null;\nfont-style: inherit;\">TRUE</span>,</span>\n<span>    size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4</span>, </span>\n<span>    color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>    fontface <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/scale_gradient.html\">scale_fill_gradient2</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    low <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#FFFE9EB3\"</span>,</span>\n<span>    mid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#C53270B3\"</span>,</span>\n<span>    high <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#040404B3\"</span>,</span>\n<span>    midpoint <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22.5</span>,</span>\n<span>    limits <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">45</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/labs.html\">labs</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Sexual\"</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span>,</span>\n<span>    fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> </span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/guides.html\">guides</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"none\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    plot.margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    </span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">22</span>,</span>\n<span>      hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span>,</span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Now, using {patchwork} package, I combine the three plots into one single representation. I also use <code><a href=\"https://patchwork.data-imaginist.com/reference/plot_annotation.html\">plot_annotation()</a></code> function to add a title, subtitle, and caption to the overall design.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb11\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Design display two rows, one with the three maps, and the second one only with the common guide</span></span>\n<span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&lt;-</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_emotional_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_physical_cambodia</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> <span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_sexual_cambodia</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">/</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com/reference/guide_area.html\">guide_area</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> </span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom title, subtitle, and caption</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com/reference/plot_annotation.html\">plot_annotation</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Intimate partner violence in Cambodia, 2021-22\"</span>,</span>\n<span>    subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Proportion of ever-partnered women and girls aged 15-49 who have been victims of violence perpetrated by their intimate partner, by type of violence.\"</span>,</span>\n<span>    caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"**Data:** 2021-22 Cambodia Demographic and Health Survey (CDHS) &lt;br&gt; **Chart:** Juan Torres Mungu\u00eda\"</span>,</span>\n<span>    theme <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Title settings</span></span>\n<span>      plot.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"plot\"</span>, </span>\n<span>      plot.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>        face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">30</span>,</span>\n<span>        hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">50</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>      <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      </span>\n<span>      plot.subtitle <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>        color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey20\"</span>,</span>\n<span>        size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">25</span>,</span>\n<span>        hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>        margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">40</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">50</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>        <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>        </span>\n<span>        <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Caption settings</span></span>\n<span>        <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># I use element_markdown() because the caption has markdown text</span></span>\n<span>        plot.caption <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://wilkelab.org/ggtext/reference/element_markdown.html\">element_markdown</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>          color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"black\"</span>,</span>\n<span>          size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">15</span>,</span>\n<span>          hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>,</span>\n<span>          margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">80</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">50</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>        <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span></span>\n<span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://patchwork.data-imaginist.com/reference/plot_layout.html\">plot_layout</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>guides <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"collect\"</span>,</span>\n<span>              heights <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">13</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>               <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">'cm'</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">'cm'</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>              <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">+</span> </span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/ggtheme.html\">theme_minimal</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    base_family <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"Scada\"</span></span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span> <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">&amp;</span></span>\n<span>  <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Custom theme settings</span></span>\n<span>  <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/theme.html\">theme</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>    legend.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bottom\"</span>,</span>\n<span>    legend.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">10</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span>,</span>\n<span>      hjust <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.5</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.title.position <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"top\"</span>,</span>\n<span>    legend.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_text</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      margin <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">margin</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">5</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, </span>\n<span>      face <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"bold\"</span>,</span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"grey10\"</span>,</span>\n<span>      size <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">14</span></span>\n<span>    <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.key.width <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1.4</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.key.height <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/unit.html\">unit</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">1</span>, <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"cm\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    legend.direction <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"horizontal\"</span>,</span>\n<span></span>\n<span>    plot.background <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_rect</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>      color <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E5E5E5\"</span>,</span>\n<span>      fill <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#E5E5E5\"</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Axis settings</span></span>\n<span>    axis.title <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.line <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.text <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    axis.ticks <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>,</span>\n<span>    panel.grid <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://ggplot2.tidyverse.org/reference/element.html\">element_blank</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span>    </span>\n<span>  <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p>Finally, I use <code><a href=\"https://rdrr.io/r/grid/grid.lines.html\">grid.lines()</a></code> from {grid} package to add a horizontal line after the subtitle.</p>\n<div class=\"cell\">\n<div class=\"code-copy-outer-scaffold\"><div class=\"sourceCode\" id=\"cb12\" style=\"background: #f1f3f5;\"><pre class=\"downlit sourceCode r code-with-copy\"><code class=\"sourceCode R\"><span><span class=\"va\" style=\"color: #111111;\nbackground-color: null;\nfont-style: inherit;\">map_ipv_cambodia</span></span>\n<span></span>\n<span><span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/grid.lines.html\">grid.lines</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span></span>\n<span>  x <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/base/c.html\">c</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span><span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.04</span>, <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.96</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Values should be between 0 and 1</span></span>\n<span>  y <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">0.88</span>, <span class=\"co\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\"># Value should be between 0 and 1</span></span>\n<span>  gp <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fu\" style=\"color: #4758AB;\nbackground-color: null;\nfont-style: inherit;\"><a href=\"https://rdrr.io/r/grid/gpar.html\">gpar</a></span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">(</span>col <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"st\" style=\"color: #20794D;\nbackground-color: null;\nfont-style: inherit;\">\"#C53270B3\"</span>, </span>\n<span>            lwd <span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">=</span> <span class=\"fl\" style=\"color: #AD0000;\nbackground-color: null;\nfont-style: inherit;\">4</span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span>\n<span><span class=\"op\" style=\"color: #5E5E5E;\nbackground-color: null;\nfont-style: inherit;\">)</span></span></code></pre></div></div>\n</div>\n<p><a class=\"lightbox\" data-gallery=\"quarto-lightbox-gallery-2\" href=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia//ipv-cambodia-map.png\"><img class=\"img-fluid\" src=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/ipv-cambodia-map.png\" style=\"margin-top: 0px; margin-bottom: 0px;;width:100.0%\"/></a></p>\n</section><div class=\"default\" id=\"quarto-appendix\"><section class=\"quarto-appendix-contents\" id=\"quarto-citation\"><h2 class=\"anchored quarto-appendix-heading\">Citation</h2><div><div class=\"quarto-appendix-secondary-label\">BibTeX citation:</div><pre class=\"sourceCode code-with-copy quarto-appendix-bibtex\"><code class=\"sourceCode bibtex\">@online{torres_mungu\u00eda2025,\n  author = {Torres Mungu\u00eda, Juan Armando},\n  title = {Three Maps to Examine the Prevalence of Intimate Partner\n    Violence {(IPV)} in {Cambodia}},\n  date = {2025-05-10},\n  url = {https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/},\n  langid = {en}\n}\n</code></pre><div class=\"quarto-appendix-secondary-label\">For attribution, please cite this work as:</div><div class=\"csl-entry quarto-appendix-citeas\" id=\"ref-torres_mungu\u00eda2025\">\nTorres Mungu\u00eda, Juan Armando. 2025. <span>\"Three Maps to Examine the\nPrevalence of Intimate Partner Violence (IPV) in Cambodia.\"</span> May\n10, 2025. <a href=\"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/\">https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/</a>.\n</div></div></section></div>","doi":"https://doi.org/10.59350/xc58v-hjg76","guid":"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/","image":"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/ipv-cambodia-map.png","language":"en","license":"https://creativecommons.org/licenses/by/4.0/legalcode","published_at":1746835200,"rid":"pn84n-7h484","summary":"Overview According to the 2021-22 Domestic Violence module of the Kingdom of Cambodia's Demographic and Health Survey (CDHS), over 21% of Cambodian women aged 15\u201349 who have ever had a husband (or intimate partner), have experienced physical, sexual, economic, and/or emotional intimate partner violence in their lifetime.","tags":["Data Visualization","Intimate Partner Violence (IPV)","Tidyverse","Ggplot2","Shapefiles"],"title":"Three maps to examine the prevalence of intimate partner violence (IPV) in Cambodia","updated_at":1790603797,"url":"https://juan-torresmunguia.netlify.app/blog/posts/map-intimate-partner-violence-cambodia/","version":"v1"}],"out_of":57669,"page":1,"per_page":10,"total-results":57669}
