

{"id":3538,"date":"2015-07-24T14:50:24","date_gmt":"2015-07-24T19:50:24","guid":{"rendered":"http:\/\/rud.is\/b\/?p=3538"},"modified":"2020-04-03T11:21:36","modified_gmt":"2020-04-03T16:21:36","slug":"a-path-towards-easier-map-projection-machinations-with-ggplot2","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/","title":{"rendered":"A Path Towards Easier Map Projection Machinations with ggplot2"},"content":{"rendered":"<p>The <code>$DAYJOB<\/code> doesn&#8217;t afford much opportunity to work with cartographic datasets, but I <em>really<\/em> like maps and tinker with shapefiles and geo-data when I can, plus answer a ton of geo-questions on StackOverflow. R makes it easy\u2014one might even say <em>too easy<\/em>\u2014to work with maps. All it takes to make a map of the continental United States (CONUS) is:<\/p>\n<pre><code class=\"language-r\">library(maps)\nmap(\"state\")\n<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3548\" data-permalink=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/base_1-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png?fit=672%2C480&amp;ssl=1\" data-orig-size=\"672,480\" 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=\"base_1-1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png?fit=300%2C214&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png?fit=510%2C364&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png?resize=510%2C364&#038;ssl=1\" alt=\"base_1-1\" width=\"510\" height=\"364\" class=\"aligncenter size-full wp-image-3548\" \/><\/a><\/p>\n<p>It&#8217;s a <em>little<\/em> more involved with ggplot2:<\/p>\n<pre><code class=\"language-r\">library(ggplot2)\nlibrary(ggthemes)\n\nstates &lt;- map_data(\"state\")\n\ngg &lt;- ggplot()\ngg &lt;- gg + geom_map(data=states, map=states,\n                    aes(x=long, y=lat, map_id=region),\n                    color=\"black\", fill=\"white\", size=0.25)\ngg &lt;- gg + theme_map()\ngg\n<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_1-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3547\" data-permalink=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/ggplot_1-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_1-1.png?fit=672%2C480&amp;ssl=1\" data-orig-size=\"672,480\" 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=\"ggplot_1-1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_1-1.png?fit=300%2C214&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_1-1.png?fit=510%2C364&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_1-1.png?resize=510%2C364&#038;ssl=1\" alt=\"ggplot_1-1\" width=\"510\" height=\"364\" class=\"aligncenter size-full wp-image-3547\" \/><\/a><\/p>\n<p>Both of those maps are <em>horrible<\/em>. The <code>maps::map<\/code> function defaults to using a rectangular projection with the aspect ratio chosen so that longitude and latitude scales are equivalent at the center of the picture. ggplot will size the graphic to the device window. Sticking with these defaults is a <em>really<\/em> bad idea. Why? I&#8217;ll let Mark Monmonier (author of <a href=\"https:\/\/www.amazon.com\/How-Lie-Maps-2nd-Edition\/dp\/0226534219\">How to Lie with Maps<\/a>) explain:<\/p>\n<blockquote><p>\n  <em>Maps have three basic attributes: scale, projection, and symbolization. Each element is a source of distortion. As a group, they describe the essence of the map&#8217;s possibilities and limitations. No one can use maps or make maps safely and effectively without understanding map scales, map projections, and map symbols.<\/em><\/p>\n<p>  &hellip;<\/p>\n<p>  <em>Map projections distort five geographic relationships: areas, angles, gross shapes, distances, and directions. Although some projections preserve local angles but not areas, others preserve areas but not local angles. All distort large shapes noticeably (but some distort continental shapes more than others), and all distort at least some distances and some directions.<\/em>\n <\/p><\/blockquote>\n<p>There are great examples in his book on how map projections can inflate or diminish the area and relative importance of countries and regions, and how a map projection can itself become a rallying point for &#8220;cartographically oppressed&#8221; regions.<\/p>\n<p>If map projections are important (and they are) what should you do? Both <code>map<\/code> and ggplot give you options to use projections that are found in the <code>mapproj<\/code> library (specifically using the <code>mapproject<\/code> function). The help for <code>mapproject<\/code> even gives an example of using the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Albers_projection\">Albers equal-area conic projection<\/a> when plotting the CONUS:<\/p>\n<pre><code class=\"language-r\">library(mapproj)\nmap(\"state\", projection=\"albers\", par=c(lat0=30, lat1=40))\n<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_2-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3546\" data-permalink=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/base_2-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_2-1.png?fit=672%2C480&amp;ssl=1\" data-orig-size=\"672,480\" 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=\"base_2-1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_2-1.png?fit=300%2C214&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_2-1.png?fit=510%2C364&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_2-1.png?resize=510%2C364&#038;ssl=1\" alt=\"base_2-1\" width=\"510\" height=\"364\" class=\"aligncenter size-full wp-image-3546\" \/><\/a><\/p>\n<p>As it&#8217;s full name suggests, Albers is an equal-area projection which is recommended for U.S. choropleths as it preserves the relative areas of geographic features. It&#8217;s also better than the ggplot default (&#8220;<span class=\"removed_link\" title=\"https:\/\/en.wikipedia.org\/wiki\/Mercator_projection&quot;\">Mercator<\/span>&#8220;) in it&#8217;s <code>coord_map<\/code>:<\/p>\n<pre><code class=\"language-r\">gg + coord_map()\n<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_2-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3544\" data-permalink=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/ggplot_2-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_2-1.png?fit=672%2C480&amp;ssl=1\" data-orig-size=\"672,480\" 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=\"ggplot_2-1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_2-1.png?fit=300%2C214&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_2-1.png?fit=510%2C364&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_2-1.png?resize=510%2C364&#038;ssl=1\" alt=\"ggplot_2-1\" width=\"510\" height=\"364\" class=\"aligncenter size-full wp-image-3544\" \/><\/a><\/p>\n<p>But, we <em>can<\/em> pass in parameters to use a saner projection:<\/p>\n<pre><code class=\"language-r\">gg + coord_map(\"albers\", lat0=30, lat1=40)\n<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_3-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3545\" data-permalink=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/ggplot_3-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_3-1.png?fit=672%2C480&amp;ssl=1\" data-orig-size=\"672,480\" 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=\"ggplot_3-1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_3-1.png?fit=300%2C214&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_3-1.png?fit=510%2C364&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_3-1.png?resize=510%2C364&#038;ssl=1\" alt=\"ggplot_3-1\" width=\"510\" height=\"364\" class=\"aligncenter size-full wp-image-3545\" \/><\/a><\/p>\n<p>The <code>mapproject<\/code> function exposes 41 projections, which may <em>seem<\/em> generous; however, not all of them are practical and even the ones with parameters are not very customizable. Before we dig into that a bit more, you&#8217;re probably wondering (if you don&#8217;t work with cartography for a living or hobby) how one goes about choosing a map projection&hellip;<\/p>\n<h3>Choosing A Map Projection<\/h3>\n<p>Thankfully, many smart folks have thought quite a bit about choosing map projections and there are a number of resources you can draw upon when making your own choices.<\/p>\n<p>The first one is <span class=\"removed_link\" title=\"http:\/\/pubs.er.usgs.gov\/publication\/b1532\">Map Projections &#8211; A Working Manual<\/span>. This is a free resource from the U.S. Geological Survey and was published back in 1987. It has a &#8220;companion&#8221; resource &#8211; <a href=\"https:\/\/pubs.usgs.gov\/pp\/1453\/report.pdf\">An Album of Map Projections<\/a>. Both are outstanding resources to have on hand as they provide a great deal of information on map projections. If you&#8217;re in a hurry, the &#8220;Album&#8221; makes for a good quick reference. Here&#8217;s the entry for our buddy, Albers:<\/p>\n<p><center><br \/>\n<a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/album-albers.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3549\" data-permalink=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/album-albers\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/album-albers.png?fit=600%2C496&amp;ssl=1\" data-orig-size=\"600,496\" 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=\"album-albers\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/album-albers.png?fit=300%2C248&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/album-albers.png?fit=510%2C422&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/album-albers.png?resize=510%2C422&#038;ssl=1\" alt=\"album-albers\" width=\"510\" height=\"422\" class=\"aligncenter size-full wp-image-3549\" \/><\/a><br \/>\n<\/center><\/p>\n<p>(Go to page 10 of the &#8220;Album&#8221; for the larger version)<\/p>\n<p>The image in the upper-right is a &#8220;Tissot indicatrix&#8221; (named for it&#8217;s creator Nicolas Auguste Tissot), which <em>&#8220;puts Tissot indicatrices at every 30\u00b0 of latitude and longitude, except at the poles. This shows the shape of infinitesimally small circles on the Earth as they appear when they are plotted by using a fixed finite scale at the same locations on a map. Every circle is plotted as a circle or an ellipse or, in extreme cases, as a straight line. On an equal-area projection, all these ellipses and circles are shown as having the same area. The flattening of the ellipse shows the extent of local shape distortion and how much the scale is changed and in what direction. On conformal map projections, all indicatrices remain circles, but the areas change. On other projections, both the areas and the shapes of the indicatrices change&#8221;<\/em>. This makes for a great way to understand just how your creations are being distorted (though that may be obvious when you actually plot your maps).<\/p>\n<p>The &#8220;Working Manual&#8221; also includes the equations necessary to compute the projections. Both provide projection usage guidance as well as the technically bits describing them.<\/p>\n<p>The <a href=\"https:\/\/ec.europa.eu\/jrc\/en\/about\/jrc-in-brief\">Institute for Environment and Sustainability<\/a> has a similar guide for <a href=\"http:\/\/ec.europa.eu\/eurostat\/documents\/4311134\/4366152\/Map-projections-EUROPE.pdf\/460d90e4-b7f2-49b7-8962-5c860c76757d\">Map Projections for Europe<\/a>.<\/p>\n<p>Many countries and municipalities also have their own guides for using projections (e.g. <span class=\"removed_link\" title=\"https:\/\/www.dfg.ca.gov\/biogeodata\/gis\/pdfs\/DFG_Projection_and_Datum_Guidelines.pdf\">California<\/span>).<\/p>\n<p>If you can handle what feels like a TARDIS trip back in time to the days of GeoCities, <a href=\"http:\/\/mapref.org\/contents.htm\">MapRef<\/a> also provides good information on projections. You can also review <a href=\"http:\/\/www.progonos.com\/furuti\/MapProj\/Normal\/TOC\/cartTOC.html\">Carlos A. Furuti&#8217;s compilation<\/a> of projections for more information.<\/p>\n<h3>Using More Complex\/Nuanced Projections<\/h3>\n<p>Despite being able to use Albers and 40 other projections via <code>mapproject<\/code>, having more flexibility would allow us to use grid systems (see the refs in the previous section for what those are) and also hyper-customize many projections without the need to write our own equations (be thankful of that as you skim the math in the &#8220;Working Manual&#8221;!).<\/p>\n<p>Gerald Evenden developed a library and utility called <code>proj<\/code> for the USGS back in 1995 and said utility, library &amp; projection specification idiom has been maintained and expanded ever since in the <a href=\"https:\/\/github.com\/OSGeo\/proj.4\/wiki\">PROJ.4 project<\/a>. This library\/tool is straightforward to install on most (if not all) operating systems. PROJ.4 lets you specify projections in a (fairly complex) string format (often referred to as a <code>proj4string<\/code>, especially in R). For example, you can specify Albers for the U.S. with:<\/p>\n<pre><code class=\"language-r\">\"+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96\"\n<\/code><\/pre>\n<p><a href=\"ftp:\/\/ftp.remotesensing.org\/proj\/OF90-284.pdf\">Cartographic Projection Procedures for the UNIX Environment\u2014A User\u2019s Manual<\/a> (considered &#8220;the&#8221;manual for PROJ.4) explains how to build the specification. At the time of this blog post there are 134 named (i.e. <code>+proj=NAME<\/code>) projections availble for use &amp; customization (run <code>proj -l<\/code> at a command-line to see the full list).<\/p>\n<p>A simple example of why this is useful is when you need to plot a world map. Said activity should <em>always<\/em> be prefaced with a review of <a href=\"https:\/\/xkcd.com\/977\/\">this seminal work<\/a> to ensure you will choose a good projection\u2014say, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Winkel_tripel_projection\">Winkel tripel<\/a>. A quick glance of what <code>mapproject<\/code> supports will show you that you&#8217;re pretty much out of luck using the standard R tools we&#8217;ve seen so far for that but there is a handy <code>+proj=wintri<\/code> in PROJ.4 we can use.<\/p>\n<p>Here&#8217;s how you&#8217;d plot that projection in the base plotting system:<\/p>\n<pre><code class=\"language-r\">library(sp)\nlibrary(rworldmap) # this pkg has waaaay better world shapefiles\n\nplot(spTransform(getMap(), CRS(\"+proj=wintri\")))\n<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_3-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3543\" data-permalink=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/base_3-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_3-1.png?fit=672%2C480&amp;ssl=1\" data-orig-size=\"672,480\" 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=\"base_3-1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_3-1.png?fit=300%2C214&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_3-1.png?fit=510%2C364&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_3-1.png?resize=510%2C364&#038;ssl=1\" alt=\"base_3-1\" width=\"510\" height=\"364\" class=\"aligncenter size-full wp-image-3543\" \/><\/a><\/p>\n<p>However, we can&#8217;t pass in PROJ.4 strings to ggplot&#8217;s <code>coord_map<\/code>, so we have to project the Earth first before plotting and use <code>coord_equal<\/code>:<\/p>\n<pre><code class=\"language-r\">world &lt;- fortify(spTransform(getMap(), CRS(\"+proj=wintri\")))\n\ngg &lt;- ggplot()\ngg &lt;- gg + geom_map(data=world, map=world,\n                    aes(x=long, y=lat, map_id=id),\n                    color=\"black\", fill=\"white\", size=0.25)\ngg &lt;- gg + coord_equal()\ngg &lt;- gg + theme_map()\ngg\n<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_4-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3542\" data-permalink=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/ggplot_4-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_4-1.png?fit=672%2C480&amp;ssl=1\" data-orig-size=\"672,480\" 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=\"ggplot_4-1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_4-1.png?fit=300%2C214&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_4-1.png?fit=510%2C364&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_4-1.png?resize=510%2C364&#038;ssl=1\" alt=\"ggplot_4-1\" width=\"510\" height=\"364\" class=\"aligncenter size-full wp-image-3542\" \/><\/a><\/p>\n<p>While that works, you have to pre-project any lines, points, etc. as well before plotting them with the map. For example, here are the locations of all of the non-military rocket launch sites (yeah, I&#8217;ve done that before, but it&#8217;s a fun data set! &#8211; and I had it handy):<\/p>\n<pre><code class=\"language-r\">library(rgdal) # for readOGR\nlibrary(httr)  # for downloading\n\nlaunch_sites &lt;- paste0(\"https:\/\/collaborate.org\/sites\/collaborate.org\/\",\n                       \"files\/spacecentersnon-militaryspacelaunchsites.kml\")\ninvisible(try(GET(launch_sites, write_disk(\"\/tmp\/launch-sites.kml\")), silent=TRUE))\n\nsites &lt;- readOGR(\"\/tmp\/launch-sites.kml\", \n                 \"SpaceCenters: Non-Military Space Launch Sites\", \n                 verbose=FALSE)\nsites_wt &lt;- spTransform(sites, CRS(\"+proj=wintri\"))\nsites_wt &lt;- coordinates(sites_wt)\n\ngg &lt;- gg + geom_point(data=as.data.frame(sites_wt), \n                      aes(x=coords.x1, y=coords.x2), \n                      color=\"#b2182b\")\ngg\n<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_5-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3540\" data-permalink=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/ggplot_5-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_5-1.png?fit=672%2C480&amp;ssl=1\" data-orig-size=\"672,480\" 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=\"ggplot_5-1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_5-1.png?fit=300%2C214&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_5-1.png?fit=510%2C364&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_5-1.png?resize=510%2C364&#038;ssl=1\" alt=\"ggplot_5-1\" width=\"510\" height=\"364\" class=\"aligncenter size-full wp-image-3540\" \/><\/a><\/p>\n<p>If you have more layers, that&#8217;s doable, but painful. If we could make it so ggplot allow for PROJ.4 projections in some <code>coord_<\/code> this would help keep our plot idioms (and code) cleaner. Thus, <code>coord_proj<\/code> was born.<\/p>\n<p><code>coord_proj<\/code> mimics the functionality of <code>coord_map<\/code> but uses <code>proj4::project<\/code> instead of <code>mapproject<\/code> (and takes in any of those parameters). The world map with launch sites now looks like this (complete ggplot code):<\/p>\n<pre><code class=\"language-r\">world &lt;- fortify(getMap())\nsites &lt;- as.data.frame(coordinates(readOGR(\"\/tmp\/launch-sites.kml\", \n                                           \"SpaceCenters: Non-Military Space Launch Sites\", \n                                           verbose=FALSE)))\n\ngg &lt;- ggplot()\ngg &lt;- gg + geom_map(data=world, map=world,\n                    aes(x=long, y=lat, map_id=id),\n                    color=\"black\", fill=\"white\", size=0.25)\ngg &lt;- gg + geom_point(data=(sites), \n                      aes(x=coords.x1, y=coords.x2), \n                      color=\"#b2182b\")\ngg &lt;- gg + coord_proj(\"+proj=wintri\")\ngg &lt;- gg + theme_map()\ngg\n<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_6-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3541\" data-permalink=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/ggplot_6-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_6-1.png?fit=672%2C480&amp;ssl=1\" data-orig-size=\"672,480\" 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=\"ggplot_6-1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_6-1.png?fit=300%2C214&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_6-1.png?fit=510%2C364&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_6-1.png?resize=510%2C364&#038;ssl=1\" alt=\"ggplot_6-1\" width=\"510\" height=\"364\" class=\"aligncenter size-full wp-image-3541\" \/><\/a><\/p>\n<p>Now, if you want to go all <em>Hobo-Dyer<\/em> instead of Winkel tripel, it&#8217;s one, small change:<\/p>\n<pre><code class=\"language-r\">gg + coord_proj(\"+proj=cea +lat_ts=37.5\")\n<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_7-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3539\" data-permalink=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/ggplot_7-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_7-1.png?fit=672%2C480&amp;ssl=1\" data-orig-size=\"672,480\" 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=\"ggplot_7-1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_7-1.png?fit=300%2C214&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_7-1.png?fit=510%2C364&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/ggplot_7-1.png?resize=510%2C364&#038;ssl=1\" alt=\"ggplot_7-1\" width=\"510\" height=\"364\" class=\"aligncenter size-full wp-image-3539\" \/><\/a><\/p>\n<p><a href=\"http:\/\/spatialreference.org\/\">Spatial Reference<\/a> is a website by Howard Butler, Christopher Schmidt, Dane Springmeyer, and Josh Livni that helps assist others in their understanding, recording, and usage of spatial reference systems. It&#8217;s ultimate goal is to let you use URI&#8217;s to specify spatial reference systems, but you can use it to lookup Proj4 strings to meet virtually any need you have.<\/p>\n<h3>The Bad News<\/h3>\n<p>Presently, <code>coord_proj<\/code> is <em>not<\/em> part of the ggplot2 code base. I chose a <em>really<\/em> bad time to muck with this as Hadley is doing all sorts of spiffy stuff to ggplot2 and it&#8217;s not a good time to shove this in there.<\/p>\n<p><em>You<\/em> <em>can<\/em> fork your own copy of ggplot2 from <a href=\"https:\/\/github.com\/tidyverse\/ggplot2\">Hadley&#8217;s GitHub repo<\/a> and add <a href=\"https:\/\/gist.github.com\/hrbrmstr\/363e33f74e2972c93ca7\">this file<\/a> to it, re-document\/collate\/build the package and then use it locally. It still needs some work (there&#8217;s a horrible hack in it that anyone familiar with geo-stuff will cringe at) but I welcome feedback\/contributions. Hopefully this will get into ggplot2 (or out of it and into a separate package since Hadley is making ggplot2 very extensible in his update) at some point in the not-too-distant future.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The $DAYJOB doesn&#8217;t afford much opportunity to work with cartographic datasets, but I really like maps and tinker with shapefiles and geo-data when I can, plus answer a ton of geo-questions on StackOverflow. R makes it easy\u2014one might even say too easy\u2014to work with maps. All it takes to make a map of the continental [&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":false,"_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,706,91],"tags":[810],"class_list":["post-3538","post","type-post","status-publish","format-standard","hentry","category-cartography","category-data-visualization","category-datavis-2","category-dataviz","category-maps","category-r","tag-post"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>A Path Towards Easier Map Projection Machinations with ggplot2 - 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\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Path Towards Easier Map Projection Machinations with ggplot2 - rud.is\" \/>\n<meta property=\"og:description\" content=\"The $DAYJOB doesn&#8217;t afford much opportunity to work with cartographic datasets, but I really like maps and tinker with shapefiles and geo-data when I can, plus answer a ton of geo-questions on StackOverflow. R makes it easy\u2014one might even say too easy\u2014to work with maps. All it takes to make a map of the continental [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2015-07-24T19:50:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-03T16:21:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.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=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"A Path Towards Easier Map Projection Machinations with ggplot2\",\"datePublished\":\"2015-07-24T19:50:24+00:00\",\"dateModified\":\"2020-04-03T16:21:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/\"},\"wordCount\":1455,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886\"},\"image\":{\"@id\":\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png\",\"keywords\":[\"post\"],\"articleSection\":[\"cartography\",\"Data Visualization\",\"DataVis\",\"DataViz\",\"maps\",\"R\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/\",\"url\":\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/\",\"name\":\"A Path Towards Easier Map Projection Machinations with ggplot2 - rud.is\",\"isPartOf\":{\"@id\":\"https:\/\/rud.is\/b\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png\",\"datePublished\":\"2015-07-24T19:50:24+00:00\",\"dateModified\":\"2020-04-03T16:21:36+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png?fit=672%2C480&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png?fit=672%2C480&ssl=1\",\"width\":672,\"height\":480},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/rud.is\/b\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A Path Towards Easier Map Projection Machinations with ggplot2\"}]},{\"@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":"A Path Towards Easier Map Projection Machinations with ggplot2 - 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\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/","og_locale":"en_US","og_type":"article","og_title":"A Path Towards Easier Map Projection Machinations with ggplot2 - rud.is","og_description":"The $DAYJOB doesn&#8217;t afford much opportunity to work with cartographic datasets, but I really like maps and tinker with shapefiles and geo-data when I can, plus answer a ton of geo-questions on StackOverflow. R makes it easy\u2014one might even say too easy\u2014to work with maps. All it takes to make a map of the continental [&hellip;]","og_url":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/","og_site_name":"rud.is","article_published_time":"2015-07-24T19:50:24+00:00","article_modified_time":"2020-04-03T16:21:36+00:00","og_image":[{"url":"https:\/\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png","type":"","width":"","height":""}],"author":"hrbrmstr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hrbrmstr","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"A Path Towards Easier Map Projection Machinations with ggplot2","datePublished":"2015-07-24T19:50:24+00:00","dateModified":"2020-04-03T16:21:36+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/"},"wordCount":1455,"commentCount":7,"publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"image":{"@id":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#primaryimage"},"thumbnailUrl":"https:\/\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png","keywords":["post"],"articleSection":["cartography","Data Visualization","DataVis","DataViz","maps","R"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/","url":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/","name":"A Path Towards Easier Map Projection Machinations with ggplot2 - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#primaryimage"},"image":{"@id":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#primaryimage"},"thumbnailUrl":"https:\/\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png","datePublished":"2015-07-24T19:50:24+00:00","dateModified":"2020-04-03T16:21:36+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#primaryimage","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png?fit=672%2C480&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/07\/base_1-1.png?fit=672%2C480&ssl=1","width":672,"height":480},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2015\/07\/24\/a-path-towards-easier-map-projection-machinations-with-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"A Path Towards Easier Map Projection Machinations with ggplot2"}]},{"@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-V4","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":3538,"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":3700,"url":"https:\/\/rud.is\/b\/2015\/10\/04\/replicating-natgeos-proper-earthquake-map-in-r\/","url_meta":{"origin":3538,"position":1},"title":"Replicating NatGeo&#8217;s &#8220;Proper&#8221; Earthquake Map in R","author":"hrbrmstr","date":"2015-10-04","format":false,"excerpt":"I saw this post over at NatGeo over the weekend and felt compelled to replicate this: with ggplot2. Three shapefiles later and we have it close enough to toss into a post (and I really don't believe the continent names are necessary). library(rgdal) library(ggplot2) library(ggthemes) library(ggalt) # devtools::install_github(\"hrbrmstr\/ggalt\") # grab\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\/2015\/10\/unnamed-chunk-1-1.png?fit=1200%2C685&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/10\/unnamed-chunk-1-1.png?fit=1200%2C685&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/10\/unnamed-chunk-1-1.png?fit=1200%2C685&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/10\/unnamed-chunk-1-1.png?fit=1200%2C685&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/10\/unnamed-chunk-1-1.png?fit=1200%2C685&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1591,"url":"https:\/\/rud.is\/b\/2012\/10\/05\/diy-zeroaccess-geoip-plots\/","url_meta":{"origin":3538,"position":2},"title":"DIY ZeroAccess GeoIP Plots","author":"hrbrmstr","date":"2012-10-05","format":false,"excerpt":"Since F-Secure was #spiffy enough to provide us with GeoIP data for mapping the scope of the ZeroAccess botnet, I thought that some aspiring infosec data scientists might want to see how to use something besides Google Maps & Google Earth to view the data. If you look at the\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":11840,"url":"https:\/\/rud.is\/b\/2019\/01\/30\/fast-static-maps-built-with-r\/","url_meta":{"origin":3538,"position":3},"title":"Fast Static Maps Built with R","author":"hrbrmstr","date":"2019-01-30","format":false,"excerpt":"Luke Whyte posted an article (apologies for a Medium link) over on Towards Data Science showing how to use a command line workflow involving curl, node and various D3 libraries and javascript source files to build a series of SVG static maps. It's well written and you should give it\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\/2019\/01\/fast-static-maps.png?fit=1200%2C806&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2019\/01\/fast-static-maps.png?fit=1200%2C806&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2019\/01\/fast-static-maps.png?fit=1200%2C806&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2019\/01\/fast-static-maps.png?fit=1200%2C806&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2019\/01\/fast-static-maps.png?fit=1200%2C806&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3832,"url":"https:\/\/rud.is\/b\/2015\/12\/28\/world-map-panel-plots-with-ggplot2-2-0-ggalt\/","url_meta":{"origin":3538,"position":4},"title":"World Map Panel Plots with ggplot2 2.0 &#038; ggalt","author":"hrbrmstr","date":"2015-12-28","format":false,"excerpt":"James Austin (@awhstin) made some #spiffy 4-panel maps with base R graphics but also posited he didn't use ggplot2 because: \u2026ggplot2 and maps currently do not support world maps at this point, which does not give us a great overall view. That is certainly a box I would not put\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\/2015\/12\/facetmaps.png?fit=1154%2C722&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/12\/facetmaps.png?fit=1154%2C722&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/12\/facetmaps.png?fit=1154%2C722&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/12\/facetmaps.png?fit=1154%2C722&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2015\/12\/facetmaps.png?fit=1154%2C722&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3442,"url":"https:\/\/rud.is\/b\/2015\/05\/26\/a-quick-incomplete-comparison-of-ggplot2-rbokeh-plotting-idioms\/","url_meta":{"origin":3538,"position":5},"title":"A quick, incomplete comparison of ggplot2 &#038; rbokeh plotting idioms","author":"hrbrmstr","date":"2015-05-26","format":false,"excerpt":"I set aside a small bit of time to give [rbokeh](https:\/\/github.com\/bokeh\/rbokeh) a try and figured I'd share a small bit of code that shows how to make the \"same\" chart in both ggplot2 and rbokeh. #### What is Bokeh\/rbokeh? rbokeh is an [htmlwidget](http:\/\/htmlwidgets.org) wrapper for the [Bokeh](http:\/\/bokeh.pydata.org\/en\/latest\/) visualization library that\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":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/3538","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=3538"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/3538\/revisions"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=3538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=3538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=3538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}