{"id":377,"date":"2012-03-19T07:46:48","date_gmt":"2012-03-19T07:46:48","guid":{"rendered":"http:\/\/rulesofreason.wordpress.com\/?p=377"},"modified":"2012-03-19T07:46:48","modified_gmt":"2012-03-19T07:46:48","slug":"visualizing-left-right-government-positions","status":"publish","type":"post","link":"http:\/\/re-design.dimiter.eu\/?p=377","title":{"rendered":"Visualizing left-right government positions"},"content":{"rendered":"<p>How does the political landscape of Europe change over time? One way to approach this question is to map the socio-economic left-right positions of the governments in power. So let&#8217;s plot the changing ideological \u00a0positions of the governments using data from the <a href=\"https:\/\/manifesto-project.wzb.eu\/\" target=\"_blank\">Manifesto<\/a> project! As you will see below, this proved to be a more challenging task than I imagined, but the preliminary results are worth sharing nonetheless.<\/p>\n<p>First, we need to extract the left-right positions from the <a href=\"https:\/\/manifesto-project.wzb.eu\/\" target=\"_blank\">Manifesto<\/a> dataset. Using the function described <a href=\"http:\/\/re-design.dimiter.eu\/2012\/03\/12\/compiling-government-positions-from-the-manifesto-project-data-with-r\/\" target=\"_blank\">here<\/a>, this is straightforward:<\/p>\n<p><code>lr2000&lt;-manifesto.position('rile', start=2000, end=2000)<\/code><\/p>\n<p>This compiles the (weighted) cabinet positions for the European countries for the year 2000. Next, let&#8217;s generate a static map. We can use the new <a href=\"http:\/\/cran.r-project.org\/web\/packages\/rworldmap\/index.html\" target=\"_blank\">package<\/a> <code>rworldmap <\/code>for this purpose. Let&#8217;s also build a custom palette that maps colors to left-right values. Since in Europe red traditionally is the color of the political left (the socialists), the palette ranges from dark red to gray to dark blue (for the right-wing governments).<\/p>\n<pre>library (rworldmap)\nop &lt;- palette(c('red4','red3','red2','red1','grey','blue1', 'blue2','blue3', 'blue4'))<\/pre>\n<p>After recoding the name of the UK, we are ready to bind our data and plot the map. You can save the map as a <code>png<\/code> file.<\/p>\n<pre>library(car)\nlr2000$State&lt;-recode(lr$State, \"'Great Britain'='United Kingdom'\")\n\nlrmapdata &lt;- joinCountryData2Map( lr2000,joinCode = \"NAME\", nameJoinColumn = \"State\", mapResolution='medium')\n\npar(mai=c(0,0,0.2,0),xaxs=\"i\",yaxs=\"i\")\npng(file='LR2000map.png', width=640,height=480)\nmapCountryData( lrmapdata, nameColumnToPlot=\"position\",colourPalette=op, xlim=c(-9,31), ylim=c(36,68), mapTitle='2000', aspect=1.25,addLegend=T )\ndev.off()<\/pre>\n<p>The limits on on the x- and y-axes center the map on Europe. It is a process of trial and error till you get it right, and the limits need to be co-ordinated with the aspect and the width and height of the <code>png<\/code> file so that the map looks reasonably well-proportioned. Here \u00a0is the result (click to see in full resolution):<\/p>\n<p><a href=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/lr2010map.png\"><img data-attachment-id=\"379\" data-permalink=\"http:\/\/re-design.dimiter.eu\/?attachment_id=379\" data-orig-file=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/lr2010map.png?fit=640%2C480\" data-orig-size=\"640,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=\"LR2010map\" data-image-description=\"\" data-medium-file=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/lr2010map.png?fit=300%2C225\" data-large-file=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/lr2010map.png?fit=640%2C480\" loading=\"lazy\" class=\"alignnone size-full wp-image-379\" title=\"LR2010map\" src=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/lr2010map.png?resize=584%2C438\" alt=\"\" width=\"584\" height=\"438\" srcset=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/lr2010map.png?w=640 640w, https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/lr2010map.png?resize=300%2C225 300w\" sizes=\"(max-width: 584px) 100vw, 584px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>It looks a bit chunky but not too bad. Next, we have to find a way to show developments over time. We could show several plots for different years on one page, but this is not very effective:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/rplot2.png\"><img data-attachment-id=\"384\" data-permalink=\"http:\/\/re-design.dimiter.eu\/?attachment_id=384\" data-orig-file=\"https:\/\/i0.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/rplot2.png?fit=600%2C400\" data-orig-size=\"600,400\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Rplot\" data-image-description=\"\" data-medium-file=\"https:\/\/i0.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/rplot2.png?fit=300%2C200\" data-large-file=\"https:\/\/i0.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/rplot2.png?fit=600%2C400\" loading=\"lazy\" class=\"alignnone size-full wp-image-384\" title=\"Rplot\" src=\"https:\/\/i0.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/rplot2.png?resize=584%2C389\" alt=\"\" width=\"584\" height=\"389\" srcset=\"https:\/\/i0.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/rplot2.png?w=600 600w, https:\/\/i0.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/03\/rplot2.png?resize=300%2C200 300w\" sizes=\"(max-width: 584px) 100vw, 584px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>A much better way would be to make the maps dynamic, or, in other words, to animate them. But this is easier said than done. After searching for a few days for tools that can accomplish the job, I settled for producing individual maps for each month, importing the series into Adobe Flash, and exporting a simple animation movie. The R code to produce\u00a0 the individual\u00a0 maps:<\/p>\n<pre>lr&lt;-manifesto.position('rile', start=1948, end=2008, period='month')\nlr$State&lt;-recode(lr$State, \"'Great Britain'='United Kingdom'\")\nu.c&lt;-unique(lr$Year.month)\nfor (i in 1:length(u.c)){\n     lr.temp&lt;-subset(lr, lr$Year.month==u.c[i])\n     lrmapdata &lt;- joinCountryData2Map( lr.temp,joinCode = \"NAME\", nameJoinColumn = \"State\", mapResolution='medium')\n     plot.name&lt;-paste('.\/maps\/map',i,'.png', sep='') \n\n     par(mai=c(0,0,0.2,0),xaxs=\"i\",yaxs=\"i\")\n     png(file=plot.name, width=640,height=480)\n     mapCountryData( lrmapdata, nameColumnToPlot=\"position\",colourPalette=op, xlim=c(-9,31), ylim=c(36,68), mapTitle=u.c[i], aspect=1.25,addLegend=T )\n     dev.off() }<\/pre>\n<p>And here is the result <em>(opens outside the post):<\/em><\/p>\n<p><a href=\"http:\/\/www.dimiter.eu\/leftright.html\" target=\"_blank\">Flash video of Left-Right positions<\/a> (slow)<\/p>\n<p>It kind of works, it has buttons for navigation, but it has one major flow &#8211; it is damn slow. It should be 12 frames (maps) per second, and it is 12 fps inside Flash, but once exported, the frame rate goes down (probably because my laptop&#8217;s processor is too slow). In fact, I <em>can<\/em> export a fast version, but only if I get rid of the control buttons. Here it is (right-click and press play to start):<\/p>\n<p><a href=\"http:\/\/www.dimiter.eu\/lrfast.html\" target=\"_blank\">Flash video of Left-Right positions<\/a> (fast)<\/p>\n<p>You can also play the animation as an AVI video (uploaded on YouTube), but somehow, through the mysteries of video-processing, a crisp slideshow of 8mb ended up as a low-res movie of 600mb.<\/p>\n<p><span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe class='youtube-player' width='640' height='360' src='https:\/\/www.youtube.com\/embed\/IkNEDkCtQNc?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en-US&#038;autohide=2&#038;wmode=transparent' allowfullscreen='true' style='border:0;' sandbox='allow-scripts allow-same-origin allow-popups allow-presentation'><\/iframe><\/span><br \/>\nThe results resemble my initial idea, although none is perfect. Ideally, I would want a fast movie with controls and a time-slider, but my Flash programming skills (and my computer) need to be upgraded for that. Meanwhile, the <a href=\"https:\/\/manifesto-project.wzb.eu\/\" target=\"_blank\">Manifesto<\/a> project could also update their data on which the animation is based.<\/p>\n<p>Altogether, the experience of creating the visualization has been much more painful than I anticipated. First, there doesn&#8217;t seem to be an easy way to get a map of Europe (or, more precisely, of the European Union territories) for use in R. The available options are\u00a0 either too low resolution, or too outdated (e.g. featuring Czechoslovakia), or require centering a world-map using <code>ylim<\/code> and <code>xlim<\/code> which is a problem because these coordinates are connected to the dimensions and the resolution of the output plot. For the US, and for individual European states, there are tons of slick and easy-to-find maps (shapefiles), but for Europe I couldn&#8217;t find anything that doesn&#8217;t feature huge tracts of land east to the Urals, which are irrelevant and remain empty with political data (which is usually available for the EU+ states only). Any pointers to good, relatively high-res maps (shapefiles) of the EU will be much appreciated.<\/p>\n<p>Second, producing an animation out of the individual maps is rather difficult. Currently, <a href=\"http:\/\/code.google.com\/apis\/chart\/\" target=\"_blank\">Google Charts<\/a> offer <a href=\"http:\/\/code.google.com\/apis\/chart\/interactive\/docs\/gallery\/motionchart.html\" target=\"_blank\">dynamic plots<\/a> and <a href=\"http:\/\/code.google.com\/apis\/chart\/interactive\/docs\/gallery\/geochart.html\" target=\"_blank\">static maps<\/a>, I hope in the future they include dynamic maps as well. Especially because the <code>googleVis<\/code> <a href=\"http:\/\/cran.r-project.org\/web\/packages\/googleVis\/index.html\" target=\"_blank\">package<\/a> makes it possible to build Google charts from within R. I also found a new tool called <a href=\"http:\/\/www.statsilk.com\/\" target=\"_blank\">StatPlanet<\/a> which seems relevant and rather cool, but still relies on Adobe Flash and has no packaged Europe\/EU maps. The big guns in visualization software are most probably up to the task but <a href=\"http:\/\/www.tableausoftware.com\/\" target=\"_blank\">Tableau<\/a> is prohibitively expensive and <a href=\"http:\/\/processing.org\/\" target=\"_blank\">Processing<\/a> is said to have a steep learning curve. Again, any help in identifying solutions that do not require proprietary software to produce animated maps would be much appreciated. I hope to be able to post an update on the project soon.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How does the political landscape of Europe change over time? One way to approach this question is to map the socio-economic left-right positions of the governments in power. So let&#8217;s plot the changing ideological \u00a0positions of the governments using data from the Manifesto project! As you will see below, this proved to be a more challenging task than I imagined, but the preliminary results are worth sharing nonetheless. First, we need to extract the left-right positions from the Manifesto dataset. Using the function described here, this is straightforward: lr2000&lt;-manifesto.position(&#8216;rile&#8217;, start=2000, end=2000) This compiles the (weighted) cabinet positions for the European countries for the year 2000. Next, let&#8217;s generate a static map. We can use the new package rworldmap for this purpose. Let&#8217;s also build a custom palette that maps colors to left-right values. Since in Europe red traditionally is the color of the political left (the socialists), the palette ranges from dark red to gray to dark blue (for the right-wing governments). library (rworldmap) op &lt;- palette(c(&#8216;red4&#8242;,&#8217;red3&#8242;,&#8217;red2&#8242;,&#8217;red1&#8242;,&#8217;grey&#8217;,&#8217;blue1&#8242;, &#8216;blue2&#8242;,&#8217;blue3&#8217;, &#8216;blue4&#8217;)) After recoding the name of the UK, we are ready to bind our data and plot the map. You can save the map as a png file. library(car) lr2000$State&lt;-recode(lr$State, &#8220;&#8216;Great Britain&#8217;=&#8217;United Kingdom'&#8221;) lrmapdata &lt;- joinCountryData2Map( lr2000,joinCode = &#8220;NAME&#8221;, nameJoinColumn = &#8220;State&#8221;, mapResolution=&#8217;medium&#8217;) par(mai=c(0,0,0.2,0),xaxs=&#8221;i&#8221;,yaxs=&#8221;i&#8221;) png(file=&#8217;LR2000map.png&#8217;, width=640,height=480) mapCountryData( lrmapdata, nameColumnToPlot=&#8221;position&#8221;,colourPalette=op, xlim=c(-9,31), ylim=c(36,68), mapTitle=&#8217;2000&#8242;, aspect=1.25,addLegend=T ) dev.off() The limits on on the x- and y-axes center the map on Europe. It is a process of trial and error till you get it right, and&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/re-design.dimiter.eu\/?p=377\">Continue reading<span class=\"screen-reader-text\">Visualizing left-right government positions<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[11,39],"tags":[72,162,196,198,245,306,345,377,394,399,464,465,501,575],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7g3hj-65","jetpack-related-posts":[{"id":1028,"url":"http:\/\/re-design.dimiter.eu\/?p=1028","url_meta":{"origin":377,"position":0},"title":"Government positions from party-level Manifesto data (with R)","date":"January 31, 2019","format":false,"excerpt":"In empirical research in political science and public policy, we often need estimates of the political positions of governments (cabinets) and the salience of different issues for different governments (cabinets). Data on policy positions and issue salience is available, but typically at the level of political parties. One prominent source\u2026","rel":"","context":"In &quot;Measurement&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":354,"url":"http:\/\/re-design.dimiter.eu\/?p=354","url_meta":{"origin":377,"position":1},"title":"Compiling government positions from the Manifesto Project data with R","date":"March 12, 2012","format":false,"excerpt":"****N.B. I have updated the functions in February 2019 to makes use of the latest Manifesto data. See for details here.*** The Manifesto Project (former Manifesto Research Group, Comparative Manifestos Project) has assembled a database of 'quantitative content analyses of parties\u2019 election programs from more than 50 countries covering all\u2026","rel":"","context":"In &quot;Policy making&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":346,"url":"http:\/\/re-design.dimiter.eu\/?p=346","url_meta":{"origin":377,"position":2},"title":"Creating Data Maps","date":"March 5, 2012","format":false,"excerpt":"There are several online tools for data visualization including IBM's ManyEyes and Google's Chart Tools. For a recent post on the other blog to which I contribute I wanted to map the distribution of a variable on a geographical map of Europe. I decided that's a good opportunity to try\u2026","rel":"","context":"In &quot;Data visualization&quot;","img":{"alt_text":"","src":"http:\/\/eurosearch.files.wordpress.com\/2012\/02\/exportmap.png?w=350&h=200&crop=1","width":350,"height":200},"classes":[]},{"id":948,"url":"http:\/\/re-design.dimiter.eu\/?p=948","url_meta":{"origin":377,"position":3},"title":"Books on data visualization","date":"November 21, 2017","format":false,"excerpt":"Here is a compilation of new and classic books on data visualization: \u00a0 Scott Murray (2017)\u00a0Interactive Data Visualization for the Web\u00a0[amazon asin=1491921285&template=add to cart] Elijah Meeks (2017)\u00a0D3.Js in Action: Data Visualization with JavaScript\u00a0[amazon asin=1617294489&template=add to cart] Alberto Cairo (2016)\u00a0The Truthful Art: Data, Charts, and Maps for Communication\u00a0[amazon asin=0321934075&template=add to cart]\u2026","rel":"","context":"In &quot;Data visualization&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":647,"url":"http:\/\/re-design.dimiter.eu\/?p=647","url_meta":{"origin":377,"position":4},"title":"New data source for political science researchers","date":"December 19, 2012","format":false,"excerpt":"Political Data Yearbook Interactive\u00a0is a new source for data on election results, turnout and government composition for all EU and some non-European countries. It is basically an online version of the yearbooks that ECPR printed as part of the European Journal for Political Research for many years now. The interactive\u2026","rel":"","context":"In &quot;Data visualization&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":837,"url":"http:\/\/re-design.dimiter.eu\/?p=837","url_meta":{"origin":377,"position":5},"title":"Immigration from Central and Eastern Europe fuels support for Eurosceptic parties in the UK","date":"May 4, 2015","format":false,"excerpt":"Combining political, demographic and economic data for the local level in the UK, we find that the presence of immigrants from Central and Eastern Europe (CEE) is related to higher voting shares cast for parties with Eurosceptic positions at the 2014 elections for the European Parliament. Evidence across Europe supports\u2026","rel":"","context":"In &quot;EU governance&quot;","img":{"alt_text":"Data source: Standard Eurobarometer (59 to 82).","src":"http:\/\/eurosearch.files.wordpress.com\/2015\/05\/figure-1-importance-of-immigration.png?w=350&h=200&crop=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=\/wp\/v2\/posts\/377"}],"collection":[{"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=377"}],"version-history":[{"count":0,"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=\/wp\/v2\/posts\/377\/revisions"}],"wp:attachment":[{"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}