Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I am working on a review paper on microfinance in India and use data from the MIX market. Today, I was amazed by how quick I conjured a map of India with the headquarters of the microfinance institutions that report data to the MIX market depicted on that map. Ideally, I would have more geolocation data – but this is hard to come by. But what we can clearly see is the clustering of institutions in big cities and in the south, which was hit hardest by the recent crisis.
I dont think anybody has produced such a map before. In fact, I can do this for all institutions reporting data around the world, which may be interesting to see. Also, I already tried to make the size of the dot proportional to e.g. measures of real yield or color-coding the nearest neighborhood (say the neigbhouring districts) by the average loan sizes reported. Lots of things to do. Maybe thats something for the guys at MIX Market or for David Roodman who, I think has finished his open book.
The key difficulty was actually not in plotting the map (though it took some time), but in obtaining geo-data on where the headquarters of the microfinance institutions are located. I managed to obtain this data – though its not perfect – by making calls to the Google MAP API via a PHP script., basically using the following two functions:
function ResponseToArray($response) { return json_decode($response,true); } function findLocation($string) { $url = "http://maps.google.com/maps/geo?q=".$string."&output=json&sensor=true_or_false&key=your_api_key"; $raw = file_get_contents($url); $geodata = ResponseToArray($raw); $point = $geodata["Placemark"][0]["Point"]["coordinates"]; return $point; }
The first one transforms the JSON return into an array and the latter, actually does the call. The variable $string should contain the actual paramters, such as the city and the zip code of where the institution is located.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.