{"id":422,"date":"2014-01-06T21:35:12","date_gmt":"2014-01-07T02:35:12","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=422"},"modified":"2014-01-06T21:35:12","modified_gmt":"2014-01-07T02:35:12","slug":"how-to-create-an-attractive-choropleth-map-in-r","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2014\/01\/06\/how-to-create-an-attractive-choropleth-map-in-r\/","title":{"rendered":"How to create an attractive choropleth map in R?"},"content":{"rendered":"<div id=\"question\" data-questionid=\"43534\">\n<table>\n<tbody>\n<tr>\n<td>\n<div>\n<div itemprop=\"description\">\n<p>I&#8217;ve been experimenting with choropleth mapping techniques in R, having reaped the benefits of ggplot2 for creating beautiful graphs within a powerful data analysis package.<\/p>\n<p>When it comes to mapping I&#8217;ve failed to produce results comparable to those I routinely get from QGIS. Using data of flow in Sheffield (fully replicable data and .qgs file\u00a0<a href=\"http:\/\/dl.dropbox.com\/u\/15008199\/Rflows-simple.zip\" rel=\"nofollow\">here<\/a>), QGIS easily produced the following:<\/p>\n<p><img decoding=\"async\" alt=\"QGIS image\" src=\"http:\/\/i.stack.imgur.com\/vgAMx.png\" \/><\/p>\n<p>The best I could produce using R (using code described\u00a0<a href=\"http:\/\/rpubs.com\/RobinLovelace\/3126\" rel=\"nofollow\">here<\/a>) were these two maps, the first using GISTools, the second using ggplot2:<\/p>\n<p><img decoding=\"async\" alt=\"GISTools choropleth\" src=\"http:\/\/i.stack.imgur.com\/bH3L2.png\" \/><img decoding=\"async\" alt=\"ggplot2 choro\" src=\"http:\/\/i.stack.imgur.com\/jUey4.png\" \/><\/p>\n<p>To me, the ggplot2 option seems far more attractive, if only I could solve the problem of the faulty lines (probably a problem with the fortify() command, or not reading in shapefiles using readOGR() described<a href=\"https:\/\/github.com\/hadley\/ggplot2\/wiki\/plotting-polygon-shapefiles\" rel=\"nofollow\">here<\/a>.)<\/p>\n<p>So the question is 2-fold: is the ggplot2 option the best choropleth mapping solution in R and, if so, how can I solve the problem of the faulty white lines?<\/p>\n<p>Replicable code to find out what I&#8217;ve done is\u00a0<a href=\"http:\/\/dl.dropbox.com\/u\/15008199\/Rflows-simple.zip\" rel=\"nofollow\">here<\/a>.<\/p>\n<p><strong>Edit &#8211; Since made choropleth() output option more attractive:<\/strong><\/p>\n<p><img decoding=\"async\" alt=\"New Rplot\" src=\"http:\/\/i.stack.imgur.com\/EfthI.png\" \/><\/p>\n<p>The ugliness of this option can be reduced by exporting at higher resolution and removing the legend (<a href=\"http:\/\/gis.stackexchange.com\/questions\/3310\/what-is-the-most-useful-spatial-r-trick\">other R legends<\/a>\u00a0are available). Still not managed to change line thickness but it&#8217;s getting better! Red lines represent flows to zones which employ &gt; 5000 people.<\/p>\n<\/div>\n<div><a title=\"show questions tagged 'r'\" href=\"http:\/\/gis.stackexchange.com\/questions\/tagged\/r\" rel=\"tag\">r<\/a>\u00a0<a title=\"show questions tagged 'thematic-map'\" href=\"http:\/\/gis.stackexchange.com\/questions\/tagged\/thematic-map\" rel=\"tag\">thematic-map<\/a><\/div>\n<table>\n<tbody>\n<tr>\n<td>\n<div><a id=\"link-post-43534\" title=\"short permalink to this question\" href=\"http:\/\/gis.stackexchange.com\/q\/43534\">share<\/a><a title=\"\" href=\"http:\/\/gis.stackexchange.com\/posts\/43534\/edit\">improve this question<\/a><\/div>\n<\/td>\n<td align=\"right\">\n<div>\n<div><a title=\"show all edits to this post\" href=\"http:\/\/gis.stackexchange.com\/posts\/43534\/revisions\">edited\u00a0Dec 9 &#8217;12 at 17:56<\/a><\/div>\n<div>\n<div><img decoding=\"async\" alt=\"\" src=\"http:\/\/i.stack.imgur.com\/RGurs.png?s=32&amp;g=1\" \/><\/div>\n<\/div>\n<div><a href=\"http:\/\/gis.stackexchange.com\/users\/292\/r-k\">R.K.<\/a><br \/>\n11.1k22066<\/div>\n<\/div>\n<\/td>\n<td>\n<div>\n<div>asked\u00a0Dec 8 &#8217;12 at 15:14<\/div>\n<div>\n<div><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"https:\/\/www.gravatar.com\/avatar\/67b1027cca3877a76a9024425519ddde?s=32&amp;d=identicon&amp;r=PG\" width=\"32\" height=\"32\" \/><\/div>\n<\/div>\n<div><a href=\"http:\/\/gis.stackexchange.com\/users\/12567\/robinlovelace\">RobinLovelace<\/a><br \/>\n842118<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>\n<div id=\"comments-43534\" data-localized=\"true\"><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div id=\"answers\">\n<div id=\"answers-header\">\n<div>\n<div>\n<div id=\"tabs\"><a title=\"Answers with the latest activity first\" href=\"http:\/\/gis.stackexchange.com\/questions\/43534\/how-to-create-an-attractive-choropleth-map-in-r?answertab=active#tab-top\">active<\/a><a title=\"Answers in the order they were provided\" href=\"http:\/\/gis.stackexchange.com\/questions\/43534\/how-to-create-an-attractive-choropleth-map-in-r?answertab=oldest#tab-top\">oldest<\/a><a title=\"Answers with the highest score first\" href=\"http:\/\/gis.stackexchange.com\/questions\/43534\/how-to-create-an-attractive-choropleth-map-in-r?answertab=votes#tab-top\">votes<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><a name=\"43563\"><\/a><\/p>\n<div id=\"answer-43563\" data-answerid=\"43563\">\n<table>\n<tbody>\n<tr>\n<td>\n<div><a title=\"This answer is useful\">up vote<\/a>3<a title=\"This answer is not useful\">down vote<\/a><\/div>\n<\/td>\n<td>\n<div>\n<p>There are some great resources on exactly this very interesting subject, including:<\/p>\n<p>From Revolutions:<\/p>\n<p><a href=\"http:\/\/blog.revolutionanalytics.com\/2009\/11\/choropleth-map-r-challenge.html\" rel=\"nofollow\">Choropleth Map R Challenge<\/a><\/p>\n<p><a href=\"http:\/\/blog.revolutionanalytics.com\/2009\/11\/choropleth-challenge-result.html\" rel=\"nofollow\">Choropleth Challenge Results<\/a><\/p>\n<p>From Stack Overflow.se:<\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/1260965\/developing-geographic-thematic-maps-with-r\">Developing Geographic Thematic Maps with R<\/a><\/p>\n<p>There are excellent examples of choropleth maps and their associated R code, including my favorite (i.e. attached map) using ggplot2. It should be relatively straight forward to insert your own data set into one of the script examples.<\/p>\n<p>R Code for this map available from\u00a0<a href=\"http:\/\/www.thisisthegreenroom.com\/2009\/choropleths-in-r\/\" rel=\"nofollow\">This is the Green Room<\/a><\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/i.stack.imgur.com\/Offoo.png\" \/><\/p>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been experimenting with choropleth mapping techniques in R, having reaped the benefits of ggplot2 for creating beautiful graphs within a powerful data analysis package.&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-422","post","type-post","status-publish","format-standard","hentry","category-arcgis"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=422"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/422\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}