

{"id":4203,"date":"2016-03-26T12:17:18","date_gmt":"2016-03-26T17:17:18","guid":{"rendered":"http:\/\/rud.is\/b\/?p=4203"},"modified":"2018-03-07T16:42:45","modified_gmt":"2018-03-07T21:42:45","slug":"nuclear-animations-in-r","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/","title":{"rendered":"Nuclear Animations in R"},"content":{"rendered":"<p>> UPDATE: For <a rel=\"tag\" class=\"hashtag u-tag u-category\" href=\"https:\/\/rud.is\/b\/tag\/rstats\/\">#rstats<\/a> folks interested in what this might look like in D3, [take a gander](https:\/\/rud.is\/b\/2016\/03\/27\/nuclear-animations-in-d3\/)<\/p>\n<p>@jsvine (Data Editor at BuzzFeed) cleaned up and posted a [data sets of historical nuclear explosions](https:\/\/github.com\/data-is-plural\/nuclear-explosions) earlier this week. I used it to show a few plotting examples in class, but it&#8217;s also a really fun data set to play around with: categorial countries; time series; lat\/long pairs; and, of course, nuclear explosions!<\/p>\n<p>My previous machinations with the data set were all static, so I though it&#8217;d be fun to make a WarGames-esque world map animation to show who boomed where and how many booms each ended up making. The code is below (after the video). It&#8217;s commented and there are some ggplot2 tricks in there that those new to R might be interested in.<\/p>\n<p>As I say in the code, I ended up tweaking `ffmpeg` parameters to get this video working on Twitter (the video file ended up being much, much smaller than the animated gif I originally toyed with making). Using `convert` from ImageMagick will quickly make a nice, local animated gif, or you can explore how to incorporate the ggplot2 frames into the `animation` package.<\/p>\n<div style=\"width: 510px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-4203-1\" width=\"510\" height=\"434\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/rud.is\/b\/wp-content\/uploads\/2016\/03\/booms.mp4?_=1\" \/><a href=\"https:\/\/rud.is\/b\/wp-content\/uploads\/2016\/03\/booms.mp4\">https:\/\/rud.is\/b\/wp-content\/uploads\/2016\/03\/booms.mp4<\/a><\/video><\/div>\n<pre id=\"booms\"><code class=\"language-r\">library(purrr)\r\nlibrary(dplyr)\r\nlibrary(tidyr)\r\nlibrary(sp)\r\nlibrary(maptools)\r\nlibrary(maps)\r\nlibrary(grid)\r\nlibrary(scales)\r\nlibrary(ggplot2)   # devtools::install_github(&quot;hadley\/ggplot2&quot;)\r\nlibrary(ggthemes)\r\nlibrary(gridExtra)\r\nlibrary(ggalt)\r\n\r\n# read and munge the data, being kind to github&#039;s servers\r\nURL &lt;- &quot;https:\/\/raw.githubusercontent.com\/data-is-plural\/nuclear-explosions\/master\/data\/sipri-report-explosions.csv&quot;\r\nfil &lt;- basename(URL)\r\nif (!file.exists(fil)) download.file(URL, fil)\r\n\r\nread.csv(fil, stringsAsFactors=FALSE) %&gt;%\r\n  tbl_df() %&gt;%\r\n  mutate(date=as.Date(as.character(date_long), format=&quot;%Y%m%d&quot;),\r\n         year=as.character(year),\r\n         yr=as.Date(sprintf(&quot;%s-01-01&quot;, year)),\r\n         country=sub(&quot;^PAKIST$&quot;, &quot;PAKISTAN&quot;, country)) -&gt; dat\r\n\r\n# doing this so we can order things by most irresponsible country to least\r\ncount(dat, country) %&gt;%\r\n  arrange(desc(n)) %&gt;%\r\n  mutate(country=factor(country, levels=unique(country))) -&gt; booms\r\n\r\n# Intercourse Antarctica\r\nworld_map &lt;- filter(map_data(&quot;world&quot;), region!=&quot;Antarctica&quot;)\r\n\r\nscary &lt;- &quot;#2b2b2b&quot; # a.k.a &quot;slate black&quot;\r\nlight &lt;- &quot;#bfbfbf&quot; # a.k.a &quot;off white&quot;\r\n\r\nproj &lt;- &quot;+proj=kav7&quot; # Winkel-Tripel is *so* 2015\r\n\r\n# In the original code I was using to play around with various themeing\r\n# and display options this encapsulated theme_ function really helped alot\r\n# but to do the grid.arrange with the bars it only ended up saving a teensy\r\n# bit of typing.\r\n#\r\n# Also, Tungsten is ridiculously expensive but I have access via corporate\r\n# subscriptions, so I&#039;d suggest going with Arial Narrow vs draining your\r\n# bank account since I really like the detailed kerning pairs but also think\r\n# that it&#039;s just a tad too narrow. It seemed fitting for this vis, tho.\r\n\r\ntheme_scary_world_map &lt;- function(scary=&quot;#2b2b2b&quot;, light=&quot;#8f8f8f&quot;) {\r\n  theme_map() +\r\n    theme(text=element_text(family=&quot;Tungsten-Light&quot;),\r\n          title=element_text(family=&quot;Tungsten-Semibold&quot;),\r\n          plot.background=element_rect(fill=scary, color=scary),\r\n          panel.background=element_rect(fill=scary, color=scary),\r\n          legend.background=element_rect(fill=scary),\r\n          legend.key=element_rect(fill=scary, color=scary),\r\n          legend.text=element_text(color=light, size=10),\r\n          legend.title=element_text(color=light),\r\n          axis.title=element_text(color=light),\r\n          axis.title.x=element_text(color=light, family=&quot;Tungsten-Book&quot;, size=14),\r\n          axis.title.y=element_blank(),\r\n          plot.title=element_text(color=light, face=&quot;bold&quot;, size=16),\r\n          plot.subtitle=element_text(color=light, family=&quot;Tungsten-Light&quot;,\r\n                                     size=13, margin=margin(b=14)),\r\n          plot.caption=element_text(color=light, family=&quot;Tungsten-ExtraLight&quot;,\r\n                                    size=9, margin=margin(t=10)),\r\n          plot.margin=margin(0, 0, 0, 0),\r\n          legend.position=&quot;bottom&quot;)\r\n}\r\n\r\n# I wanted to see booms by unique coords\r\ncount(dat, year, country, latitude, longitude) %&gt;%\r\n  ungroup() %&gt;%\r\n  mutate(country=factor(country, levels=unique(booms$country))) -&gt; dat_agg\r\n\r\nyears &lt;- as.character(seq(1945, 1998, 1))\r\n\r\n# place to hold the pngs\r\ndir.create(&quot;booms&quot;, FALSE)\r\n\r\n# I ended up lovingly hand-crafting ffmpeg parameters to get the animation to\r\n# work with Twitter&#039;s posting guidelines. A plain &#039;old ImageMagick &quot;convert&quot;\r\n# from multiple png&#039;s to animated gif will work fine for a local viewing\r\n\r\ntil &lt;- length(years)\r\npb &lt;- progress_estimated(til)\r\nsuppressWarnings(walk(1:til, function(i) {\r\n\r\n  pb$tick()$print()\r\n  \r\n  # data for map\r\n  tmp_dat &lt;- filter(dat_agg, year&lt;=years[i])\r\n\r\n  # data for bars\r\n  count(tmp_dat, country, wt=n) %&gt;%\r\n    arrange(desc(nn)) %&gt;%\r\n    mutate(country=factor(country, levels=unique(country))) %&gt;%\r\n    complete(country, fill=list(nn=0)) -&gt; boom2 # this gets us all the countries on the barplot x-axis even if the had no booms yet\r\n\r\n  gg &lt;- ggplot()\r\n  gg &lt;- gg + geom_map(data=world_map, map=world_map,\r\n                      aes(x=long, y=lat, map_id=region),\r\n                      color=light, size=0.1, fill=scary)\r\n  gg &lt;- gg + geom_point(data=tmp_dat,\r\n                        aes(x=longitude, y=latitude, size=n, color=country),\r\n                        shape=21, stroke=0.3)\r\n\r\n  # the &quot;trick&quot; here is to force the # of labeled breaks so ggplot2 doesn&#039;t\r\n  # truncate the range on us (it&#039;s nice that way and that feature is usually helpful)\r\n  gg &lt;- gg + scale_radius(name=&quot;&quot;, range=c(2, 8), limits=c(1, 50),\r\n                          breaks=c(5, 10, 25, 50),\r\n                          labels=c(&quot;1-4&quot;, &quot;5-9&quot;, &quot;10-24&quot;, &quot;25-50&quot;))\r\n\r\n  gg &lt;- gg + scale_color_brewer(name=&quot;&quot;, palette=&quot;Set1&quot;, drop=FALSE)\r\n  gg &lt;- gg + coord_proj(proj)\r\n  gg &lt;- gg + labs(x=years[i], y=NULL, title=&quot;Nuclear Explosions, 1945\u20131998&quot;,\r\n                  subtitle=&quot;Stockholm International Peace Research Institute (SIPRI) and Sweden&#039;s Defence Research Establishment&quot;,\r\n                  caption=NULL)\r\n\r\n  # order doesn&#039;t actually work but it will after I get a PR into ggplot2\r\n  # the tweaks here let us make the legends look like we want vs just mapped\r\n  # to the aesthetics\r\n  gg &lt;- gg + guides(size=guide_legend(override.aes=list(color=light, stroke=0.5)),\r\n                    color=guide_legend(override.aes=list(alpha=1, shape=16, size=3), nrow=1))\r\n\r\n  gg &lt;- gg + theme_scary_world_map(scary, light)\r\n  gg &lt;- gg + theme(plot.margin=margin(t=6, b=-1.5, l=4, r=4))\r\n  gg_map &lt;- gg\r\n  \r\n  gg\r\n\r\n  gg &lt;- ggplot(boom2, aes(x=country, y=nn))\r\n  gg &lt;- gg + geom_bar(stat=&quot;identity&quot;, aes(fill=country), width=0.5, color=light, size=0.05)\r\n  gg &lt;- gg + scale_x_discrete(expand=c(0,0))\r\n  gg &lt;- gg + scale_y_continuous(expand=c(0,0), limits=c(0, 1100))\r\n  gg &lt;- gg + scale_fill_brewer(name=&quot;&quot;, palette=&quot;Set1&quot;, drop=FALSE)\r\n  gg &lt;- gg + labs(x=NULL, y=NULL, title=NULL, subtitle=NULL,\r\n                  caption=&quot;Data from https:\/\/github.com\/data-is-plural\/nuclear-explosions&quot;)\r\n  gg &lt;- gg + theme_scary_world_map(scary, light)\r\n  gg &lt;- gg + theme(axis.text=element_text(color=light))\r\n  gg &lt;- gg + theme(axis.text.x=element_text(color=light, size=11, margin=margin(t=2)))\r\n  gg &lt;- gg + theme(axis.text.y=element_text(color=light, size=6, margin=margin(r=5)))\r\n  gg &lt;- gg + theme(axis.title.x=element_blank())\r\n  gg &lt;- gg + theme(plot.margin=margin(l=20, r=20, t=-1.5, b=5))\r\n  gg &lt;- gg + theme(panel.grid=element_line(color=light, size=0.15))\r\n  gg &lt;- gg + theme(panel.margin=margin(0, 0, 0, 0))\r\n  gg &lt;- gg + theme(panel.grid.major.x=element_blank())\r\n  gg &lt;- gg + theme(panel.grid.major.y=element_line(color=light, size=0.05))\r\n  gg &lt;- gg + theme(panel.grid.minor=element_blank())\r\n  gg &lt;- gg + theme(panel.grid.minor.x=element_blank())\r\n  gg &lt;- gg + theme(panel.grid.minor.y=element_blank())\r\n  gg &lt;- gg + theme(axis.line=element_line(color=light, size=0.1))\r\n  gg &lt;- gg + theme(axis.line.x=element_line(color=light, size=0.1))\r\n  gg &lt;- gg + theme(axis.line.y=element_blank())\r\n  gg &lt;- gg + theme(legend.position=&quot;none&quot;)\r\n  gg_bars &lt;- gg\r\n\r\n  # dimensions arrived at via trial and error\r\n\r\n  png(sprintf(&quot;.\/booms\/frame_%03d.png&quot;, i), width=639.5*2, height=544*2, res=144, bg=scary)\r\n  grid.arrange(gg_map, gg_bars, ncol=1, heights=c(0.85, 0.15), padding=unit(0, &quot;null&quot;), clip=&quot;on&quot;)\r\n  dev.off()\r\n\r\n}))<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>> UPDATE: For #rstats folks interested in what this might look like in D3, [take a gander](https:\/\/rud.is\/b\/2016\/03\/27\/nuclear-animations-in-d3\/) @jsvine (Data Editor at BuzzFeed) cleaned up and posted a [data sets of historical nuclear explosions](https:\/\/github.com\/data-is-plural\/nuclear-explosions) earlier this week. I used it to show a few plotting examples in class, but it&#8217;s also a really fun data set [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4215,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[24,678,673,674,753,91],"tags":[810],"class_list":["post-4203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-charts-graphs","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>Nuclear Animations in R - rud.is<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Nuclear Animations in R - rud.is\" \/>\n<meta property=\"og:description\" content=\"&gt; UPDATE: For #rstats folks interested in what this might look like in D3, [take a gander](https:\/\/rud.is\/b\/2016\/03\/27\/nuclear-animations-in-d3\/) @jsvine (Data Editor at BuzzFeed) cleaned up and posted a [data sets of historical nuclear explosions](https:\/\/github.com\/data-is-plural\/nuclear-explosions) earlier this week. I used it to show a few plotting examples in class, but it&#8217;s also a really fun data set [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2016-03-26T17:17:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-03-07T21:42:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1967%2C1551&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1967\" \/>\n\t<meta property=\"og:image:height\" content=\"1551\" \/>\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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"Nuclear Animations in R\",\"datePublished\":\"2016-03-26T17:17:18+00:00\",\"dateModified\":\"2018-03-07T21:42:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/\"},\"wordCount\":230,\"commentCount\":13,\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/03\\\/ogimg.png?fit=1967%2C1551&ssl=1\",\"keywords\":[\"post\"],\"articleSection\":[\"Charts &amp; Graphs\",\"Data Visualization\",\"DataVis\",\"DataViz\",\"ggplot\",\"R\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/\",\"name\":\"Nuclear Animations in R - rud.is\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/03\\\/ogimg.png?fit=1967%2C1551&ssl=1\",\"datePublished\":\"2016-03-26T17:17:18+00:00\",\"dateModified\":\"2018-03-07T21:42:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/03\\\/ogimg.png?fit=1967%2C1551&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/03\\\/ogimg.png?fit=1967%2C1551&ssl=1\",\"width\":1967,\"height\":1551},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/03\\\/26\\\/nuclear-animations-in-r\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/rud.is\\\/b\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Nuclear Animations in R\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/\",\"name\":\"rud.is\",\"description\":\"&quot;In God we trust. All others must bring data&quot;\",\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/rud.is\\\/b\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\",\"name\":\"hrbrmstr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"width\":460,\"height\":460,\"caption\":\"hrbrmstr\"},\"logo\":{\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\"},\"description\":\"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7\",\"sameAs\":[\"http:\\\/\\\/rud.is\"],\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/author\\\/hrbrmstr\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Nuclear Animations in R - rud.is","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/","og_locale":"en_US","og_type":"article","og_title":"Nuclear Animations in R - rud.is","og_description":"> UPDATE: For #rstats folks interested in what this might look like in D3, [take a gander](https:\/\/rud.is\/b\/2016\/03\/27\/nuclear-animations-in-d3\/) @jsvine (Data Editor at BuzzFeed) cleaned up and posted a [data sets of historical nuclear explosions](https:\/\/github.com\/data-is-plural\/nuclear-explosions) earlier this week. I used it to show a few plotting examples in class, but it&#8217;s also a really fun data set [&hellip;]","og_url":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/","og_site_name":"rud.is","article_published_time":"2016-03-26T17:17:18+00:00","article_modified_time":"2018-03-07T21:42:45+00:00","og_image":[{"width":1967,"height":1551,"url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1967%2C1551&ssl=1","type":"image\/png"}],"author":"hrbrmstr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hrbrmstr","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"Nuclear Animations in R","datePublished":"2016-03-26T17:17:18+00:00","dateModified":"2018-03-07T21:42:45+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/"},"wordCount":230,"commentCount":13,"publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"image":{"@id":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1967%2C1551&ssl=1","keywords":["post"],"articleSection":["Charts &amp; Graphs","Data Visualization","DataVis","DataViz","ggplot","R"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/","url":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/","name":"Nuclear Animations in R - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/#primaryimage"},"image":{"@id":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1967%2C1551&ssl=1","datePublished":"2016-03-26T17:17:18+00:00","dateModified":"2018-03-07T21:42:45+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/#primaryimage","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1967%2C1551&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1967%2C1551&ssl=1","width":1967,"height":1551},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2016\/03\/26\/nuclear-animations-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"Nuclear Animations in R"}]},{"@type":"WebSite","@id":"https:\/\/rud.is\/b\/#website","url":"https:\/\/rud.is\/b\/","name":"rud.is","description":"&quot;In God we trust. All others must bring data&quot;","publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rud.is\/b\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886","name":"hrbrmstr","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","width":460,"height":460,"caption":"hrbrmstr"},"logo":{"@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1"},"description":"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7","sameAs":["http:\/\/rud.is"],"url":"https:\/\/rud.is\/b\/author\/hrbrmstr\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1967%2C1551&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p23idr-15N","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":4209,"url":"https:\/\/rud.is\/b\/2016\/03\/27\/nuclear-animations-in-d3\/","url_meta":{"origin":4203,"position":0},"title":"Nuclear Animations in D3","author":"hrbrmstr","date":"2016-03-27","format":false,"excerpt":"As I said, I'm kinda obsessed with the \"nuclear\" data set. So much so that I made a D3 version that's similar to the R version I made the other day. I tried not to code much today (too much Easter fun going on), so I left off the size\u2026","rel":"","context":"In &quot;cartography&quot;","block_context":{"text":"cartography","link":"https:\/\/rud.is\/b\/category\/cartography\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1200%2C946&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1200%2C946&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1200%2C946&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1200%2C946&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/ogimg.png?fit=1200%2C946&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":4396,"url":"https:\/\/rud.is\/b\/2016\/05\/14\/global-temperature-change-in-r-d3-without-the-vertigo\/","url_meta":{"origin":4203,"position":1},"title":"Global Temperature Change in R &#038; D3 (without the vertigo)","author":"hrbrmstr","date":"2016-05-14","format":false,"excerpt":"This made the rounds on social media last week: Spiraling global temperatures from 1850-2016 (full animation) https:\/\/t.co\/YETC5HkmTr pic.twitter.com\/Ypci717AHq\u2014 Ed Hawkins (@ed_hawkins) May 9, 2016 One of the original versions was static and was not nearly as popular, but\u2014as you can see\u2014this one went viral. Despite the public's infatuation with circles\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\/05\/hadcrut.png?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/05\/hadcrut.png?fit=1200%2C600&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/05\/hadcrut.png?fit=1200%2C600&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/05\/hadcrut.png?fit=1200%2C600&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/05\/hadcrut.png?fit=1200%2C600&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3117,"url":"https:\/\/rud.is\/b\/2014\/11\/16\/moving-the-earth-well-alaska-hawaii-with-r\/","url_meta":{"origin":4203,"position":2},"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":1507,"url":"https:\/\/rud.is\/b\/2012\/07\/12\/ssh-password-time-series-heatmap-in-d3\/","url_meta":{"origin":4203,"position":3},"title":"SSH Password Time-series Heatmap In D3","author":"hrbrmstr","date":"2012-07-12","format":false,"excerpt":"In @jayjacobs' latest post on SSH honeypot passsword analysis he shows some spiffy visualizations from crunching the data with Tableau. While I've joked with him and called them \"robocharts\", the reality is that Tableau does let you work on visualizing the answers to questions quickly without having to go into\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":2728,"url":"https:\/\/rud.is\/b\/2013\/09\/28\/obamacare-jobs-r-d3\/","url_meta":{"origin":4203,"position":4},"title":"Visualizing &#8220;ObamaCare-related&#8221; Job Cuts","author":"hrbrmstr","date":"2013-09-28","format":false,"excerpt":"UPDATE: Added some extra visualization elements since this post went live. New select menu and hover text for individual job impact detail lines in the table. I was reviewing RSS feeds when I came across this story about \"ObamaCare Employer Mandate: A List Of Cuts To Work Hours, Jobs\" over\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\/2013\/09\/oc-snap.png.png?fit=945%2C660&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/09\/oc-snap.png.png?fit=945%2C660&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/09\/oc-snap.png.png?fit=945%2C660&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/09\/oc-snap.png.png?fit=945%2C660&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":3028,"url":"https:\/\/rud.is\/b\/2014\/09\/20\/chartingmapping-the-scottish-vote-with-r-rvestdplyrtidyrtopojsonggplot\/","url_meta":{"origin":4203,"position":5},"title":"Charting\/Mapping the Scottish Vote with R (an rvest\/dplyr\/tidyr\/TopoJSON\/ggplot tutorial)","author":"hrbrmstr","date":"2014-09-20","format":false,"excerpt":"The BBC did a pretty good job [live tracking the Scotland secession vote](http:\/\/www.bbc.com\/news\/events\/scotland-decides\/results), but I really didn't like the color scheme they chose and decided to use the final tally site as the basis for another tutorial using the tools from the Hadleyverse and taking advantage of the fact 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\/4203","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=4203"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/4203\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media\/4215"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=4203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=4203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=4203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}