{"id":659,"date":"2014-07-15T09:48:32","date_gmt":"2014-07-15T16:48:32","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=659"},"modified":"2014-07-15T09:48:32","modified_gmt":"2014-07-15T16:48:32","slug":"horizon-plots-with-ggplot-not","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2014\/07\/15\/horizon-plots-with-ggplot-not\/","title":{"rendered":"Horizon plots with ggplot (not)"},"content":{"rendered":"<p style=\"color: #2d3433;\">The\u00a0<a style=\"font-weight: inherit; font-style: inherit; color: #d05b1c;\" href=\"http:\/\/timelyportfolio.blogspot.com\/2012\/08\/horizon-plots-with-plotxts.html\">Timely Portfolio<\/a>\u00a0blog via R-bloggers has recently published some interesting entries about the value of horizon plots for visual comparison of a number of time series.\u00a0<img loading=\"lazy\" decoding=\"async\" title=\"Horizon plot using lattice\" src=\"https:\/\/lh5.googleusercontent.com\/-SD0dnapgZkk\/UC5QaOmehJI\/AAAAAAACrT4\/bWjmEHnMe8Y\/s800\/plot.xts%2520horizon%2520plot.png\" alt=\"\" width=\"640\" height=\"800\" \/><\/p>\n<p style=\"color: #2d3433;\">Very nice it looks too. You can read more about them\u00a0<a style=\"font-weight: inherit; font-style: inherit; color: #d05b1c;\" href=\"http:\/\/www.perceptualedge.com\/blog\/?p=390\">here<\/a>. The trick to understanding them is to imagine that each row was orginally a line chart of six times the height. First colour the area between the origin and the line so that dark reds are very negative and dark blues very positive. Then, for each row, slice the chart into six horizontal slices and lay them on top of one another. That way you save a lot of vertical space so comparisons are easier. Dark red still means very negative, etc. The vertical scale is the same for each chart.<\/p>\n<p style=\"color: #2d3433;\">This one was done using the latticeExtra package in R. I couldn\u2019t figure out how to do them in ggplot. It was trivially easy to do a normal line chart and add a coloured background:<\/p>\n<blockquote style=\"color: #5c6b69;\">\n<pre style=\"font-weight: inherit; font-style: inherit;\">library(ggplot2)\nlibrary(reshape)\nrequire(PerformanceAnalytics)\ndata(edhec)\ned=data.frame(edhec)\ned$date=as.Date(rownames(ed))\nm=melt(ed,id=\"date\")\nm$variable=gsub('\\\\.',' ',m$variable)\nggplot(m,aes(date,0,fill=value))+geom_tile(aes(height=max(m$value)-min(m$value)))+geom_line(aes(x=date,y=value))+facet_grid(variable~.)+ scale_fill_gradient2(low=\"red\",high=\"blue\")+ylab(\"value\")+ opts(strip.text.y=theme_text(angle=0, hjust=1))<\/pre>\n<\/blockquote>\n<p style=\"color: #2d3433;\">That\u2019s it.<\/p>\n<p style=\"color: #2d3433;\"><a style=\"font-weight: inherit; font-style: inherit; color: #d05b1c;\" href=\"http:\/\/socialdatablog.com\/wp-content\/uploads\/2012\/08\/Rplot01.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Rplot01\" src=\"http:\/\/socialdatablog.com\/wp-content\/uploads\/2012\/08\/800x568xRplot01.png.pagespeed.ic.YEpDfuk9rF.png\" alt=\"\" width=\"800\" height=\"568\" \/><\/a><\/p>\n<p style=\"color: #2d3433;\">Not as sophisticated, but actually the colours help quite nicely for comparison without the complexity of the horizon approach. It seems less exciting \u2013 but then perhaps the horizon plot overstates its case a bit. And it is trivial to understand, which the horizon plot isn\u2019t.<\/p>\n<p style=\"color: #2d3433;\">What do you think, is the horizon plot worth the extra effort?<br \/>\nIs there an easy way to do horizon plots in ggplot?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The\u00a0Timely Portfolio\u00a0blog via R-bloggers has recently published some interesting entries about the value of horizon plots for visual comparison of a number of time series.\u00a0&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-659","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=659"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/659\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}