

{"id":4501,"date":"2016-07-07T16:27:25","date_gmt":"2016-07-07T21:27:25","guid":{"rendered":"http:\/\/rud.is\/b\/?p=4501"},"modified":"2018-03-07T16:42:22","modified_gmt":"2018-03-07T21:42:22","slug":"bridging-the-political-polygons-gap-with-ggplot2","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/","title":{"rendered":"Bridging The Political [Polygons] Gap with ggplot2"},"content":{"rendered":"<p>The @pewresearch folks have been collecting political survey data for quite a while, and I noticed the [visualization below](http:\/\/www.people-press.org\/2014\/06\/12\/section-1-growing-ideological-consistency\/#interactive) referenced in a [Tableau vis contest entry](https:\/\/www.interworks.com\/blog\/rrouse\/2016\/06\/24\/politics-viz-contest-plotting-political-polarization):<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/Cursor_and_Political_Polarization_and_Growing_Ideological_Consistency___Pew_Research_Center.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4503\" data-permalink=\"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/cursor_and_political_polarization_and_growing_ideological_consistency___pew_research_center\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/Cursor_and_Political_Polarization_and_Growing_Ideological_Consistency___Pew_Research_Center.png?fit=669%2C631&amp;ssl=1\" data-orig-size=\"669,631\" 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=\"Cursor_and_Political_Polarization_and_Growing_Ideological_Consistency___Pew_Research_Center\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/Cursor_and_Political_Polarization_and_Growing_Ideological_Consistency___Pew_Research_Center.png?fit=510%2C481&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/Cursor_and_Political_Polarization_and_Growing_Ideological_Consistency___Pew_Research_Center.png?w=510&#038;ssl=1\" alt=\"Cursor_and_Political_Polarization_and_Growing_Ideological_Consistency___Pew_Research_Center\"  class=\"aligncenter size-full wp-image-4503\" \/><\/a><\/p>\n<p>Those are filled [frequency polygons](http:\/\/onlinestatbook.com\/2\/graphing_distributions\/freq_poly.html), which are super-easy to replicate in ggplot2, especially since Pew even _kind of_ made the data available via their interactive visualization (it&#8217;s available in other Pew resources, just not as compact). So, we can look at all 5 study years for both the general population and politically active respondents with `ggplot2` facets, incorporating the use of `V8`, `dplyr`, `tidyr`, `purrr` and some R spatial functions along the way.<\/p>\n<p>The first code block has the &#8220;data&#8221;, data transformations and initial plot code. The &#8220;data&#8221; is really javascript blocks picked up from the `view-source:` of the interactive visualization. We use the `V8` package to get this data then bend it to our will for visuals.<\/p>\n<pre id=\"plot_1\"><code class=\"language-r\">library(V8)\r\nlibrary(dplyr)\r\nlibrary(tidyr)\r\nlibrary(purrr)\r\nlibrary(ggplot2)  # devtools::install_github(&quot;hadley\/ggplot2)\r\nlibrary(hrbrmisc) # devtools::install_github(&quot;hrbrmstr\/hrbrmisc)\r\nlibrary(rgeos)\r\nlibrary(sp)\r\n\r\nctx &lt;- v8()\r\nctx$eval(&quot;\r\n\tvar party_data = [\r\n\t\t[{\r\n\t\t\tname: &#039;Dem&#039;,\r\n\t\t\tdata: [0.57,1.60,1.89,3.49,3.96,6.56,7.23,8.54,9.10,9.45,9.30,9.15,7.74,6.80,4.66,4.32,2.14,1.95,0.87,0.57,0.12]\r\n\t\t},{\r\n\t\t\tname: &#039;REP&#039;,\r\n\t\t\tdata: [0.03,0.22,0.28,1.49,1.66,2.77,3.26,4.98,5.36,7.28,7.72,8.16,8.86,8.88,8.64,8.00,6.20,5.80,4.87,4.20,1.34]\r\n\t\t}],\r\n\t\t[{\r\n\t\t\tname: &#039;Dem&#039;,\r\n\t\t\tdata: [1.22,2.78,3.28,5.12,6.15,7.77,8.24,9.35,9.73,9.19,8.83,8.47,5.98,5.17,3.62,2.87,1.06,0.75,0.20,0.15,0.04]\r\n\t\t}, {\r\n\t\t\tname: &#039;REP&#039;,\r\n\t\t\tdata: [0.23,0.49,0.65,2.23,2.62,4.06,5.02,7.53,7.70,7.28,7.72,8.15,8.87,8.47,7.08,6.27,4.29,3.99,3.54,2.79,1.03]\r\n\t\t}],\r\n\t\t[{\r\n\t\t\tname: &#039;Dem&#039;,\r\n\t\t\tdata: [2.07,3.57,4.21,6.74,7.95,8.41,8.58,9.07,8.98,8.46,8.47,8.49,5.39,3.62,2.11,1.98,1.00,0.55,0.17,0.17,0.00]\r\n\t\t}, {\r\n\t\t\tname: &#039;REP&#039;,\r\n\t\t\tdata: [0.19,0.71,1.04,2.17,2.07,3.65,4.92,7.28,8.26,9.64,9.59,9.55,7.91,7.74,6.84,6.01,4.37,3.46,2.09,1.65,0.86]\r\n\t\t}],\r\n\t\t[{\r\n\t\t\tname: &#039;Dem&#039;,\r\n\t\t\tdata: [2.97,4.09,4.28,6.65,7.90,8.37,8.16,8.74,8.61,8.15,7.74,7.32,4.88,4.82,2.79,2.07,0.96,0.78,0.41,0.29,0.02]\r\n\t\t}, {\r\n\t\t\tname: &#039;REP&#039;,\r\n\t\t\tdata: [0.04,0.21,0.28,0.88,1.29,2.64,3.08,4.92,5.84,6.65,6.79,6.92,8.50,8.61,8.05,8.00,7.52,7.51,5.61,4.17,2.50]\r\n\t\t}],\r\n\t\t[{\r\n\t\t\tname: &#039;Dem&#039;,\r\n\t\t\tdata: [4.81,6.04,6.57,7.67,7.84,8.09,8.24,8.91,8.60,6.92,6.69,6.47,4.22,3.85,1.97,1.69,0.66,0.49,0.14,0.10,0.03]\r\n\t\t}, {\r\n\t\t\tname: &#039;REP&#039;,\r\n\t\t\tdata: [0.11,0.36,0.49,1.23,1.35,2.35,2.83,4.63,5.09,6.12,6.27,6.41,7.88,8.03,7.58,8.26,8.12,7.29,6.38,5.89,3.34]\r\n\t\t}],\r\n\t];\r\n\r\n\tvar party_engaged_data = [\r\n\t\t[{\r\n\t\t\tname: &#039;Dem&#039;,\r\n\t\t\tdata: [0.88,2.19,2.61,4.00,4.76,6.72,7.71,8.45,8.03,8.79,8.79,8.80,7.23,6.13,4.53,4.31,2.22,2.01,1.05,0.66,0.13]\r\n\t\t}, {\r\n\t\t\tname: &#039;REP&#039;,\r\n\t\t\tdata: [0.00,0.09,0.09,0.95,1.21,1.67,2.24,3.22,3.70,6.24,6.43,6.62,8.01,8.42,8.97,8.48,7.45,7.68,8.64,7.37,2.53]\r\n\t\t}],\r\n\t\t[{\r\n\t\t\tname: &#039;Dem&#039;,\r\n\t\t\tdata: [1.61,3.35,4.25,6.75,8.01,8.20,8.23,9.14,8.94,8.68,8.46,8.25,4.62,3.51,2.91,2.63,1.19,0.74,0.24,0.17,0.12]\r\n\t\t},{\r\n\t\t\tname: &#039;REP&#039;,\r\n\t\t\tdata: [0.21,0.38,0.68,1.62,1.55,2.55,3.99,4.65,4.31,5.78,6.28,6.79,8.47,9.01,8.61,8.34,7.16,6.50,6.10,4.78,2.25]\r\n\t\t}],\r\n\t\t[{\r\n\t\t\tname: &#039;Dem&#039;,\r\n\t\t\tdata: [3.09,4.89,6.22,9.40,9.65,9.20,8.99,6.48,7.36,7.67,6.95,6.22,4.53,3.79,2.19,2.02,0.74,0.07,0.27,0.27,0.00]\r\n\t\t}, {\r\n\t\t\tname: &#039;REP&#039;,\r\n\t\t\tdata: [0.29,0.59,0.67,2.11,2.03,2.67,4.12,6.55,6.93,8.42,8.79,9.17,7.33,6.84,7.42,7.25,6.36,5.32,3.35,2.57,1.24]\r\n\t\t}],\r\n\t\t[{\r\n\t\t\tname: &#039;Dem&#039;,\r\n\t\t\tdata: [6.00,5.24,5.11,7.66,9.25,8.25,8.00,8.09,8.12,7.05,6.59,6.12,4.25,4.07,2.30,1.49,0.98,0.80,0.42,0.16,0.06]\r\n\t\t}, {\r\n\t\t\tname: &#039;REP&#039;,\r\n\t\t\tdata: [0.00,0.13,0.13,0.48,0.97,2.10,2.73,3.14,3.64,5.04,5.30,5.56,6.87,6.75,8.03,9.33,11.01,10.49,7.61,6.02,4.68]\r\n\t\t}],\r\n\t\t[{\r\n\t\t\tname: &#039;Dem&#039;,\r\n\t\t\tdata: [9.53,9.68,10.35,9.33,9.34,7.59,6.67,6.41,6.60,5.21,4.84,4.47,2.90,2.61,1.37,1.14,0.73,0.59,0.30,0.28,0.06]\r\n\t\t}, {\r\n\t\t\tname: &#039;REP&#039;,\r\n\t\t\tdata: [0.15,0.11,0.13,0.46,0.52,1.18,1.45,2.46,2.84,4.15,4.37,4.60,6.36,6.66,7.34,9.09,11.40,10.53,10.58,9.85,5.76]\r\n\t\t}],\r\n\t];\r\n&quot;)\r\n\r\nyears &lt;- c(1994, 1999, 2004, 2001, 2014)\r\n\r\n# Transform the javascript data -------------------------------------------\r\n\r\nparty_data &lt;- ctx$get(&quot;party_data&quot;)\r\nmap_df(1:length(party_data), function(i) {\r\n  x &lt;- party_data[[i]]\r\n  names(x$data) &lt;- x$name\r\n  dat &lt;- as.data.frame(x$data)\r\n  bind_cols(dat, data_frame(x=-10:10, year=rep(years[i], nrow(dat))))\r\n}) -&gt; party_data\r\n\r\nparty_engaged_data &lt;- ctx$get(&quot;party_engaged_data&quot;)\r\nmap_df(1:length(party_engaged_data), function(i) {\r\n  x &lt;- party_engaged_data[[i]]\r\n  names(x$data) &lt;- x$name\r\n  dat &lt;- as.data.frame(x$data)\r\n  bind_cols(dat, data_frame(x=-10:10, year=rep(years[i], nrow(dat))))\r\n}) -&gt; party_engaged_data\r\n\r\n# We need it in long form -------------------------------------------------\r\n\r\ngather(party_data, party, pct, -x, -year) %&gt;%\r\n  mutate(party=factor(party, levels=c(&quot;REP&quot;, &quot;Dem&quot;))) -&gt; party_data_long\r\n\r\ngather(party_engaged_data, party, pct, -x, -year) %&gt;%\r\n  mutate(party=factor(party, levels=c(&quot;REP&quot;, &quot;Dem&quot;))) -&gt; party_engaged_data_long\r\n\r\n# Traditional frequency polygon plots -------------------------------------\r\n\r\ngg &lt;- ggplot()\r\ngg &lt;- gg + geom_ribbon(data=party_data_long,\r\n                       aes(x=x, ymin=0, ymax=pct, fill=party, color=party), alpha=0.5)\r\ngg &lt;- gg + scale_x_continuous(expand=c(0,0), breaks=c(-8, 0, 8),\r\n                              labels=c(&quot;Consistently\\nliberal&quot;, &quot;Mixed&quot;, &quot;Consistently\\nconservative&quot;))\r\ngg &lt;- gg + scale_y_continuous(expand=c(0,0), limits=c(0, 12))\r\ngg &lt;- gg + scale_color_manual(name=NULL, values=c(Dem=&quot;#728ea2&quot;, REP=&quot;#cf6a5d&quot;),\r\n                              labels=c(Dem=&quot;Democrats&quot;, REP=&quot;Republicans&quot;))\r\ngg &lt;- gg + guides(color=&quot;none&quot;, fill=guide_legend(override.aes=list(alpha=1)))\r\ngg &lt;- gg + scale_fill_manual(name=NULL, values=c(Dem=&quot;#728ea2&quot;, REP=&quot;#cf6a5d&quot;),\r\n                             labels=c(Dem=&quot;Democrats&quot;, REP=&quot;Republicans&quot;))\r\ngg &lt;- gg + facet_wrap(~year, ncol=2, scales=&quot;free_x&quot;)\r\ngg &lt;- gg + labs(x=NULL, y=NULL,\r\n                title=&quot;Political Polarization, 1994-2014 (General Population)&quot;,\r\n                caption=&quot;Source: http:\/\/www.people-press.org\/2014\/06\/12\/section-1-growing-ideological-consistency\/iframe\/&quot;)\r\ngg &lt;- gg + theme_hrbrmstr_an(grid=&quot;&quot;)\r\ngg &lt;- gg + theme(panel.margin=margin(t=30, b=30, l=30, r=30))\r\ngg &lt;- gg + theme(legend.position=c(0.75, 0.1))\r\ngg &lt;- gg + theme(legend.direction=&quot;horizontal&quot;)\r\ngg &lt;- gg + theme(axis.text.y=element_blank())\r\ngg\r\n\r\ngg &lt;- ggplot()\r\ngg &lt;- gg + geom_ribbon(data=party_engaged_data_long,\r\n                       aes(x=x, ymin=0, ymax=pct, fill=party, color=party), alpha=0.5)\r\ngg &lt;- gg + scale_x_continuous(expand=c(0,0), breaks=c(-8, 0, 8),\r\n                              labels=c(&quot;Consistently\\nliberal&quot;, &quot;Mixed&quot;, &quot;Consistently\\nconservative&quot;))\r\ngg &lt;- gg + scale_y_continuous(expand=c(0,0), limits=c(0, 12))\r\ngg &lt;- gg + scale_color_manual(name=NULL, values=c(Dem=&quot;#728ea2&quot;, REP=&quot;#cf6a5d&quot;),\r\n                              labels=c(Dem=&quot;Democrats&quot;, REP=&quot;Republicans&quot;))\r\ngg &lt;- gg + guides(color=&quot;none&quot;, fill=guide_legend(override.aes=list(alpha=1)))\r\ngg &lt;- gg + scale_fill_manual(name=NULL, values=c(Dem=&quot;#728ea2&quot;, REP=&quot;#cf6a5d&quot;),\r\n                             labels=c(Dem=&quot;Democrats&quot;, REP=&quot;Republicans&quot;))\r\ngg &lt;- gg + facet_wrap(~year, ncol=2, scales=&quot;free_x&quot;)\r\ngg &lt;- gg + labs(x=NULL, y=NULL,\r\n                title=&quot;Political Polarization, 1994-2014 (Politically Active)&quot;,\r\n                caption=&quot;Source: http:\/\/www.people-press.org\/2014\/06\/12\/section-1-growing-ideological-consistency\/iframe\/&quot;)\r\ngg &lt;- gg + theme_hrbrmstr_an(grid=&quot;&quot;)\r\ngg &lt;- gg + theme(panel.margin=margin(t=30, b=30, l=30, r=30))\r\ngg &lt;- gg + theme(legend.position=c(0.75, 0.1))\r\ngg &lt;- gg + theme(legend.direction=&quot;horizontal&quot;)\r\ngg &lt;- gg + theme(axis.text.y=element_blank())\r\ngg<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/genalpha.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4507\" data-permalink=\"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/genalpha\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/genalpha.png?fit=1532%2C1408&amp;ssl=1\" data-orig-size=\"1532,1408\" 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=\"genalpha\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/genalpha.png?fit=510%2C469&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/genalpha.png?w=510&#038;ssl=1\" alt=\"genalpha\"  class=\"aligncenter size-full wp-image-4507\" \/><\/a><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engalpha.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4506\" data-permalink=\"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/engalpha\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engalpha.png?fit=1544%2C1412&amp;ssl=1\" data-orig-size=\"1544,1412\" 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=\"engalpha\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engalpha.png?fit=510%2C466&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engalpha.png?w=510&#038;ssl=1\" alt=\"engalpha\"  class=\"aligncenter size-full wp-image-4506\" \/><\/a><\/p>\n<p>It provides a similar effect to the Pew &#038; Interworks visuals using alpha transparency to blend the point of polygon intersections. But I _really_ kinda like the way both Pew &#038; Interworks did their visualizations without alpha blending yet still highlighting the intersected areas. We can do that in R as well with a bit more work by:<\/p>\n<p>&#8211; grouping each data frame by year<br \/>\n&#8211; turning each set of points (Dem &#038; Rep) to R polygons<br \/>\n&#8211; computing the intersection of those polygons<br \/>\n&#8211; turning that intersection back into a data frame<br \/>\n&#8211; adding this new polygon to the plots while also removing the alpha blend<\/p>\n<p>Here&#8217;s what that looks like in code:<\/p>\n<pre id=\"plot2\"><code class=\"language-r\"># Setup a function to do the polygon intersection -------------------------\r\n\r\npolysect &lt;- function(df) {\r\n\r\n  bind_rows(data_frame(x=-10, pct=0),\r\n            select(filter(df, party==&quot;Dem&quot;), x, pct),\r\n            data_frame(x=10, pct=0)) %&gt;%\r\n    as.matrix() %&gt;%\r\n    Polygon() %&gt;%\r\n    list() %&gt;%\r\n    Polygons(1) %&gt;%\r\n    list() %&gt;%\r\n    SpatialPolygons() -&gt; dem\r\n\r\n  bind_rows(data_frame(x=-10, pct=0),\r\n            select(filter(df, party==&quot;REP&quot;), x, pct),\r\n            data_frame(x=10, pct=0)) %&gt;%\r\n    as.matrix() %&gt;%\r\n    Polygon() %&gt;%\r\n    list() %&gt;%\r\n    Polygons(1) %&gt;%\r\n    list() %&gt;%\r\n    SpatialPolygons() -&gt; rep\r\n\r\n  inter &lt;- gIntersection(dem, rep)\r\n  inter &lt;- as.data.frame(inter@polygons[[1]]@Polygons[[1]]@coords)[c(-1, -25),]\r\n  inter &lt;- mutate(inter, year=df$year[1])\r\n  inter\r\n\r\n}\r\n\r\n# Get the intersected area ------------------------------------------------\r\n\r\ngroup_by(party_data_long, year) %&gt;%\r\n  do(polysect(.)) -&gt; general_sect\r\n\r\ngroup_by(party_engaged_data_long, year) %&gt;%\r\n  do(polysect(.)) -&gt; engaged_sect\r\n\r\n\r\n# Try the plots again -----------------------------------------------------\r\n\r\ngg &lt;- ggplot()\r\ngg &lt;- gg + geom_ribbon(data=party_data_long,\r\n                       aes(x=x, ymin=0, ymax=pct, fill=party, color=party))\r\ngg &lt;- gg + geom_ribbon(data=general_sect, aes(x=x, ymin=0, ymax=y), color=&quot;#666979&quot;, fill=&quot;#666979&quot;)\r\ngg &lt;- gg + scale_x_continuous(expand=c(0,0), breaks=c(-8, 0, 8),\r\n                              labels=c(&quot;Consistently\\nliberal&quot;, &quot;Mixed&quot;, &quot;Consistently\\nconservative&quot;))\r\ngg &lt;- gg + scale_y_continuous(expand=c(0,0), limits=c(0, 12))\r\ngg &lt;- gg + scale_color_manual(name=NULL, values=c(Dem=&quot;#728ea2&quot;, REP=&quot;#cf6a5d&quot;),\r\n                              labels=c(Dem=&quot;Democrats&quot;, REP=&quot;Republicans&quot;))\r\ngg &lt;- gg + guides(color=&quot;none&quot;, fill=guide_legend(override.aes=list(alpha=1)))\r\ngg &lt;- gg + scale_fill_manual(name=NULL, values=c(Dem=&quot;#728ea2&quot;, REP=&quot;#cf6a5d&quot;),\r\n                             labels=c(Dem=&quot;Democrats&quot;, REP=&quot;Republicans&quot;))\r\ngg &lt;- gg + facet_wrap(~year, ncol=2, scales=&quot;free_x&quot;)\r\ngg &lt;- gg + labs(x=NULL, y=NULL,\r\n                title=&quot;Political Polarization, 1994-2014 (General Population)&quot;,\r\n                caption=&quot;Source: http:\/\/www.people-press.org\/2014\/06\/12\/section-1-growing-ideological-consistency\/iframe\/&quot;)\r\ngg &lt;- gg + theme_hrbrmstr_an(grid=&quot;&quot;)\r\ngg &lt;- gg + theme(panel.margin=margin(t=30, b=30, l=30, r=30))\r\ngg &lt;- gg + theme(legend.position=c(0.75, 0.1))\r\ngg &lt;- gg + theme(legend.direction=&quot;horizontal&quot;)\r\ngg &lt;- gg + theme(axis.text.y=element_blank())\r\ngg\r\n\r\ngg &lt;- ggplot()\r\ngg &lt;- gg + geom_ribbon(data=party_engaged_data_long,\r\n                       aes(x=x, ymin=0, ymax=pct, fill=party, color=party))\r\ngg &lt;- gg + geom_ribbon(data=engaged_sect, aes(x=x, ymin=0, ymax=y), color=&quot;#666979&quot;, fill=&quot;#666979&quot;)\r\ngg &lt;- gg + scale_x_continuous(expand=c(0,0), breaks=c(-8, 0, 8),\r\n                              labels=c(&quot;Consistently\\nliberal&quot;, &quot;Mixed&quot;, &quot;Consistently\\nconservative&quot;))\r\ngg &lt;- gg + scale_y_continuous(expand=c(0,0), limits=c(0, 12))\r\ngg &lt;- gg + scale_color_manual(name=NULL, values=c(Dem=&quot;#728ea2&quot;, REP=&quot;#cf6a5d&quot;),\r\n                              labels=c(Dem=&quot;Democrats&quot;, REP=&quot;Republicans&quot;))\r\ngg &lt;- gg + guides(color=&quot;none&quot;, fill=guide_legend(override.aes=list(alpha=1)))\r\ngg &lt;- gg + scale_fill_manual(name=NULL, values=c(Dem=&quot;#728ea2&quot;, REP=&quot;#cf6a5d&quot;),\r\n                             labels=c(Dem=&quot;Democrats&quot;, REP=&quot;Republicans&quot;))\r\ngg &lt;- gg + facet_wrap(~year, ncol=2, scales=&quot;free_x&quot;)\r\ngg &lt;- gg + labs(x=NULL, y=NULL,\r\n                title=&quot;Political Polarization, 1994-2014 (Politically Active)&quot;,\r\n                caption=&quot;Source: http:\/\/www.people-press.org\/2014\/06\/12\/section-1-growing-ideological-consistency\/iframe\/&quot;)\r\ngg &lt;- gg + theme_hrbrmstr_an(grid=&quot;&quot;)\r\ngg &lt;- gg + theme(panel.margin=margin(t=30, b=30, l=30, r=30))\r\ngg &lt;- gg + theme(legend.position=c(0.75, 0.1))\r\ngg &lt;- gg + theme(legend.direction=&quot;horizontal&quot;)\r\ngg &lt;- gg + theme(axis.text.y=element_blank())\r\ngg<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/genfull.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4510\" data-permalink=\"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/genfull\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/genfull.png?fit=1530%2C1414&amp;ssl=1\" data-orig-size=\"1530,1414\" 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=\"genfull\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/genfull.png?fit=510%2C471&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/genfull.png?w=510&#038;ssl=1\" alt=\"genfull\"  class=\"aligncenter size-full wp-image-4510\" \/><\/a><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engfull.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4509\" data-permalink=\"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/engfull\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engfull.png?fit=1532%2C1402&amp;ssl=1\" data-orig-size=\"1532,1402\" 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=\"engfull\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engfull.png?fit=510%2C467&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engfull.png?w=510&#038;ssl=1\" alt=\"engfull\"  class=\"aligncenter size-full wp-image-4509\" \/><\/a><\/p>\n<p>Without much extra effort\/work we now have what I believe to be a more striking set of visuals. (And, I should probably makes a `points_to_spatial_polys()` convenience function.) <\/p>\n<p>You&#8217;ll find the &#8220;overall&#8221; group data as well as the party median values in [the Pew HTML source code](view-source:http:\/\/www.people-press.org\/2014\/06\/12\/section-1-growing-ideological-consistency\/iframe\/) if you want to try to fully replicate their visualizations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The @pewresearch folks have been collecting political survey data for quite a while, and I noticed the [visualization below](http:\/\/www.people-press.org\/2014\/06\/12\/section-1-growing-ideological-consistency\/#interactive) referenced in a [Tableau vis contest entry](https:\/\/www.interworks.com\/blog\/rrouse\/2016\/06\/24\/politics-viz-contest-plotting-political-polarization): Those are filled [frequency polygons](http:\/\/onlinestatbook.com\/2\/graphing_distributions\/freq_poly.html), which are super-easy to replicate in ggplot2, especially since Pew even _kind of_ made the data available via their interactive visualization (it&#8217;s available in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4509,"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":[678,673,674,753,91],"tags":[810],"class_list":["post-4501","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-visualization","category-datavis-2","category-dataviz","category-ggplot","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>Bridging The Political [Polygons] Gap 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\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bridging The Political [Polygons] Gap with ggplot2 - rud.is\" \/>\n<meta property=\"og:description\" content=\"The @pewresearch folks have been collecting political survey data for quite a while, and I noticed the [visualization below](http:\/\/www.people-press.org\/2014\/06\/12\/section-1-growing-ideological-consistency\/#interactive) referenced in a [Tableau vis contest entry](https:\/\/www.interworks.com\/blog\/rrouse\/2016\/06\/24\/politics-viz-contest-plotting-political-polarization): Those are filled [frequency polygons](http:\/\/onlinestatbook.com\/2\/graphing_distributions\/freq_poly.html), which are super-easy to replicate in ggplot2, especially since Pew even _kind of_ made the data available via their interactive visualization (it&#8217;s available in [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-07T21:27:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-03-07T21:42:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engfull.png?fit=1532%2C1402&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1532\" \/>\n\t<meta property=\"og:image:height\" content=\"1402\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"Bridging The Political [Polygons] Gap with ggplot2\",\"datePublished\":\"2016-07-07T21:27:25+00:00\",\"dateModified\":\"2018-03-07T21:42:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/\"},\"wordCount\":364,\"commentCount\":8,\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/07\\\/engfull.png?fit=1532%2C1402&ssl=1\",\"keywords\":[\"post\"],\"articleSection\":[\"Data Visualization\",\"DataVis\",\"DataViz\",\"ggplot\",\"R\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/\",\"name\":\"Bridging The Political [Polygons] Gap with ggplot2 - rud.is\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/07\\\/engfull.png?fit=1532%2C1402&ssl=1\",\"datePublished\":\"2016-07-07T21:27:25+00:00\",\"dateModified\":\"2018-03-07T21:42:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/07\\\/engfull.png?fit=1532%2C1402&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/07\\\/engfull.png?fit=1532%2C1402&ssl=1\",\"width\":1532,\"height\":1402},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/07\\\/07\\\/bridging-the-political-polygons-gap-with-ggplot2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/rud.is\\\/b\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bridging The Political [Polygons] Gap 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":"Bridging The Political [Polygons] Gap 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\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/","og_locale":"en_US","og_type":"article","og_title":"Bridging The Political [Polygons] Gap with ggplot2 - rud.is","og_description":"The @pewresearch folks have been collecting political survey data for quite a while, and I noticed the [visualization below](http:\/\/www.people-press.org\/2014\/06\/12\/section-1-growing-ideological-consistency\/#interactive) referenced in a [Tableau vis contest entry](https:\/\/www.interworks.com\/blog\/rrouse\/2016\/06\/24\/politics-viz-contest-plotting-political-polarization): Those are filled [frequency polygons](http:\/\/onlinestatbook.com\/2\/graphing_distributions\/freq_poly.html), which are super-easy to replicate in ggplot2, especially since Pew even _kind of_ made the data available via their interactive visualization (it&#8217;s available in [&hellip;]","og_url":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/","og_site_name":"rud.is","article_published_time":"2016-07-07T21:27:25+00:00","article_modified_time":"2018-03-07T21:42:22+00:00","og_image":[{"width":1532,"height":1402,"url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engfull.png?fit=1532%2C1402&ssl=1","type":"image\/png"}],"author":"hrbrmstr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hrbrmstr","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"Bridging The Political [Polygons] Gap with ggplot2","datePublished":"2016-07-07T21:27:25+00:00","dateModified":"2018-03-07T21:42:22+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/"},"wordCount":364,"commentCount":8,"publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"image":{"@id":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engfull.png?fit=1532%2C1402&ssl=1","keywords":["post"],"articleSection":["Data Visualization","DataVis","DataViz","ggplot","R"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/","url":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/","name":"Bridging The Political [Polygons] Gap with ggplot2 - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/#primaryimage"},"image":{"@id":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engfull.png?fit=1532%2C1402&ssl=1","datePublished":"2016-07-07T21:27:25+00:00","dateModified":"2018-03-07T21:42:22+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/#primaryimage","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engfull.png?fit=1532%2C1402&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engfull.png?fit=1532%2C1402&ssl=1","width":1532,"height":1402},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2016\/07\/07\/bridging-the-political-polygons-gap-with-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"Bridging The Political [Polygons] Gap 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":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/07\/engfull.png?fit=1532%2C1402&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p23idr-1aB","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":3442,"url":"https:\/\/rud.is\/b\/2015\/05\/26\/a-quick-incomplete-comparison-of-ggplot2-rbokeh-plotting-idioms\/","url_meta":{"origin":4501,"position":0},"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":[]},{"id":3832,"url":"https:\/\/rud.is\/b\/2015\/12\/28\/world-map-panel-plots-with-ggplot2-2-0-ggalt\/","url_meta":{"origin":4501,"position":1},"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":3054,"url":"https:\/\/rud.is\/b\/2014\/09\/26\/overcoming-d3-cartographic-envy-with-r-ggplot\/","url_meta":{"origin":4501,"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":2846,"url":"https:\/\/rud.is\/b\/2013\/12\/27\/points-polygons-and-power-outages\/","url_meta":{"origin":4501,"position":3},"title":"Points, Polygons and Power Outages","author":"hrbrmstr","date":"2013-12-27","format":false,"excerpt":"Most of my free coding time has been spent tweaking a D3-based live power outage tracker for Central Maine Power customers (there's also a woefully less-featured Shiny app for it, too). There is some R associated with the D3 vis, but it's limited to a cron job that's makes the\u2026","rel":"","context":"In &quot;Data Visualization&quot;","block_context":{"text":"Data Visualization","link":"https:\/\/rud.is\/b\/category\/data-visualization\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4154,"url":"https:\/\/rud.is\/b\/2016\/03\/18\/stacking-the-deck-against-treemaps\/","url_meta":{"origin":4501,"position":4},"title":"Stacking the deck against treemaps","author":"hrbrmstr","date":"2016-03-18","format":false,"excerpt":"So, I (unapologetically) did this to @Highcharts last week: @hrbrmstr Your loss of words inspired this post!! https:\/\/t.co\/3KO0BP0k0u @hadleywickham @ma_salmon @tdmv @bearloga @rushworth_a @awhstin\u2014 Highcharts (@Highcharts) March 18, 2016 They did an awesome makeover (it's interactive if you follow the link): And, I'm not kidding, it's actually a really good\u2026","rel":"","context":"In &quot;Data Visualization&quot;","block_context":{"text":"Data Visualization","link":"https:\/\/rud.is\/b\/category\/data-visualization\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/RStudioScreenSnapz021.png?fit=1200%2C695&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/RStudioScreenSnapz021.png?fit=1200%2C695&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/RStudioScreenSnapz021.png?fit=1200%2C695&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/RStudioScreenSnapz021.png?fit=1200%2C695&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/RStudioScreenSnapz021.png?fit=1200%2C695&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":4133,"url":"https:\/\/rud.is\/b\/2016\/03\/16\/supreme-annotations\/","url_meta":{"origin":4501,"position":5},"title":"Supreme Annotations","author":"hrbrmstr","date":"2016-03-16","format":false,"excerpt":"This is a follow up to a twitter-gist post & to the annotation party we're having this week I had not intended this to be \"Annotation Week\" but there was a large, positive response to my annotation \"hack\" post. This reaction surprised me, then someone pointed me to this link\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":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/supremes.png?fit=1200%2C987&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/supremes.png?fit=1200%2C987&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/supremes.png?fit=1200%2C987&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/supremes.png?fit=1200%2C987&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/supremes.png?fit=1200%2C987&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/4501","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=4501"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/4501\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media\/4509"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=4501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=4501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=4501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}