

{"id":3399,"date":"2015-05-14T14:29:50","date_gmt":"2015-05-14T19:29:50","guid":{"rendered":"http:\/\/rud.is\/b\/?p=3399"},"modified":"2018-08-28T17:10:10","modified_gmt":"2018-08-28T22:10:10","slug":"geojson-hexagonal-statebins-in-r","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/","title":{"rendered":"GeoJSON Hexagonal &#8220;Statebins&#8221; in R"},"content":{"rendered":"<p>There&#8217;s been lots of buzz about &#8220;statebin&#8221; maps of late. A recent tweet by @andrewxhill referencing work by @dannydb pointed to a <span class=\"removed_link\" title=\"https:\/\/team.carto.com\/u\/andrew\/tables\/andrew.us_states_hexgrid\/public\/map\">nice shapefile<\/span> (<a href=\"https:\/\/gist.github.com\/hrbrmstr\/51f961198f65509ad863#file-us_states_hexgrid-geojson\">alternate link<\/a>) that ends up being a really great way to handle statebin maps (and I feel like a fool for not considering it for a more generic solution earlier).<\/p>\n<blockquote class=\"twitter-tweet\" lang=\"en\">\n<p lang=\"en\" dir=\"ltr\">Here is the GeoJSON, Shapefile download for the hexgrid states map based on <a href=\"https:\/\/mobile.twitter.com\/dannydb\">@dannydb<\/a>&#39;s <a href=\"https:\/\/t.co\/0exQcC8D5S\">https:\/\/t.co\/0exQcC8D5S<\/a> <a href=\"http:\/\/t.co\/F8pNH79MoQ\">pic.twitter.com\/F8pNH79MoQ<\/a><\/p>\n<p>&mdash; Andrew W Hill (@andrewxhill) <a href=\"https:\/\/mobile.twitter.com\/andrewxhill\/status\/598857286472335360\">May 14, 2015<\/a><\/p><\/blockquote>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<p>Here&#8217;s a way to use the GeoJSON version in R. I like GeoJSON since it&#8217;s a single file vs a directory of files and is readable vs binary. If you&#8217;re in a TL;DR hurry, you can just review the code <a href=\"https:\/\/gist.github.com\/hrbrmstr\/4efedf3b24f7da4e24d1\">in this gist<\/a>. Read on for expository.<\/p>\n<h4>Taking a look around<\/h4>\n<p>When you download the GeoJSON, it should be in a file called <code>us_states_hexgrid.geojson<\/code>. We can see what&#8217;s in there with R pretty easily:<\/p>\n<pre><code class=\"language-r\">library(rgdal)\n\nogrInfo(\"us_states_hexgrid.geojson\", \"OGRGeoJSON\")\n\n## Source: \"us_states_hexgrid.geojson\", layer: \"OGRGeoJSON\"\n## Driver: GeoJSON number of rows 51 \n## Feature type: wkbPolygon with 2 dimensions\n## Extent: (-137.9747 26.39343) - (-69.90286 55.3132)\n## CRS: +proj=longlat +datum=WGS84 +no_defs  \n## Number of fields: 6 \n##         name type length typeName\n## 1 cartodb_id    0      0  Integer\n## 2 created_at    4      0   String\n## 3 updated_at    4      0   String\n## 4      label    4      0   String\n## 5       bees    2      0     Real\n## 6  iso3166_2    4      0   String<\/code><\/pre>\n<p>Along with the basic shapefile goodness, we have some data, too! We&#8217;ll use all this to make a chorpleth hexbin of &#8220;bees&#8221; (I have no idea what this is but assume it has something to do with bee population, which is a serious problem on the planet right now). Let&#8217;s dig in.<\/p>\n<h4>Plotting the bins<\/h4>\n<p>First we need to read in the data, which is pretty simple:<\/p>\n<pre><code class=\"language-r\">\nus <- readOGR(\"us_states_hexgrid.geojson\", \"OGRGeoJSON\")<\/code><\/pre>\n<p>That ends up being a fairly complex object with polygons and data. However, we can take a quick look at it with base R graphics:<\/p>\n<pre><code class=\"language-r\">\nplot(us)<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3400\" data-permalink=\"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/base1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/base1.png?fit=820%2C473&amp;ssl=1\" data-orig-size=\"820,473\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"base1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/base1.png?fit=510%2C294&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/base1.png?resize=510%2C294&#038;ssl=1\" alt=\"base1\" width=\"510\" height=\"294\" class=\"aligncenter size-full wp-image-3400\" \/><\/p>\n<p>Yay! While we <em>could<\/em> do most (if not all) the remainder of the graphics in base R, I personally believe ggplot is more intuitive and expressive, so let's do the same thing with ggplot. First, we'll have to get the data structure into something ggplot can handle:<\/p>\n<pre><code class=\"language-r\">library(ggplot2)\n\nus_map <- fortify(us, region=\"iso3166_2\")<\/code><\/pre>\n<p>That gives us a data frame with the 2-letter state abbreviations as the \"region\" keys. Now we can do a basic ggplot:<\/p>\n<pre><code class=\"language-r\">ggplot(data=us_map, aes(map_id=id, x=long, y=lat)) + \n  geom_map(map=us_map, color=\"black\", fill=\"white\")<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3403\" data-permalink=\"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/rplot-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot.png?fit=739%2C386&amp;ssl=1\" data-orig-size=\"739,386\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Rplot\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot.png?fit=510%2C266&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot.png?resize=510%2C266&#038;ssl=1\" alt=\"Rplot\" width=\"510\" height=\"266\" class=\"aligncenter size-full wp-image-3403\" \/><\/p>\n<p>Ugh. Talk about ugly. But, at least it works! Now all we need to do is turn it into a choropleth, remove some map chart junk and make it look prettier!<\/p>\n<h4>Upping the aesthetics<\/h4>\n<p>There's a pretty good idiom for making maps in R. There's a handy layer\/<code>geom<\/code> called <code>geom_map<\/code> which takes care of a ton of details under the hood. We can use it for making outlines and fills and add as many layers of them as we want\/need. For our needs, we'll:<\/p>\n<ul>\n<li>put down a base layer of polygons<\/li>\n<li>add a fill layer for our data<\/li>\n<li>get rid of map chart junk<\/li>\n<\/ul>\n<p>This is all pretty straightforward once you get the hang of it:<\/p>\n<pre><code class=\"language-r\">g <- ggplot()\n\n# Plot base map -----------------------------------------------------------\n\ngg <- gg + geom_map(data=us_map, map=us_map,\n                    aes(x=long, y=lat, map_id=id),\n                    color=\"white\", size=0.5)\n\n# Plot filled polygons ----------------------------------------------------\n\ngg <- gg + geom_map(data=us@data, map=us_map,\n                    aes(fill=bees, map_id=iso3166_2))\n\n# Remove chart junk for the \u201cmap\" -----------------------------------------\n\ngg <- gg + labs(x=NULL, y=NULL)\ngg <- gg + theme_bw()\ngg <- gg + theme(panel.border=element_blank())\ngg <- gg + theme(panel.grid=element_blank())\ngg <- gg + theme(axis.ticks=element_blank())\ngg <- gg + theme(axis.text=element_blank())\ngg<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3405\" data-permalink=\"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/rplot01-3\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot011.png?fit=715%2C392&amp;ssl=1\" data-orig-size=\"715,392\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Rplot01\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot011.png?fit=510%2C280&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot011.png?resize=510%2C280&#038;ssl=1\" alt=\"Rplot01\" width=\"510\" height=\"280\" class=\"aligncenter size-full wp-image-3405\" \/><\/p>\n<p>Definitely better, but it still needs work. Outlines would be good and it definitely needs a better color palette. It would also be nice if the polygons weren't \"warped\". We can fix these issues by adding in a few other elements:<\/p>\n<pre><code class=\"language-r\">gg <- ggplot()\ngg <- gg + geom_map(data=us_map, map=us_map,\n                    aes(x=long, y=lat, map_id=id),\n                    color=\"white\", size=0.5)\ngg <- gg + geom_map(data=us@data, map=us_map,\n                    aes(fill=bees, map_id=iso3166_2))\n\n# Overlay borders without ugly line on legend -----------------------------\n\ngg <- gg + geom_map(data=us@data, map=us_map,\n                    aes(map_id=iso3166_2),\n                    fill=\"#ffffff\", alpha=0, color=\"white\",\n                    show_guide=FALSE)\n\n# ColorBrewer scale; using distiller for discrete vs continuous -----------\n\ngg <- gg + scale_fill_distiller(palette=\"RdPu\", na.value=\"#7f7f7f\")\n\n# coord_map mercator works best for the display ---------------------------\n\ngg <- gg + coord_map()\n\ngg <- gg + labs(x=NULL, y=NULL)\ngg <- gg + theme_bw()\ngg <- gg + theme(panel.border=element_blank())\ngg <- gg + theme(panel.grid=element_blank())\ngg <- gg + theme(axis.ticks=element_blank())\ngg <- gg + theme(axis.text=element_blank())\ngg<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3406\" data-permalink=\"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/rplot02\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot02.png?fit=750%2C428&amp;ssl=1\" data-orig-size=\"750,428\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Rplot02\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot02.png?fit=510%2C291&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot02.png?resize=510%2C291&#038;ssl=1\" alt=\"Rplot02\" width=\"510\" height=\"291\" class=\"aligncenter size-full wp-image-3406\" \/><\/p>\n<p>Much better. We use a \"hack\" to keep the legend free of white slash marks for the polygon outlines (see <span class=\"removed_link\" title=\"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/#comment-9464\">the comments<\/span> for a less-hackish way) and <code>coord_map<\/code> to let the projection handle the \"unwarping\". By using the <code>distiller<\/code> fill, we get discrete color bins vs continuous shades (use what you feel is most appropriate, though, for your own work).<\/p>\n<h4>Where are we?<\/h4>\n<p>Most statebin\/hexbin maps still (probably) need state labels since (a) Americans are notoriously bad at geography and (b) even if they were good at geography, we've removed much of the base references for folks to work from accurately.<\/p>\n<p>The data exists in the shapefile, but to get the labels put in the centers of each polygon we have to do a bit of work:<\/p>\n<pre><code class=\"language-r\">library(rgeos)\n\ncenters <- cbind.data.frame(data.frame(gCentroid(us, byid=TRUE), id=us@data$iso3166_2))<\/code><\/pre>\n<p>That gets us a data frame of the <code>x<\/code> &amp; <code>y<\/code> centers of each polygon along with the (abbreviated) state name. We can now add a layer with <code>geom_text<\/code> to place the label. The following is the complete solution:<\/p>\n<pre><code class=\"language-r\">library(rgdal)\nlibrary(rgeos)\nlibrary(ggplot2)\n\nus <- readOGR(\"us_states_hexgrid.geojson\", \"OGRGeoJSON\")\n\ncenters <- cbind.data.frame(data.frame(gCentroid(us, byid=TRUE), id=us@data$iso3166_2))\n\nus_map <- fortify(us, region=\"iso3166_2\")\n\nggplot(data=us_map, aes(map_id=id, x=long, y=lat)) + geom_map(map=us_map, color=\"black\", fill=\"white\")\n\ngg <- ggplot()\ngg <- gg + geom_map(data=us_map, map=us_map,\n                    aes(x=long, y=lat, map_id=id),\n                    color=\"white\", size=0.5)\ngg <- gg + geom_map(data=us@data, map=us_map,\n                    aes(fill=bees, map_id=iso3166_2))\ngg <- gg + geom_map(data=us@data, map=us_map,\n                    aes(map_id=iso3166_2),\n                    fill=\"#ffffff\", alpha=0, color=\"white\",\n                    show_guide=FALSE)\ngg <- gg + geom_text(data=centers, aes(label=id, x=x, y=y), color=\"white\", size=4)\ngg <- gg + scale_fill_distiller(palette=\"RdPu\", na.value=\"#7f7f7f\")\ngg <- gg + coord_map()\ngg <- gg + labs(x=NULL, y=NULL)\ngg <- gg + theme_bw()\ngg <- gg + theme(panel.border=element_blank())\ngg <- gg + theme(panel.grid=element_blank())\ngg <- gg + theme(axis.ticks=element_blank())\ngg <- gg + theme(axis.text=element_blank())\ngg<\/code><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3407\" data-permalink=\"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/rplot03\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot03.png?fit=922%2C535&amp;ssl=1\" data-orig-size=\"922,535\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Rplot03\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot03.png?fit=510%2C296&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/Rplot03.png?resize=510%2C296&#038;ssl=1\" alt=\"Rplot03\" width=\"510\" height=\"296\" class=\"aligncenter size-full wp-image-3407\" \/><\/p>\n<h4>Wrapping up<\/h4>\n<p>This is a pretty neat way to work with \"statebins\" and I'll probably take some time over the summer to update my <a href=\"https:\/\/cran.r-project.org\/web\/packages\/statebins\/index.html\">statebins<\/a> package to use shapefiles and allow for more generic shapes. Ramnath Vaidyanathan has also done some work with statebins and javascript, so I'll see what I can do to merge all the functionality into one package.<\/p>\n<p>If you've got an alternate way to work with these or have some interesting \"bins\" to show, drop a note in the comments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&#8217;s been lots of buzz about &#8220;statebin&#8221; maps of late. A recent tweet by @andrewxhill referencing work by @dannydb pointed to a nice shapefile (alternate link) that ends up being a really great way to handle statebin maps (and I feel like a fool for not considering it for a more generic solution earlier). Here [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[721,678,673,674,720,91],"tags":[810],"class_list":["post-3399","post","type-post","status-publish","format-standard","hentry","category-cartography","category-data-visualization","category-datavis-2","category-dataviz","category-gis","category-r","tag-post"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>GeoJSON Hexagonal &quot;Statebins&quot; in R - rud.is<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"GeoJSON Hexagonal &quot;Statebins&quot; in R - rud.is\" \/>\n<meta property=\"og:description\" content=\"There&#8217;s been lots of buzz about &#8220;statebin&#8221; maps of late. A recent tweet by @andrewxhill referencing work by @dannydb pointed to a nice shapefile (alternate link) that ends up being a really great way to handle statebin maps (and I feel like a fool for not considering it for a more generic solution earlier). Here [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2015-05-14T19:29:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-08-28T22:10:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/rud.is\/b\/wp-content\/uploads\/2015\/05\/base1.png\" \/>\n<meta name=\"author\" content=\"hrbrmstr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"hrbrmstr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"GeoJSON Hexagonal &#8220;Statebins&#8221; in R\",\"datePublished\":\"2015-05-14T19:29:50+00:00\",\"dateModified\":\"2018-08-28T22:10:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/\"},\"wordCount\":747,\"commentCount\":10,\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/base1.png\",\"keywords\":[\"post\"],\"articleSection\":[\"cartography\",\"Data Visualization\",\"DataVis\",\"DataViz\",\"gis\",\"R\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/\",\"name\":\"GeoJSON Hexagonal \\\"Statebins\\\" in R - rud.is\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/base1.png\",\"datePublished\":\"2015-05-14T19:29:50+00:00\",\"dateModified\":\"2018-08-28T22:10:10+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/base1.png?fit=820%2C473&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/base1.png?fit=820%2C473&ssl=1\",\"width\":820,\"height\":473},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2015\\\/05\\\/14\\\/geojson-hexagonal-statebins-in-r\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/rud.is\\\/b\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"GeoJSON Hexagonal &#8220;Statebins&#8221; in R\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/\",\"name\":\"rud.is\",\"description\":\"&quot;In God we trust. All others must bring data&quot;\",\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/rud.is\\\/b\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\",\"name\":\"hrbrmstr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"width\":460,\"height\":460,\"caption\":\"hrbrmstr\"},\"logo\":{\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\"},\"description\":\"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7\",\"sameAs\":[\"http:\\\/\\\/rud.is\"],\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/author\\\/hrbrmstr\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"GeoJSON Hexagonal \"Statebins\" in R - rud.is","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/","og_locale":"en_US","og_type":"article","og_title":"GeoJSON Hexagonal \"Statebins\" in R - rud.is","og_description":"There&#8217;s been lots of buzz about &#8220;statebin&#8221; maps of late. A recent tweet by @andrewxhill referencing work by @dannydb pointed to a nice shapefile (alternate link) that ends up being a really great way to handle statebin maps (and I feel like a fool for not considering it for a more generic solution earlier). Here [&hellip;]","og_url":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/","og_site_name":"rud.is","article_published_time":"2015-05-14T19:29:50+00:00","article_modified_time":"2018-08-28T22:10:10+00:00","og_image":[{"url":"https:\/\/rud.is\/b\/wp-content\/uploads\/2015\/05\/base1.png","type":"","width":"","height":""}],"author":"hrbrmstr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hrbrmstr","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"GeoJSON Hexagonal &#8220;Statebins&#8221; in R","datePublished":"2015-05-14T19:29:50+00:00","dateModified":"2018-08-28T22:10:10+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/"},"wordCount":747,"commentCount":10,"publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"image":{"@id":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/rud.is\/b\/wp-content\/uploads\/2015\/05\/base1.png","keywords":["post"],"articleSection":["cartography","Data Visualization","DataVis","DataViz","gis","R"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/","url":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/","name":"GeoJSON Hexagonal \"Statebins\" in R - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/#primaryimage"},"image":{"@id":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/rud.is\/b\/wp-content\/uploads\/2015\/05\/base1.png","datePublished":"2015-05-14T19:29:50+00:00","dateModified":"2018-08-28T22:10:10+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/#primaryimage","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/base1.png?fit=820%2C473&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/05\/base1.png?fit=820%2C473&ssl=1","width":820,"height":473},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2015\/05\/14\/geojson-hexagonal-statebins-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"GeoJSON Hexagonal &#8220;Statebins&#8221; in R"}]},{"@type":"WebSite","@id":"https:\/\/rud.is\/b\/#website","url":"https:\/\/rud.is\/b\/","name":"rud.is","description":"&quot;In God we trust. All others must bring data&quot;","publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rud.is\/b\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886","name":"hrbrmstr","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","width":460,"height":460,"caption":"hrbrmstr"},"logo":{"@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1"},"description":"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7","sameAs":["http:\/\/rud.is"],"url":"https:\/\/rud.is\/b\/author\/hrbrmstr\/"}]}},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p23idr-SP","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":3117,"url":"https:\/\/rud.is\/b\/2014\/11\/16\/moving-the-earth-well-alaska-hawaii-with-r\/","url_meta":{"origin":3399,"position":0},"title":"Moving The Earth (well, Alaska &#038; Hawaii) With R","author":"hrbrmstr","date":"2014-11-16","format":false,"excerpt":"In a previous post we looked at how to use D3 TopoJSON files with R and make some very D3-esque maps. I mentioned that one thing missing was moving Alaska & Hawaii a bit closer to the continental United States and this post shows you how to do that. The\u2026","rel":"","context":"In &quot;d3&quot;","block_context":{"text":"d3","link":"https:\/\/rud.is\/b\/category\/d3\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4217,"url":"https:\/\/rud.is\/b\/2016\/03\/29\/easier-composite-u-s-choropleths-with-albersusa\/","url_meta":{"origin":3399,"position":1},"title":"Easier Composite U.S. Choropleths with albersusa","author":"hrbrmstr","date":"2016-03-29","format":false,"excerpt":"Folks who've been tracking this blog on R-bloggers probably remember [this post](https:\/\/rud.is\/b\/2014\/11\/16\/moving-the-earth-well-alaska-hawaii-with-r\/) where I showed how to create a composite U.S. map with an Albers projection (which is commonly referred to as AlbersUSA these days thanks to D3). I'm not sure why I didn't think of this earlier, but you\u2026","rel":"","context":"In &quot;cartography&quot;","block_context":{"text":"cartography","link":"https:\/\/rud.is\/b\/category\/cartography\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3054,"url":"https:\/\/rud.is\/b\/2014\/09\/26\/overcoming-d3-cartographic-envy-with-r-ggplot\/","url_meta":{"origin":3399,"position":2},"title":"Overcoming D3 Cartographic Envy With R + ggplot","author":"hrbrmstr","date":"2014-09-26","format":false,"excerpt":"When I used one of the Scotland TopoJSON files for a recent post, it really hit me just how much D3 cartography envy I had\/have as an R user. Don't get me wrong, I can conjure up D3 maps pretty well [1] [2] and the utility of an interactive map\u2026","rel":"","context":"In &quot;Charts &amp; Graphs&quot;","block_context":{"text":"Charts &amp; Graphs","link":"https:\/\/rud.is\/b\/category\/charts-graphs\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":11612,"url":"https:\/\/rud.is\/b\/2018\/10\/10\/geojson-version-of-cbc-quebec-ridings-hex-cartograms-with-example-usage-in-r\/","url_meta":{"origin":3399,"position":3},"title":"GeoJSON  Version of CBC Quebec Ridings Hex Cartograms with  Example Usage in R","author":"hrbrmstr","date":"2018-10-10","format":false,"excerpt":"The CBC covered the recent (as of the original post-time on this blog entry) Quebec elections and used a well-crafted hex grid map to display results: They have a great 'splainer on why they use this type of map. Thinking that it may be useful for others, I used a\u2026","rel":"","context":"In &quot;cartography&quot;","block_context":{"text":"cartography","link":"https:\/\/rud.is\/b\/category\/cartography\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/10\/ggplot-sf.png?fit=1200%2C900&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/10\/ggplot-sf.png?fit=1200%2C900&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/10\/ggplot-sf.png?fit=1200%2C900&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/10\/ggplot-sf.png?fit=1200%2C900&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2018\/10\/ggplot-sf.png?fit=1200%2C900&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3413,"url":"https:\/\/rud.is\/b\/2015\/05\/15\/u-s-drought-monitoring-with-hexbin-state-maps-in-r\/","url_meta":{"origin":3399,"position":4},"title":"U.S. Drought Monitoring With Hexbin State Maps in R","author":"hrbrmstr","date":"2015-05-15","format":false,"excerpt":"On the news, today, of the early stages of drought hitting the U.S. northeast states I decided to springboard off of yesterday's post and show a more practical use of hexbin state maps than the built-in (and still purpose unknown to me) \"bees\" data. The U.S. Drought Monitor site supplies\u2026","rel":"","context":"In &quot;cartography&quot;","block_context":{"text":"cartography","link":"https:\/\/rud.is\/b\/category\/cartography\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3929,"url":"https:\/\/rud.is\/b\/2016\/02\/11\/plot-the-new-svg-r-logo-with-ggplot2\/","url_meta":{"origin":3399,"position":5},"title":"Plot the new SVG R logo with ggplot2","author":"hrbrmstr","date":"2016-02-11","format":false,"excerpt":"High resolution and SVG versions of the new R logo are finally available. I converted the SVG to WKT (file here) which means we can use it like we would a shapefile in R. That includes plotting! Here's a short example of how to read that WKT and plot the\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/rud.is\/b\/category\/r\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/02\/RStudio.png?fit=1198%2C942&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/02\/RStudio.png?fit=1198%2C942&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/02\/RStudio.png?fit=1198%2C942&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/02\/RStudio.png?fit=1198%2C942&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/02\/RStudio.png?fit=1198%2C942&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/3399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/comments?post=3399"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/3399\/revisions"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=3399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=3399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=3399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}