Site icon R-bloggers

The hourly heatmap with ggplot2

[This article was first published on HighlandR, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
a quick follow up to my last post –

I’ve had a few folk get in touch following my last post, all commenting on the last plot :

Most of these enquiries went along the following lines:

“I hadn’t thought of doing that. It looks really easy. But how do you do it?”

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. Back home now though, and the code is now uploaded as a gist to GitHub :

HeatmapHrbyDay.R

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.

Some comments :

    p <-ggplot(df,aes(day,hour,fill=temp))+  
    geom_tile(color= "white",size=0.1) +  
    scale_fill_viridis(name=" Hrly Temps C",option ="C")  
    p <-p + facet_grid(year~month)  

If you type ‘p’ in the console at this point you will see the plot. The rest of the code is formatting tweaks. For more heatmap awesomeness, check out Bob Rudis’s blog:
Bob Rudis faceted heatmaps

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.

To leave a comment for the author, please follow the link and comment on their blog: HighlandR.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.