(This article was first published on MarginTale, and kindly contributed to R-bloggers)
How do you easily get beautiful calendar heatmaps of time series in ggplot2? E.g:![]() |
| From MarginTale |
How do you attack the problem? Looking at the example output above:
- We facet_grid by "months" and "years"
- The data itself is plotted by "week of month" and "day of week" and coloured according to the value of interest
So, given a time series we just have to fiddle with time indexes to create a data.frame containing the time series as well as per observation the corresponding "month", "year", "week of month", "day of week". The rest is then a one-liner of code with Hadley's wonderful ggplot2 system.
The following code contains step by step comments:
The following code contains step by step comments:
It should be easy to wrap into a function and I hope its useful.
To leave a comment for the author, please follow the link and comment on his blog: MarginTale.
R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series,ecdf, trading) and more...


Zero Inflated Models and Generalized Linear Mixed Models with R.
Zuur, Saveliev, Ieno (2012).