<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/the-hourly-heatmap-with-ggplot2/"></div></div><div><a data-url="https://www.r-bloggers.com/the-hourly-heatmap-with-ggplot2/" data-counturl="https://www.r-bloggers.com/the-hourly-heatmap-with-ggplot2/" data-count="horizontal" data-text="The hourly heatmap with ggplot2" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://johnmackintosh.com/2016-12-01-the-hourly-heatmap/"> HighlandR</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>	a quick follow up to my last post – </p>
<p>I’ve had a few folk get in touch following my <a target="_blank" rel="nofollow" href="http://johnmackintosh.com/2016-11-27-calendar-heatmaps/">last post</a>, all commenting on the last plot :</p>
<p><img alt="2016-11-30DailyTemps.png" src="https://i1.wp.com/johnmackintosh.com/img/2016-11-30DailyTemps.png?w=456" data-recalc-dims="1"></p>
<p>Most of these enquiries went along the following lines:</p>
<p>“I hadn’t thought of doing that. It looks really easy. But how do you do it?”</p>
<p>Unfortunately I was away the last couple of days without access to the code, and I didn’t want to pass on the wrong info.<br>
Back home now though, and the code is now uploaded as a gist to GitHub :</p>
<p><a target="_blank" rel="nofollow" href="https://gist.github.com/johnmackintosh/520643a1f82a0c7df00cf949ba98a4e9">HeatmapHrbyDay.R</a></p>
<p>What is the use case? Any organisation/operation that is 24/7 will have some sort of data they can monitor via such a plot. Server loads / web traffic etc could also be analysed this way.</p>
<p>Some comments :</p>
<ul>
<li>
<p>The Interpol dataset is pretty large, so we filter out for the first weather station, which conveniently had 2 full years data. We remove all the data we don’t need as we go.</p>
</li>
<li>
<p>I use the <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/ggExtra/vignettes/ggExtra.html">ggExtra</a> package for easy removal of gridlines (and depending on the plot, easy rotation of axis labels). I know these are not the main functions or reason for the ggExtra package existing, but these commands are easy to remember. Big thanks to <a target="_blank" rel="nofollow" href="http://deanattali.com/">Dean Attali</a> for all his work on this and other cool R packages. You don’t have to use this package to remove the gridlines, but I will leave you to find the necessary syntax (hint : check my first blog post).</p>
</li>
<li>
<p>The beauty and flexibility of ggplot2 is demonstrated once again. The bulk of the plot is produced with these few lines:</p>
<p>p &lt;-ggplot(df,aes(day,hour,fill=temp))+<br>
geom_tile(color= “white”,size=0.1) +<br>
scale_fill_viridis(name=”# Hrly Temps C”,option =”C”)<br>
p &lt;-p + facet_grid(year~month)</p>
</li>
</ul>
<p>If you type ‘p’ in the console at this point you will see the plot. The rest of the code is formatting tweaks.<br>
For more heatmap awesomeness, check out Bob Rudis’s blog:<br>
<a target="_blank" rel="nofollow" href="https://rud.is/projects/facetedheatmaps.html">Bob Rudis faceted heatmaps</a></p>
<p>I think I’m done with heatmaps for the time being – hope this helped you visualise your data, would love to hear from you if it did.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/the-hourly-heatmap-with-ggplot2/"></div></div><div><a data-url="https://www.r-bloggers.com/the-hourly-heatmap-with-ggplot2/" data-counturl="https://www.r-bloggers.com/the-hourly-heatmap-with-ggplot2/" data-count="vertical" data-text="The hourly heatmap with ggplot2" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://johnmackintosh.com/2016-12-01-the-hourly-heatmap/"> HighlandR</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/9McouYV2ji8"></a></div>