{"id":199,"date":"2018-10-25T21:40:29","date_gmt":"2018-10-25T21:40:29","guid":{"rendered":"https:\/\/spectdata.com\/?p=199"},"modified":"2020-12-15T22:22:42","modified_gmt":"2020-12-15T11:22:42","slug":"how-to-use-ggplot-to-plot-pie-charts-on-a-map","status":"publish","type":"post","link":"https:\/\/spectdata.com\/index.php\/2018\/10\/25\/how-to-use-ggplot-to-plot-pie-charts-on-a-map\/","title":{"rendered":"Using ggplot to plot pie charts on a geographical map"},"content":{"rendered":"<p>In this post, we would go through the steps to plot pie charts on a world map, just like the one below.<\/p>\n<figure id=\"attachment_202\" aria-describedby=\"caption-attachment-202\" style=\"width: 540px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-202\" src=\"https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/1.-Map-plot-Leading-causes-of-death-by-country-300x196.png\" alt=\"\" width=\"540\" height=\"353\" srcset=\"https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/1.-Map-plot-Leading-causes-of-death-by-country-300x196.png 300w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/1.-Map-plot-Leading-causes-of-death-by-country-768x502.png 768w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/1.-Map-plot-Leading-causes-of-death-by-country-1024x670.png 1024w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/1.-Map-plot-Leading-causes-of-death-by-country-648x424.png 648w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/1.-Map-plot-Leading-causes-of-death-by-country-294x192.png 294w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><figcaption id=\"caption-attachment-202\" class=\"wp-caption-text\">Plot showing the leading causes of death in the year 2014 for various countries<\/figcaption><\/figure>\n<p>This image probably scared you as much as it did to me when I realized I need to create something the same as this. &#8220;How am I supposed to do this thing when I&#8217;m not even good in R programming, in fact, a newbie?&#8221; You&#8217;re probably asking this to yourself right now, or you already did. I feel you, but I got you. I struggled so much on doing my first map plot, that&#8217;s why I&#8217;ll be sharing to you the step-by-step ways on how to do it using ggplot, to save you from all the google searches and trial-and-error.<\/p>\n<p>With that, we will be answering a specific question using real-world data as we go along these steps.<\/p>\n<p>&#8220;Are there differences in the distribution of causes of death per country?&#8221;<\/p>\n<p>I managed to acquire a decent data about death causes in the world per country from <a href=\"https:\/\/www.kaggle.com\/dataquantum\/death2014\">kaggle.com<\/a> which will be used in our illustrations and simulations.<\/p>\n<p><strong>Prepare the Data<\/strong><\/p>\n<p>The first thing that we need to do is to make sure that our data is complete, that we have what we need prior to plotting. In this case, we need the data for the death causes per country and, the coordinates of each country. Then, we will load it to our work environment as below.<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist92653900\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-data_prep-r\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-r  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"data_prep.r content, created by mfmakahiya on 12:05PM on October 25, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"data_prep.r\">\n        <tr>\n          <td id=\"file-data_prep-r-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-data_prep-r-LC1\" class=\"blob-code blob-code-inner js-file-line\">rm(list=ls())<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-data_prep-r-LC2\" class=\"blob-code blob-code-inner js-file-line\">library(memisc)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-data_prep-r-LC3\" class=\"blob-code blob-code-inner js-file-line\">library(assertthat)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-data_prep-r-LC4\" class=\"blob-code blob-code-inner js-file-line\">library(sqldf)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-data_prep-r-LC5\" class=\"blob-code blob-code-inner js-file-line\">library(magrittr)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-data_prep-r-LC6\" class=\"blob-code blob-code-inner js-file-line\">library(dplyr)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-data_prep-r-LC7\" class=\"blob-code blob-code-inner js-file-line\">library(reshape2)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-data_prep-r-LC8\" class=\"blob-code blob-code-inner js-file-line\">library(ggplot2)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-data_prep-r-LC9\" class=\"blob-code blob-code-inner js-file-line\">library(oz)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-data_prep-r-LC10\" class=\"blob-code blob-code-inner js-file-line\">library(scatterpie)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-data_prep-r-LC11\" class=\"blob-code blob-code-inner js-file-line\">library(rgdal)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-data_prep-r-LC12\" class=\"blob-code blob-code-inner js-file-line\">library(maptools)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-data_prep-r-LC13\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-data_prep-r-LC14\" class=\"blob-code blob-code-inner js-file-line\"># Helper functions<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-data_prep-r-LC15\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-data_prep-r-LC16\" class=\"blob-code blob-code-inner js-file-line\">data_prep &lt;- function(csv_name) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-data_prep-r-LC17\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L18\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"18\"><\/td>\n          <td id=\"file-data_prep-r-LC18\" class=\"blob-code blob-code-inner js-file-line\">  import &lt;- read.csv(paste0(&quot;.\/Data\/&quot;, csv_name), stringsAsFactors = F)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L19\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"19\"><\/td>\n          <td id=\"file-data_prep-r-LC19\" class=\"blob-code blob-code-inner js-file-line\">  names(import) &lt;- tolower(names(import))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L20\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"20\"><\/td>\n          <td id=\"file-data_prep-r-LC20\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L21\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"21\"><\/td>\n          <td id=\"file-data_prep-r-LC21\" class=\"blob-code blob-code-inner js-file-line\">  import &lt;- import[, c(&quot;country.or.area&quot;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L22\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"22\"><\/td>\n          <td id=\"file-data_prep-r-LC22\" class=\"blob-code blob-code-inner js-file-line\">                       &quot;sex&quot;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L23\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"23\"><\/td>\n          <td id=\"file-data_prep-r-LC23\" class=\"blob-code blob-code-inner js-file-line\">                       &quot;age&quot;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L24\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"24\"><\/td>\n          <td id=\"file-data_prep-r-LC24\" class=\"blob-code blob-code-inner js-file-line\">                       &quot;cause.of.death..who.&quot;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L25\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"25\"><\/td>\n          <td id=\"file-data_prep-r-LC25\" class=\"blob-code blob-code-inner js-file-line\">                       &quot;record.type&quot;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L26\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"26\"><\/td>\n          <td id=\"file-data_prep-r-LC26\" class=\"blob-code blob-code-inner js-file-line\">                       &quot;value&quot;)]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L27\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"27\"><\/td>\n          <td id=\"file-data_prep-r-LC27\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L28\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"28\"><\/td>\n          <td id=\"file-data_prep-r-LC28\" class=\"blob-code blob-code-inner js-file-line\">  names(import) &lt;- c(&quot;country&quot;, &quot;sex&quot;, &quot;age&quot;, &quot;death_cause&quot;, &quot;record_type&quot;, &quot;value&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L29\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"29\"><\/td>\n          <td id=\"file-data_prep-r-LC29\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L30\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"30\"><\/td>\n          <td id=\"file-data_prep-r-LC30\" class=\"blob-code blob-code-inner js-file-line\">  assert_that(length(names(import)) == 6)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L31\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"31\"><\/td>\n          <td id=\"file-data_prep-r-LC31\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L32\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"32\"><\/td>\n          <td id=\"file-data_prep-r-LC32\" class=\"blob-code blob-code-inner js-file-line\">  return(import)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L33\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"33\"><\/td>\n          <td id=\"file-data_prep-r-LC33\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L34\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"34\"><\/td>\n          <td id=\"file-data_prep-r-LC34\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L35\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"35\"><\/td>\n          <td id=\"file-data_prep-r-LC35\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L36\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"36\"><\/td>\n          <td id=\"file-data_prep-r-LC36\" class=\"blob-code blob-code-inner js-file-line\">###############<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L37\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"37\"><\/td>\n          <td id=\"file-data_prep-r-LC37\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L38\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"38\"><\/td>\n          <td id=\"file-data_prep-r-LC38\" class=\"blob-code blob-code-inner js-file-line\">perform_groupby &lt;- function(data, sex_filter, record_filter) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L39\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"39\"><\/td>\n          <td id=\"file-data_prep-r-LC39\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L40\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"40\"><\/td>\n          <td id=\"file-data_prep-r-LC40\" class=\"blob-code blob-code-inner js-file-line\">  #data &lt;- import<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L41\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"41\"><\/td>\n          <td id=\"file-data_prep-r-LC41\" class=\"blob-code blob-code-inner js-file-line\">  #sex_filter &lt;- &quot;Female&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L42\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"42\"><\/td>\n          <td id=\"file-data_prep-r-LC42\" class=\"blob-code blob-code-inner js-file-line\">  #record_filter &lt;- &quot;Data tabulated by year of occurrence&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L43\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"43\"><\/td>\n          <td id=\"file-data_prep-r-LC43\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L44\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"44\"><\/td>\n          <td id=\"file-data_prep-r-LC44\" class=\"blob-code blob-code-inner js-file-line\">  final_data &lt;- data %&gt;%<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L45\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"45\"><\/td>\n          <td id=\"file-data_prep-r-LC45\" class=\"blob-code blob-code-inner js-file-line\">    filter (!sex == sex_filter, record_type == record_filter) %&gt;%<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L46\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"46\"><\/td>\n          <td id=\"file-data_prep-r-LC46\" class=\"blob-code blob-code-inner js-file-line\">    group_by(country, death_cause) %&gt;%<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L47\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"47\"><\/td>\n          <td id=\"file-data_prep-r-LC47\" class=\"blob-code blob-code-inner js-file-line\">    summarise(count = sum(value)) %&gt;%<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L48\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"48\"><\/td>\n          <td id=\"file-data_prep-r-LC48\" class=\"blob-code blob-code-inner js-file-line\">    ungroup %&gt;%<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L49\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"49\"><\/td>\n          <td id=\"file-data_prep-r-LC49\" class=\"blob-code blob-code-inner js-file-line\">    as.data.frame()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L50\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"50\"><\/td>\n          <td id=\"file-data_prep-r-LC50\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L51\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"51\"><\/td>\n          <td id=\"file-data_prep-r-LC51\" class=\"blob-code blob-code-inner js-file-line\">  return(final_data)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L52\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"52\"><\/td>\n          <td id=\"file-data_prep-r-LC52\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L53\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"53\"><\/td>\n          <td id=\"file-data_prep-r-LC53\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L54\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"54\"><\/td>\n          <td id=\"file-data_prep-r-LC54\" class=\"blob-code blob-code-inner js-file-line\">pivot_by_country &lt;- function(data) {<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L55\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"55\"><\/td>\n          <td id=\"file-data_prep-r-LC55\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L56\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"56\"><\/td>\n          <td id=\"file-data_prep-r-LC56\" class=\"blob-code blob-code-inner js-file-line\">  s1 = melt(data, id = c(&quot;country&quot;, &quot;death_cause&quot;), measure.vars = &quot;count&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L57\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"57\"><\/td>\n          <td id=\"file-data_prep-r-LC57\" class=\"blob-code blob-code-inner js-file-line\">  s2 = dcast(s1, country ~ death_cause, sum)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L58\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"58\"><\/td>\n          <td id=\"file-data_prep-r-LC58\" class=\"blob-code blob-code-inner js-file-line\">  <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L59\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"59\"><\/td>\n          <td id=\"file-data_prep-r-LC59\" class=\"blob-code blob-code-inner js-file-line\">  s2$Total = rowSums(s2[,2:NCOL(s2)])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L60\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"60\"><\/td>\n          <td id=\"file-data_prep-r-LC60\" class=\"blob-code blob-code-inner js-file-line\">  return(s2)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L61\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"61\"><\/td>\n          <td id=\"file-data_prep-r-LC61\" class=\"blob-code blob-code-inner js-file-line\">}<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L62\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"62\"><\/td>\n          <td id=\"file-data_prep-r-LC62\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L63\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"63\"><\/td>\n          <td id=\"file-data_prep-r-LC63\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L64\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"64\"><\/td>\n          <td id=\"file-data_prep-r-LC64\" class=\"blob-code blob-code-inner js-file-line\"># Main Logic<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L65\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"65\"><\/td>\n          <td id=\"file-data_prep-r-LC65\" class=\"blob-code blob-code-inner js-file-line\">death_data &lt;- data_prep(&quot;death2014.csv&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L66\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"66\"><\/td>\n          <td id=\"file-data_prep-r-LC66\" class=\"blob-code blob-code-inner js-file-line\">grouped_data &lt;- perform_groupby(death_data, &quot;&quot;, &quot;Data tabulated by year of occurrence&quot;) # Data tabulated by year of occurrence # Data tabulated by year of registration<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L67\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"67\"><\/td>\n          <td id=\"file-data_prep-r-LC67\" class=\"blob-code blob-code-inner js-file-line\">grouped_data$death_cause &lt;- gsub(&quot;*, ICD10&quot;, &quot;&quot;, grouped_data$death_cause)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L68\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"68\"><\/td>\n          <td id=\"file-data_prep-r-LC68\" class=\"blob-code blob-code-inner js-file-line\">grouped_data$death_cause &lt;- gsub(&quot;Symptoms, signs and abnormal clinical and laboratory findings, not elsewhere classified&quot;, &quot;Abnormal clinical and lab findings&quot;, grouped_data$death_cause)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L69\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"69\"><\/td>\n          <td id=\"file-data_prep-r-LC69\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L70\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"70\"><\/td>\n          <td id=\"file-data_prep-r-LC70\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L71\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"71\"><\/td>\n          <td id=\"file-data_prep-r-LC71\" class=\"blob-code blob-code-inner js-file-line\"># Top 10 leading cause overall<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L72\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"72\"><\/td>\n          <td id=\"file-data_prep-r-LC72\" class=\"blob-code blob-code-inner js-file-line\">overall_data &lt;- grouped_data %&gt;%<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L73\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"73\"><\/td>\n          <td id=\"file-data_prep-r-LC73\" class=\"blob-code blob-code-inner js-file-line\">  group_by(death_cause) %&gt;%<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L74\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"74\"><\/td>\n          <td id=\"file-data_prep-r-LC74\" class=\"blob-code blob-code-inner js-file-line\">  summarise(totalcount = sum(count)) %&gt;%<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L75\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"75\"><\/td>\n          <td id=\"file-data_prep-r-LC75\" class=\"blob-code blob-code-inner js-file-line\">  ungroup %&gt;%<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L76\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"76\"><\/td>\n          <td id=\"file-data_prep-r-LC76\" class=\"blob-code blob-code-inner js-file-line\">  as.data.frame()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L77\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"77\"><\/td>\n          <td id=\"file-data_prep-r-LC77\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L78\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"78\"><\/td>\n          <td id=\"file-data_prep-r-LC78\" class=\"blob-code blob-code-inner js-file-line\">overall_data &lt;- overall_data[order(-overall_data$totalcount), ]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L79\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"79\"><\/td>\n          <td id=\"file-data_prep-r-LC79\" class=\"blob-code blob-code-inner js-file-line\">top_ten_causes &lt;- overall_data[2:10, &quot;death_cause&quot;]<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L80\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"80\"><\/td>\n          <td id=\"file-data_prep-r-LC80\" class=\"blob-code blob-code-inner js-file-line\">top_ten_causes &lt;- gsub(&quot;*, ICD10&quot;, &quot;&quot;, top_ten_causes)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L81\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"81\"><\/td>\n          <td id=\"file-data_prep-r-LC81\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L82\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"82\"><\/td>\n          <td id=\"file-data_prep-r-LC82\" class=\"blob-code blob-code-inner js-file-line\">grouped_data$death_cause2 &lt;- grouped_data$death_cause<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L83\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"83\"><\/td>\n          <td id=\"file-data_prep-r-LC83\" class=\"blob-code blob-code-inner js-file-line\">grouped_data1 &lt;- grouped_data %&gt;%<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L84\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"84\"><\/td>\n          <td id=\"file-data_prep-r-LC84\" class=\"blob-code blob-code-inner js-file-line\">  filter (death_cause %in% top_ten_causes)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L85\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"85\"><\/td>\n          <td id=\"file-data_prep-r-LC85\" class=\"blob-code blob-code-inner js-file-line\">grouped_data2 &lt;- grouped_data %&gt;%<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L86\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"86\"><\/td>\n          <td id=\"file-data_prep-r-LC86\" class=\"blob-code blob-code-inner js-file-line\">  filter (!death_cause %in% c(top_ten_causes, &quot;All causes&quot;))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L87\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"87\"><\/td>\n          <td id=\"file-data_prep-r-LC87\" class=\"blob-code blob-code-inner js-file-line\">grouped_data2$death_cause2 &lt;- &quot;Others&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L88\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"88\"><\/td>\n          <td id=\"file-data_prep-r-LC88\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L89\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"89\"><\/td>\n          <td id=\"file-data_prep-r-LC89\" class=\"blob-code blob-code-inner js-file-line\">grouped_data &lt;- rbind(grouped_data1[, c(1,3,4)], grouped_data2[, c(1,3,4)])<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L90\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"90\"><\/td>\n          <td id=\"file-data_prep-r-LC90\" class=\"blob-code blob-code-inner js-file-line\">names(grouped_data) &lt;- c(&quot;country&quot;, &quot;count&quot;, &quot;death_cause&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L91\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"91\"><\/td>\n          <td id=\"file-data_prep-r-LC91\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L92\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"92\"><\/td>\n          <td id=\"file-data_prep-r-LC92\" class=\"blob-code blob-code-inner js-file-line\">pivotted_data &lt;- pivot_by_country(grouped_data)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L93\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"93\"><\/td>\n          <td id=\"file-data_prep-r-LC93\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L94\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"94\"><\/td>\n          <td id=\"file-data_prep-r-LC94\" class=\"blob-code blob-code-inner js-file-line\"># Getting the coordinates of each country<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L95\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"95\"><\/td>\n          <td id=\"file-data_prep-r-LC95\" class=\"blob-code blob-code-inner js-file-line\">country_lookup &lt;- read.csv(paste0(&quot;.\/Data\/&quot;, &quot;countries.csv&quot;), stringsAsFactors = F)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L96\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"96\"><\/td>\n          <td id=\"file-data_prep-r-LC96\" class=\"blob-code blob-code-inner js-file-line\">names(country_lookup)[1] &lt;- &quot;country_code&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L97\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"97\"><\/td>\n          <td id=\"file-data_prep-r-LC97\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L98\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"98\"><\/td>\n          <td id=\"file-data_prep-r-LC98\" class=\"blob-code blob-code-inner js-file-line\"># Combining data<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L99\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"99\"><\/td>\n          <td id=\"file-data_prep-r-LC99\" class=\"blob-code blob-code-inner js-file-line\">final_data &lt;- merge(x = pivotted_data, y = country_lookup, by.x = &quot;country&quot;, by.y = &quot;name&quot;, all.x = T)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L100\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"100\"><\/td>\n          <td id=\"file-data_prep-r-LC100\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L101\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"101\"><\/td>\n          <td id=\"file-data_prep-r-LC101\" class=\"blob-code blob-code-inner js-file-line\"># Data cleaning for plotting<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L102\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"102\"><\/td>\n          <td id=\"file-data_prep-r-LC102\" class=\"blob-code blob-code-inner js-file-line\">final_data &lt;- unique(final_data)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L103\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"103\"><\/td>\n          <td id=\"file-data_prep-r-LC103\" class=\"blob-code blob-code-inner js-file-line\">multiplier &lt;- log10(final_data$Total) \/ log10(max(final_data$Total))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-data_prep-r-L104\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"104\"><\/td>\n          <td id=\"file-data_prep-r-LC104\" class=\"blob-code blob-code-inner js-file-line\">final_data &lt;- cbind(final_data, multiplier)<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/94c97874d722714149c7fc432885e0c7\/raw\/993dd7024cd56237ac61ed7e8a6c55d5b82fc957\/data_prep.r\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/94c97874d722714149c7fc432885e0c7#file-data_prep-r\" class=\"Link--inTextBlock\">\n          data_prep.r\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<p>Once we\u2019ve completed all the needed data, we will proceed on deciding what method works for us for the map plot that we will be doing. We have a couple of options to use for ggplot since it is easy to get hold of the map data of the world.<\/p>\n<p><a href=\"https:\/\/www.rdocumentation.org\/\">Rdocumentation.org<\/a> has a very friendly documentation of most of r packages and functions so I would really recommend that you check it out if you&#8217;re new to R.<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist92653964\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-map_data-syntax-r\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-r  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"map_data() syntax.r content, created by mfmakahiya on 12:10PM on October 25, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"map_data() syntax.r\">\n        <tr>\n          <td id=\"file-map_data-syntax-r-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-map_data-syntax-r-LC1\" class=\"blob-code blob-code-inner js-file-line\">map_data(map, region = &quot;.&quot;, exact = FALSE, ...)<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/0d13c335676297130ffd58c47aacd2ab\/raw\/f6a9630e020488ebf782fba7c7f08899dd225d00\/map_data()%20syntax.r\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/0d13c335676297130ffd58c47aacd2ab#file-map_data-syntax-r\" class=\"Link--inTextBlock\">\n          map_data() syntax.r\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<p>where map is the name of the map provided in the <em>maps<\/em> package. map_data(\u201cworld\u201d) instantly gets the data we need to plot the world map.<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist92653993\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-borders-syntax-r\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-r  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"borders() syntax.r content, created by mfmakahiya on 12:11PM on October 25, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"borders() syntax.r\">\n        <tr>\n          <td id=\"file-borders-syntax-r-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-borders-syntax-r-LC1\" class=\"blob-code blob-code-inner js-file-line\">borders(database = &quot;world&quot;, regions = &quot;.&quot;, fill = NA,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-borders-syntax-r-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-borders-syntax-r-LC2\" class=\"blob-code blob-code-inner js-file-line\">  colour = &quot;grey50&quot;, xlim = NULL, ylim = NULL, ...)<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/2f3272af4078794cdc80798bd6f661ea\/raw\/73bb6e287fef2d510c7d5891f7f37b867913e037\/borders()%20syntax.r\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/2f3272af4078794cdc80798bd6f661ea#file-borders-syntax-r\" class=\"Link--inTextBlock\">\n          borders() syntax.r\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<p>where database is the map data you want to plot (check maps::map() for the available maps. borders(\u201cworld\u201d) gets the data to create the borders of the world.<\/p>\n<p>Lastly, using a shape (.shp) file. We will need to obtain a shape file of the map that we\u2019re interested at. In this case, I researched of a .shp file for the world and read the data using<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist92654016\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-readogr-syntax-r\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-r  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"readOGR() syntax.r content, created by mfmakahiya on 12:13PM on October 25, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"readOGR() syntax.r\">\n        <tr>\n          <td id=\"file-readogr-syntax-r-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-readogr-syntax-r-LC1\" class=\"blob-code blob-code-inner js-file-line\">readOGR(dsn, layer, verbose = TRUE, p4s=NULL, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-readogr-syntax-r-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-readogr-syntax-r-LC2\" class=\"blob-code blob-code-inner js-file-line\"> stringsAsFactors=default.stringsAsFactors(), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-readogr-syntax-r-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-readogr-syntax-r-LC3\" class=\"blob-code blob-code-inner js-file-line\"> drop_unsupported_fields=FALSE,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-readogr-syntax-r-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-readogr-syntax-r-LC4\" class=\"blob-code blob-code-inner js-file-line\"> pointDropZ=FALSE, dropNULLGeometries=TRUE,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-readogr-syntax-r-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-readogr-syntax-r-LC5\" class=\"blob-code blob-code-inner js-file-line\"> useC=TRUE, disambiguateFIDs=FALSE, addCommentsToPolygons=TRUE,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-readogr-syntax-r-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-readogr-syntax-r-LC6\" class=\"blob-code blob-code-inner js-file-line\"> encoding=NULL, use_iconv=FALSE, swapAxisOrder=FALSE, require_geomType = NULL,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-readogr-syntax-r-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-readogr-syntax-r-LC7\" class=\"blob-code blob-code-inner js-file-line\"> integer64=&quot;no.loss&quot;, GDAL1_integer64_policy=FALSE)<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/2ffc569dec62a218a3a6c4f4b9ec195d\/raw\/fa4862b64d607e725de024561423fcf2e6bf0e05\/readOGR()%20syntax.r\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/2ffc569dec62a218a3a6c4f4b9ec195d#file-readogr-syntax-r\" class=\"Link--inTextBlock\">\n          readOGR() syntax.r\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<p>where dsn is the shape file we\u2019re interested at. The data obtained from readOGR is not yet ready for plotting. We will use<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist92654026\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-fortify-syntax-r\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-r  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"fortify() syntax.r content, created by mfmakahiya on 12:13PM on October 25, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"fortify() syntax.r\">\n        <tr>\n          <td id=\"file-fortify-syntax-r-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-fortify-syntax-r-LC1\" class=\"blob-code blob-code-inner js-file-line\">fortify(model, data, ...)<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/33c72cf326a4151be70a33dc8f5735b7\/raw\/ffcbb486256a01be1fbd57c2c2aee046dcaa1935\/fortify()%20syntax.r\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/33c72cf326a4151be70a33dc8f5735b7#file-fortify-syntax-r\" class=\"Link--inTextBlock\">\n          fortify() syntax.r\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<p>where &#8220;model&#8221; is the model or R object that needs to be converted to a data frame. fortify(world) converts the data we got from the .shp file into a useful data frame ready for plotting.<\/p>\n<p>I&#8217;ve decided to use all three of them, but you can just choose one on your project, whichever works easiest and best for you.<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist92654053\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-using-map_data-in-ggplot-to-plot-world-map-r\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-r  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"using map_data in ggplot to plot world map.r content, created by mfmakahiya on 12:15PM on October 25, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"using map_data in ggplot to plot world map.r\">\n        <tr>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-LC1\" class=\"blob-code blob-code-inner js-file-line\"># Using map_data()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-LC2\" class=\"blob-code blob-code-inner js-file-line\">worldmap &lt;- map_data (&quot;world&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-LC3\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-LC4\" class=\"blob-code blob-code-inner js-file-line\">mapplot1 &lt;- ggplot(worldmap) + <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-LC5\" class=\"blob-code blob-code-inner js-file-line\">  geom_map(data = worldmap, map = worldmap, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-LC6\" class=\"blob-code blob-code-inner js-file-line\">           aes(x=long, y=lat, map_id=region), col = &quot;white&quot;, fill = &quot;gray50&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-LC7\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-using-map_data-in-ggplot-to-plot-world-map-r-LC8\" class=\"blob-code blob-code-inner js-file-line\">mapplot1<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/e2024fc728befa9a089a6599f91d4cb6\/raw\/9e273ba0e35b7f475dc5f4af83999e1bd57e01c7\/using%20map_data%20in%20ggplot%20to%20plot%20world%20map.r\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/e2024fc728befa9a089a6599f91d4cb6#file-using-map_data-in-ggplot-to-plot-world-map-r\" class=\"Link--inTextBlock\">\n          using map_data in ggplot to plot world map.r\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist92654162\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-using-borders-in-ggplot-to-plot-world-map-r\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-r  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"using borders in ggplot to plot world map.r content, created by mfmakahiya on 12:21PM on October 25, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"using borders in ggplot to plot world map.r\">\n        <tr>\n          <td id=\"file-using-borders-in-ggplot-to-plot-world-map-r-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-using-borders-in-ggplot-to-plot-world-map-r-LC1\" class=\"blob-code blob-code-inner js-file-line\"># Using borders()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-borders-in-ggplot-to-plot-world-map-r-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-using-borders-in-ggplot-to-plot-world-map-r-LC2\" class=\"blob-code blob-code-inner js-file-line\">mapplot2 &lt;- ggplot(data = final_data, aes(x=longitude, y=latitude), group = country) +<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-borders-in-ggplot-to-plot-world-map-r-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-using-borders-in-ggplot-to-plot-world-map-r-LC3\" class=\"blob-code blob-code-inner js-file-line\">  borders(&quot;world&quot;, colour=&quot;gray50&quot;, fill=&quot;gray50&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-borders-in-ggplot-to-plot-world-map-r-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-using-borders-in-ggplot-to-plot-world-map-r-LC4\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-borders-in-ggplot-to-plot-world-map-r-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-using-borders-in-ggplot-to-plot-world-map-r-LC5\" class=\"blob-code blob-code-inner js-file-line\">mapplot2<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/8d84b042b28bbb1b053f68fad0921fae\/raw\/766084d2e74a974947a039bdc00b5d354b279837\/using%20borders%20in%20ggplot%20to%20plot%20world%20map.r\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/8d84b042b28bbb1b053f68fad0921fae#file-using-borders-in-ggplot-to-plot-world-map-r\" class=\"Link--inTextBlock\">\n          using borders in ggplot to plot world map.r\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist92654204\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-r  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"using shapefile in ggplot to plot world map.r content, created by mfmakahiya on 12:25PM on October 25, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"using shapefile in ggplot to plot world map.r\">\n        <tr>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-LC1\" class=\"blob-code blob-code-inner js-file-line\"># Using shapefile \/ geom_polygon<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-LC2\" class=\"blob-code blob-code-inner js-file-line\">SHAPE_FILE_PATH = &quot;.\/Data\/World_Countries\/World_Countries.shp&quot;<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-LC3\" class=\"blob-code blob-code-inner js-file-line\">world &lt;- readOGR(dsn = SHAPE_FILE_PATH)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-LC4\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-LC5\" class=\"blob-code blob-code-inner js-file-line\">world &lt;- fortify(world)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-LC6\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-LC7\" class=\"blob-code blob-code-inner js-file-line\">mapplot3 &lt;- ggplot(data = world, aes(long, lat, group=group)) +<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-LC8\" class=\"blob-code blob-code-inner js-file-line\">  geom_polygon(color = &quot;white&quot;, fill  = &quot;gray50&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-LC9\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-using-shapefile-in-ggplot-to-plot-world-map-r-LC10\" class=\"blob-code blob-code-inner js-file-line\">mapplot3<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/47c6cc0eb71a145f168842dfa12e07ef\/raw\/02742a07b8238cfecc9894c0cc17d1057ac20d9e\/using%20shapefile%20in%20ggplot%20to%20plot%20world%20map.r\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/47c6cc0eb71a145f168842dfa12e07ef#file-using-shapefile-in-ggplot-to-plot-world-map-r\" class=\"Link--inTextBlock\">\n          using shapefile in ggplot to plot world map.r\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<p style=\"text-align: left;\"><strong>Basic map plot<\/strong><\/p>\n<p>The output of these codes looks close to each other.<\/p>\n<figure id=\"attachment_229\" aria-describedby=\"caption-attachment-229\" style=\"width: 540px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-229\" src=\"https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Basic-map-plot-300x156.png\" alt=\"\" width=\"540\" height=\"280\" srcset=\"https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Basic-map-plot-300x156.png 300w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Basic-map-plot-768x398.png 768w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Basic-map-plot-1024x531.png 1024w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Basic-map-plot-648x336.png 648w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Basic-map-plot-370x192.png 370w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Basic-map-plot.png 1910w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><figcaption id=\"caption-attachment-229\" class=\"wp-caption-text\">World map<\/figcaption><\/figure>\n<p><strong>Adding the pies<\/strong><\/p>\n<p>In order to add pies to the map plot, we will add a geom_scatterpie function to our original ggplot formula as illustrated below.<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist92654232\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-adding-geom_scatterpie-r\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-r  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"adding geom_scatterpie().r content, created by mfmakahiya on 12:28PM on October 25, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"adding geom_scatterpie().r\">\n        <tr>\n          <td id=\"file-adding-geom_scatterpie-r-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-adding-geom_scatterpie-r-LC1\" class=\"blob-code blob-code-inner js-file-line\"># Using map_data()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-geom_scatterpie-r-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-adding-geom_scatterpie-r-LC2\" class=\"blob-code blob-code-inner js-file-line\">worldmap &lt;- map_data (&quot;world&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-geom_scatterpie-r-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-adding-geom_scatterpie-r-LC3\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-geom_scatterpie-r-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-adding-geom_scatterpie-r-LC4\" class=\"blob-code blob-code-inner js-file-line\">mapplot1 &lt;- ggplot(worldmap) + <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-geom_scatterpie-r-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-adding-geom_scatterpie-r-LC5\" class=\"blob-code blob-code-inner js-file-line\">  geom_map(data = worldmap, map = worldmap, aes(x=long, y=lat, map_id=region), col = &quot;white&quot;, fill = &quot;gray50&quot;) +<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-geom_scatterpie-r-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-adding-geom_scatterpie-r-LC6\" class=\"blob-code blob-code-inner js-file-line\">  geom_scatterpie(aes(x=longitude, y=latitude, group = country, r = multiplier*6), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-geom_scatterpie-r-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-adding-geom_scatterpie-r-LC7\" class=\"blob-code blob-code-inner js-file-line\">                  data = final_data, cols = colnames(final_data[,c(2:11)]))<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-geom_scatterpie-r-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-adding-geom_scatterpie-r-LC8\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-geom_scatterpie-r-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-adding-geom_scatterpie-r-LC9\" class=\"blob-code blob-code-inner js-file-line\">mapplot1<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/90810ceb16580d4bfc5781b18d1daa87\/raw\/1c03fb2d54692bdbc888cc3b9fe4bddcf6f22e1e\/adding%20geom_scatterpie().r\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/90810ceb16580d4bfc5781b18d1daa87#file-adding-geom_scatterpie-r\" class=\"Link--inTextBlock\">\n          adding geom_scatterpie().r\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<figure id=\"attachment_231\" aria-describedby=\"caption-attachment-231\" style=\"width: 540px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-231\" src=\"https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Map-plot-with-pies-300x155.png\" alt=\"\" width=\"540\" height=\"280\" srcset=\"https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Map-plot-with-pies-300x155.png 300w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Map-plot-with-pies-768x398.png 768w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Map-plot-with-pies-1024x531.png 1024w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Map-plot-with-pies-648x336.png 648w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Map-plot-with-pies-370x192.png 370w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Map-plot-with-pies.png 1912w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><figcaption id=\"caption-attachment-231\" class=\"wp-caption-text\">World map with the distribution of death causes per country<\/figcaption><\/figure>\n<p><strong>Adding label, chart title, axis title, etc<\/strong><\/p>\n<p>To improve the appearance of our visualization, we will add a few more accessories to our chart by adding some new functions to our ggplot formula.<\/p>\n<p style=\"text-align: center;\"><style>.gist table { margin-bottom: 0; }<\/style><div style=\"tab-size: 8\" id=\"gist92654283\" class=\"gist\">\n    <div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n      <div class=\"gist-data\">\n        \n<div class=\"js-gist-file-update-container js-task-list-container\">\n      <div id=\"file-adding-more-map-plot-functions-r\" class=\"file my-2\">\n    \n    <div itemprop=\"text\"\n      class=\"Box-body p-0 blob-wrapper data type-r  \"\n      style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n      aria-label=\"adding more map plot functions.r content, created by mfmakahiya on 12:31PM on October 25, 2018.\"\n    >\n\n        \n<div class=\"js-check-hidden-unicode js-blob-code-container blob-code-content\">\n\n  <template class=\"js-file-alert-template\">\n  <div data-view-component=\"true\" class=\"flash flash-warn flash-full d-flex flex-items-center\">\n  <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n    <span>\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      <a class=\"Link--inTextBlock\" href=\"https:\/\/github.co\/hiddenchars\" target=\"_blank\">Learn more about bidirectional Unicode characters<\/a>\n    <\/span>\n\n\n  <div data-view-component=\"true\" class=\"flash-action\">        <a href=\"{{ revealButtonHref }}\" data-view-component=\"true\" class=\"btn-sm btn\">    Show hidden characters\n<\/a>\n<\/div>\n<\/div><\/template>\n<template class=\"js-line-alert-template\">\n  <span aria-label=\"This line has hidden Unicode characters\" data-view-component=\"true\" class=\"line-alert tooltipped tooltipped-e\">\n    <svg aria-hidden=\"true\" data-component=\"Octicon\" height=\"16\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" data-view-component=\"true\" class=\"octicon octicon-alert\">\n    <path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"><\/path>\n<\/svg>\n<\/span><\/template>\n\n  <table data-hpc class=\"highlight tab-size js-file-line-container\" data-tab-size=\"4\" data-paste-markdown-skip data-tagsearch-path=\"adding more map plot functions.r\">\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L1\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"1\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC1\" class=\"blob-code blob-code-inner js-file-line\"># Using map_data()<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L2\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"2\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC2\" class=\"blob-code blob-code-inner js-file-line\">worldmap &lt;- map_data (&quot;world&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L3\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"3\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC3\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L4\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"4\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC4\" class=\"blob-code blob-code-inner js-file-line\">mapplot1 &lt;- ggplot(worldmap) + <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L5\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"5\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC5\" class=\"blob-code blob-code-inner js-file-line\">  geom_map(data = worldmap, map = worldmap, aes(x=long, y=lat, map_id=region), col = &quot;white&quot;, fill = &quot;gray50&quot;) +<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L6\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"6\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC6\" class=\"blob-code blob-code-inner js-file-line\">  geom_scatterpie(aes(x=longitude, y=latitude, group = country, r = multiplier*6), <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L7\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"7\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC7\" class=\"blob-code blob-code-inner js-file-line\">                  data = final_data, cols = colnames(final_data[,c(2:11)])) +<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L8\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"8\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC8\" class=\"blob-code blob-code-inner js-file-line\">  xlim(-20,60) + ylim(10, 75) +<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L9\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"9\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC9\" class=\"blob-code blob-code-inner js-file-line\">  scale_fill_brewer(palette = &quot;Paired&quot;) +<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L10\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"10\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC10\" class=\"blob-code blob-code-inner js-file-line\">  geom_text(aes(x=longitude, y=latitude, group = country, label = country), data = final_data, stat = &quot;identity&quot;,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L11\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"11\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC11\" class=\"blob-code blob-code-inner js-file-line\">            position = position_dodge(width = 0.75), hjust = 1.5, #vjust = -1.5, size = 5, angle = 45,<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L12\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"12\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC12\" class=\"blob-code blob-code-inner js-file-line\">            check_overlap = TRUE, na.rm = FALSE, show.legend = NA, <\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L13\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"13\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC13\" class=\"blob-code blob-code-inner js-file-line\">            inherit.aes = TRUE) +<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L14\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"14\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC14\" class=\"blob-code blob-code-inner js-file-line\">  labs(title = &quot;Causes of death by country&quot;, x = &quot;Longitude&quot;, y = &quot;Latitude&quot;) +<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L15\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"15\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC15\" class=\"blob-code blob-code-inner js-file-line\">  theme(legend.position = &quot;top&quot;)<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L16\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"16\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC16\" class=\"blob-code blob-code-inner js-file-line\">\n<\/td>\n        <\/tr>\n        <tr>\n          <td id=\"file-adding-more-map-plot-functions-r-L17\" class=\"blob-num js-line-number js-blob-rnum\" data-line-number=\"17\"><\/td>\n          <td id=\"file-adding-more-map-plot-functions-r-LC17\" class=\"blob-code blob-code-inner js-file-line\">mapplot1<\/td>\n        <\/tr>\n  <\/table>\n<\/div>\n\n\n    <\/div>\n\n  <\/div>\n\n<\/div>\n\n      <\/div>\n      <div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/fa86f2f0072d6192f52ebac24cc89231\/raw\/7c7aa0fc10fa52e6b04cd1617ea6407411284083\/adding%20more%20map%20plot%20functions.r\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a>\n        <a href=\"https:\/\/gist.github.com\/mfmakahiya\/fa86f2f0072d6192f52ebac24cc89231#file-adding-more-map-plot-functions-r\" class=\"Link--inTextBlock\">\n          adding more map plot functions.r\n        <\/a>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n    <\/div>\n<\/div>\n<\/p>\n<figure id=\"attachment_233\" aria-describedby=\"caption-attachment-233\" style=\"width: 540px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-233\" src=\"https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Final-map-plot-300x160.png\" alt=\"\" width=\"540\" height=\"287\" srcset=\"https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Final-map-plot-300x160.png 300w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Final-map-plot-768x409.png 768w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Final-map-plot-1024x545.png 1024w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Final-map-plot-648x345.png 648w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Final-map-plot-361x192.png 361w, https:\/\/spectdata.com\/wp-content\/uploads\/2018\/10\/Final-map-plot.png 1891w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><figcaption id=\"caption-attachment-233\" class=\"wp-caption-text\">World map with distribution of causes of death per country from various areas<\/figcaption><\/figure>\n<p>There you go! We have plotted the distribution of death causes per country in the world map. We can see that almost all of them have the same distribution except Belarus and Georgia which is higher in diseases of the circulatory system relative to the rest of the countries.<\/p>\n<p>The method I&#8217;ve shown you above is just one way to do it. Other methods for map plot you could try are <a href=\"https:\/\/www.rdocumentation.org\/packages\/ggmap\/versions\/2.6.1\/topics\/ggmap\">ggmap<\/a>, <a href=\"https:\/\/www.rdocumentation.org\/packages\/latticeExtra\/versions\/0.6-28\/topics\/mapplot\">mapplot<\/a>,\u00a0 <a href=\"https:\/\/www.rdocumentation.org\/packages\/tmap\/versions\/2.1-1\/topics\/qtm\">qtm<\/a> from tmap package, <a href=\"https:\/\/www.rdocumentation.org\/packages\/leaflet\/versions\/2.0.2\/topics\/leaflet\">leaflet<\/a>, etc. I highly encourage you to also give it a try.<\/p>\n<p>A copy of all the files used on this simulation is available at this\u00a0<a href=\"https:\/\/github.com\/mfmakahiya\/Map-plot\">repository<\/a>.<\/p>\n<p>&#8212;&#8212;&#8211;<\/p>\n<p>Marriane Makahiya, the author, is a data scientist of SpectData. SpectData is a data analytics company founded to help companies make better use of their data.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we would go through the steps to plot pie charts on a world map, just like the one below. This image probably scared you as much as it did to me when I realized I need to create something the same as this. &#8220;How am I supposed to do this thing when &hellip; <a href=\"https:\/\/spectdata.com\/index.php\/2018\/10\/25\/how-to-use-ggplot-to-plot-pie-charts-on-a-map\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using ggplot to plot pie charts on a geographical map<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[5],"tags":[],"class_list":["post-199","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9PSm6-3d","jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/posts\/199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/comments?post=199"}],"version-history":[{"count":32,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/posts\/199\/revisions"}],"predecessor-version":[{"id":637,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/posts\/199\/revisions\/637"}],"wp:attachment":[{"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/media?parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/categories?post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spectdata.com\/index.php\/wp-json\/wp\/v2\/tags?post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}