title: Chloropleth map with geojson and ggplot2
body: <p>I am trying to map <code>Human Poverty Index</code> for <a href="https://github.com/opennepal/odp-poverty/blob/master/Human%20Poverty%20Index%20Value%20by%20Districts%20(2011)/data.csv" rel="nofollow noreferrer">various districts of Nepal</a> with choropleth map in <code>R</code> using <code>geojson</code> and <code>ggplot2</code>.</p>
  
  <p>I read <code>geojson</code> data for Nepal with districts <a href="https://github.com/mesaugat/geoJSON-Nepal/blob/master/nepal-districts.geojson" rel="nofollow noreferrer">from here</a>.</p>
  
  <p>I saw some examples <a href="https://medium.com/@anjesh/step-by-step-choropleth-map-in-r-a-case-of-mapping-nepal-7f62a84078d9" rel="nofollow noreferrer">here</a>, <a href="http://prabhasp.github.io/NepalMaps/Poverty/" rel="nofollow noreferrer">here</a>. </p>
  
  <p>This is what I did:</p>
  
  
  
  <pre class="lang-r prettyprint-override"><code># Read geojson data for nepal with districts
  library(tidyverse)
  library(geojsonio)
  #&gt; 
  #&gt; Attaching package: 'geojsonio'
  #&gt; The following object is masked from 'package:base':
  #&gt; 
  #&gt;     pretty
  spdf &lt;- geojson_read("nepal-districts.geojson",  what = "sp")
  ##https://github.com/mesaugat/geoJSON-Nepal/blob/master/nepal-districts.geojson
  
  
  
  
  #tidy data for ggplot2
  library(broom)
  spdf_fortified &lt;- tidy(spdf)
  #&gt; Regions defined for each Polygons
  
  # plot
  ggplot() +
      geom_polygon(data = spdf_fortified, aes( x = long, y = lat, group = group)) +
      theme_void() +
      coord_map()
  </code></pre>
  
  <p><img src="https://i.imgur.com/8rk9SBm.png" alt=""></p>
  
  <pre class="lang-r prettyprint-override"><code>names(spdf_fortified)
  #&gt; [1] "long"  "lat"   "order" "hole"  "piece" "group" "id"
  
  
  
  #Now read the data to map to districts
  data=read.csv("data.csv")
  #data from here
  #https://github.com/opennepal/odp-poverty/blob/master/Human%20Poverty%20Index%20Value%20by%20Districts%20(2011)/data.csv
  
  #filter and select data to reflect Value of HPI in various districts
  data &lt;- data %&gt;% filter(Sub.Group=="HPI") %&gt;% select(District,Value)
  
  
  head(data)
  #&gt;       District Value
  #&gt; 1       Achham 46.68
  #&gt; 2 Arghakhanchi 27.37
  #&gt; 3        Banke 32.10
  #&gt; 4      Baglung 27.33
  #&gt; 5      Baitadi 39.58
  #&gt; 6      Bajhang 45.32
  
  # Value represents HPI value for each district.
  
  #Now how to merge and fill Value for various districts
  #
  #
  #
  #
  </code></pre>
  
  <p>Created on 2018-06-14 by the <a href="http://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.2.0).</p>
  
  <p>If I can merge <code>spdf_fortified</code> and <code>data</code> into <code>merged_df</code>, I think I can get the chloropleth map with this code:</p>
  
  <pre class="lang-r prettyprint-override"><code>ggplot(data = merged_df, aes(x = long, y = lat, group = group)) + geom_polygon(aes(fill = Value), color = 'gray', size = 0.1)
  </code></pre>
  
  <p>Any help in merging two data ?</p>