{"id":645,"date":"2013-12-06T14:00:27","date_gmt":"2013-12-06T03:00:27","guid":{"rendered":"http:\/\/blog.panicola.com\/?p=645"},"modified":"2013-12-06T14:01:11","modified_gmt":"2013-12-06T03:01:11","slug":"flowing-data-r-tutorial","status":"publish","type":"post","link":"https:\/\/blog.panicola.com\/?p=645","title":{"rendered":"Flowing Data: R tutorial"},"content":{"rendered":"<p>This is a very cool intro to the power of R. It may come in handy&#8230;<\/p>\n<p><a href=\"http:\/\/flowingdata.com\/2013\/11\/26\/the-baseline\/\">http:\/\/flowingdata.com\/2013\/11\/26\/the-baseline\/<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"02-Percent change monthly\" src=\"http:\/\/i2.wp.com\/flowingdata.com\/wp-content\/uploads\/2013\/11\/02-Percent-change-monthly.png?resize=625%2C300\" width=\"625\" height=\"300\" \/><\/p>\n<p>This is noisy though. Maybe a year-over-year change would be more useful.<\/p>\n<div id=\"highlighter_137144\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>curr &lt;- gas$Value[-(1:12)]<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>prev &lt;- gas$Value[1:(<\/code><code>length<\/code><code>(gas$Value)-12)]<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>annChange &lt;- 100 *\u00a0<\/code><code>round<\/code><code>( (curr-prev) \/ prev, 2 )<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>4<\/code><\/td>\n<td><code>barCols &lt;-\u00a0<\/code><code>sapply<\/code><code>(annChange,<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>5<\/code><\/td>\n<td><code>\u00a0\u00a0\u00a0\u00a0<\/code><code>function<\/code><code>(x) {<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>6<\/code><\/td>\n<td><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code>if\u00a0<\/code><code>(x &lt; 0) {<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>7<\/code><\/td>\n<td><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code>return<\/code><code>(<\/code><code>\"#2cbd25\"<\/code><code>)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>8<\/code><\/td>\n<td><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code>}\u00a0<\/code><code>else<\/code>\u00a0<code>{<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>9<\/code><\/td>\n<td><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code>return<\/code><code>(<\/code><code>\"gray\"<\/code><code>)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>10<\/code><\/td>\n<td><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code>}<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>11<\/code><\/td>\n<td><code>\u00a0\u00a0\u00a0\u00a0<\/code><code>})<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>12<\/code><\/td>\n<td><code>barplot<\/code><code>(annChange, border=<\/code><code>NA<\/code><code>, space=0, las=1, col=barCols, main=<\/code><code>\"% change, annual\"<\/code><code>)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>The magnitude of drops in price are more visible this way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a very cool intro to the power of R. It may come in handy&#8230; http:\/\/flowingdata.com\/2013\/11\/26\/the-baseline\/ This is noisy though. Maybe a year-over-year change would be more useful. 1 curr &lt;- gas$Value[-(1:12)] 2 prev &lt;- gas$Value[1:(length(gas$Value)-12)] 3 annChange &lt;- 100 *\u00a0round( (curr-prev) \/ prev, 2 ) 4 barCols &lt;-\u00a0sapply(annChange, 5 \u00a0\u00a0\u00a0\u00a0function(x) { 6 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if\u00a0(x &hellip; <a href=\"https:\/\/blog.panicola.com\/?p=645\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Flowing Data: R tutorial<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,5],"tags":[],"class_list":["post-645","post","type-post","status-publish","format-standard","hentry","category-cool","category-data-saving-lives"],"_links":{"self":[{"href":"https:\/\/blog.panicola.com\/index.php?rest_route=\/wp\/v2\/posts\/645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.panicola.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.panicola.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.panicola.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.panicola.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=645"}],"version-history":[{"count":2,"href":"https:\/\/blog.panicola.com\/index.php?rest_route=\/wp\/v2\/posts\/645\/revisions"}],"predecessor-version":[{"id":647,"href":"https:\/\/blog.panicola.com\/index.php?rest_route=\/wp\/v2\/posts\/645\/revisions\/647"}],"wp:attachment":[{"href":"https:\/\/blog.panicola.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.panicola.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.panicola.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}