{"id":13893,"date":"2019-10-29T10:10:55","date_gmt":"2019-10-29T10:10:55","guid":{"rendered":"http:\/\/www.wjst.de\/blog\/?p=13893"},"modified":"2020-01-16T08:08:08","modified_gmt":"2020-01-16T08:08:08","slug":"a-new-animation-of-the-famous-hadcrut4-climate-dataset","status":"publish","type":"post","link":"https:\/\/www.wjst.de\/blog\/sciencesurf\/2019\/10\/a-new-animation-of-the-famous-hadcrut4-climate-dataset\/","title":{"rendered":"A new animation of the famous HadCRUT4 climate dataset"},"content":{"rendered":"<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/z3LG1OvsbLo\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><span data-mce-type=\"bookmark\" style=\"display: inline-block; width: 0px; overflow: hidden; line-height: 0;\" class=\"mce_SELRES_start\">\ufeff<\/span><\/iframe><\/p>\n<p><a href=\"https:\/\/www.wjst.de\/\/blog\/wp-content\/blogs.dir\/13\/files\/2019\/10\/ClimaCrisis.mp4\">Download<\/a><\/p>\n<p>Here is the R sample code (PPT aspect ratio is 6:4, Youtube wants 16:9) .<\/p>\n<p>As ggplot2 animation packages have major difficulties to manipulate the single frames, I am combining here raw PNGs using <a href=\"https:\/\/www.ffmpeg.org\/\">ffmpeg<\/a>.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n# read_cru_hemi() modified from https:\/\/mccartneytaylor.com\/plotting-climate-change-on-a-spider-graph-using-r\r\n\r\nlist.of.packages &lt;- c(&quot;ggplot2&quot;, &quot;reshape&quot;, &quot;stringr&quot;,&quot;RColorBrewer&quot;)\r\nnew.packages &lt;- list.of.packages&#x5B;!(list.of.packages %in% installed.packages()&#x5B;,&quot;Package&quot;])]\r\nif(length(new.packages)) install.packages(new.packages)\r\nlapply(list.of.packages, require, character.only = TRUE)\r\n\r\nread_cru_hemi &lt;- function(filename) {\r\n  tab &lt;- read.table(filename,fill=TRUE)\r\n  nrows &lt;- nrow(tab)\r\n  hemi &lt;- data.frame(\r\n    year=tab&#x5B;seq(1,nrows,2),1],\r\n    annual=tab&#x5B;seq(1,nrows,2),14],\r\n    month=array(tab&#x5B;seq(1,nrows,2),2:13]),\r\n    cover=array(tab&#x5B;seq(2,nrows,2),2:13])\r\n  )\r\n  hemi&#x5B;,15:26]&#x5B; hemi&#x5B;,15:26]==0 ] &lt;- c(NA)\r\n  return(hemi)\r\n}\r\n\r\nurl_dat &lt;- &quot;https:\/\/crudata.uea.ac.uk\/cru\/data\/temperature\/HadCRUT4-gl.dat&quot;\r\ntempdat &lt;- read_cru_hemi(url_dat)\r\ntempmelt &lt;- melt(tempdat&#x5B;,c(1,3:14)],id=&quot;year&quot;)\r\n\r\ncolfunc &lt;- colorRampPalette(c(&quot;grey&quot;,&quot;grey&quot;,&quot;red&quot;))\r\nFadeToGrey &lt;- colfunc(2019-1850)\r\n\r\nnew_theme &lt;- theme_classic() + theme(\r\n  text = element_text(size=18, colour=&quot;grey&quot;),\r\n  axis.line = element_blank(), \r\n  axis.text = element_text(colour=&quot;grey&quot;),\r\n  axis.ticks = element_line(colour=&quot;grey&quot;),\r\n  axis.title.x = element_blank(),\r\n  panel.border = element_blank(),\r\n  panel.grid.major = element_blank(),\r\n  panel.grid.minor = element_blank(),\r\n  panel.background = element_blank(),\r\n  legend.position = &quot;none&quot;\r\n)\r\ntheme_set(new_theme)\r\n\r\nfor(i in 1850:2019){\r\np &lt;- ggplot(tempmelt&#x5B;tempmelt$year %in% 1850:i,], aes(x=variable,y=value,color=as.factor(year),group=year)) + \r\n  geom_line() +\r\n  scale_x_discrete( labels=month.abb) +\r\n  scale_y_continuous( name=&quot;difference from baseline  &#x5B; oC ]&quot;, limits=c(-1,1) ) +\r\n  annotate(&quot;text&quot;, x=11, y=1, label=i, size=7) +\r\n  scale_color_manual( values=FadeToGrey&#x5B; 1:c(i-1849) ]  )\r\n  fn &lt;- paste(&quot;\/Users\/xxx\/Desktop\/X\/&quot;,str_pad(i-1849, 3, pad = &quot;0&quot;),&quot;.png&quot;,sep=&quot;&quot;)\r\n  ggsave(p, file=fn, width = 16, height = 9)\r\n}\r\n\r\n# not run\r\n# ffmpeg -framerate 10 -i \/Users\/xxx\/Desktop\/X\/%3d.png -r 5 -pix_fmt yuv420p -y \/Users\/xxx\/Desktop\/X\/out.mp4\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>In comparison here is the original circular plot. Would require blue, green, yellow, red in the Color Ramp Palette&#8230;<\/p>\n<p><a href=\"https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/edhawkinshadcrut4spiral.gif\" data-rel=\"key-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-13910\" src=\"https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/edhawkinshadcrut4spiral.gif\" alt=\"\" width=\"349\" height=\"376\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Now it is only a minor step to the warming strips.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nggplot(tempdat, aes(x = year, y = 1, fill = annual))+\r\n  geom_tile()+\r\n  scale_y_continuous(expand = c(0, 0))+\r\n  scale_x_continuous(expand = c(0, 0))+\r\n  scale_fill_gradientn(colors = rev(col_strip)) +\r\n  guides(fill = guide_colorbar(barwidth = 1)) +\r\n  theme( axis.ticks= element_blank(),\r\n         axis.text = element_blank(),\r\n         axis.title = element_blank()\r\n  )\r\n\r\ntempmelt$variable &lt;- as.numeric(str_replace(as.character(tempmelt$variable),&quot;month.&quot;,&quot;&quot;))\r\nggplot(tempmelt, aes(x = year, y = variable, z = value)) +\r\n  geom_raster(aes(fill = value)) +\r\n  scale_fill_gradientn(colors = rev(col_strip)) +\r\n  scale_x_continuous(expand = c(0,0)) +\r\n  scale_y_continuous(expand = c(0,0)) +\r\n  theme( axis.ticks= element_blank(),\r\n         axis.text = element_blank(),\r\n         axis.title = element_blank()\r\n  )\r\n<\/pre>\n<p><a href=\"https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01.png\" data-rel=\"key-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-15164\" src=\"https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01-620x465.png\" alt=\"\" width=\"620\" height=\"465\" srcset=\"https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01-620x465.png 620w, https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01-667x500.png 667w, https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01-768x576.png 768w, https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01.png 1000w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01-1.png\" data-rel=\"key-image-2\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01-1-620x465.png\" alt=\"\" width=\"620\" height=\"465\" class=\"alignnone size-medium wp-image-15166\" srcset=\"https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01-1-620x465.png 620w, https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01-1-667x500.png 667w, https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01-1-768x576.png 768w, https:\/\/www.wjst.de\/blog\/wp-content\/uploads\/2019\/10\/Rplot01-1.png 1000w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n\n<p>&nbsp;<\/p>\n<div class=\"bottom-note\">\n  <span class=\"mod1\">CC-BY-NC Science Surf , accessed 03.05.2026<\/span>\n <\/div>","protected":false},"excerpt":{"rendered":"<p>\ufeff Download Here is the R sample code (PPT aspect ratio is 6:4, Youtube wants 16:9) . As ggplot2 animation packages have major difficulties to manipulate the single frames, I am combining here raw PNGs using ffmpeg. # read_cru_hemi() modified from https:\/\/mccartneytaylor.com\/plotting-climate-change-on-a-spider-graph-using-r list.of.packages &lt;- c(&quot;ggplot2&quot;, &quot;reshape&quot;, &quot;stringr&quot;,&quot;RColorBrewer&quot;) new.packages &lt;- list.of.packages&#x5B;!(list.of.packages %in% installed.packages()&#x5B;,&quot;Package&quot;])] if(length(new.packages)) install.packages(new.packages) lapply(list.of.packages, &hellip; <a href=\"https:\/\/www.wjst.de\/blog\/sciencesurf\/2019\/10\/a-new-animation-of-the-famous-hadcrut4-climate-dataset\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">A new animation of the famous HadCRUT4 climate dataset<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3102],"tags":[2893,3246,1184,3244,3245],"class_list":["post-13893","post","type-post","status-publish","format-standard","hentry","category-one-world","tag-r","tag-animation","tag-climate","tag-crisis","tag-temperature"],"_links":{"self":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/13893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/comments?post=13893"}],"version-history":[{"count":33,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/13893\/revisions"}],"predecessor-version":[{"id":15167,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/13893\/revisions\/15167"}],"wp:attachment":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/media?parent=13893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/categories?post=13893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/tags?post=13893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}