Update of `ggseas` for seasonal decomposition on the fly
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
What’s new
A new version (0.5.1) of my ggseas
R package is now available on CRAN. ggseas
is a small package that provides several tools to make it easier to do seasonal adjustment or decomposition of time series on the fly in a ggplot2
pipeline. New in this version:
- A
facet.titles
argument to the decomposition graphic functionggsdc
- Addition of a vignette and other small documentation improvements
ggsdc
now supports tibbles- Fixed some minor bugs, such as how the ordering of factor levels is preserved
Installation
Installation is the usual way:
Example usage
One of the two main areas of functionality is the ability to easily do seasonal decomposition into seasonal, trend and random components in an exploratory workflow. Here’s an example, applied to the mean rent by territorial authority data published by New Zealand Ministry of Business, Innovation and Employment (disclaimer – I work there, but not on rental data).
The aim is to produce this graphic, comparing mean rents in two selected cities:
Auckland is New Zealand’s largest city, on the north island. Dunedin is on the south island and has a high proportion of students which, even before we look at the data, we might expect to impact on the rental market. In this graphic we see that the seasonal effect in Dunedin is in fact stronger than in Auckland; actually, there is virtually no seasonality in Auckland rents at all. In Dunedin, rents for leases that start in the most expensive time are around $60 or more a week more than in the cheapest. The decomposition in this graphic is done with X13-SEATS-ARIMA, which ggseas::ggsdc
calls via the excellent seasonal
R package.
Here’s the code
As another view of the data, I use the same approach to show classical multiplicative decomposition. This isn’t the best way to treat seasonal data, particularly economic data where the seasonality can be expected to change over time, but it is the simplest and can form a useful reality check on the more sophisticated algorithms used in X13-SEATS-ARIMA.
This approach forces the seasonality to be the same over the whole life of the series. Note that the “seasonality” facet is now showing multipliers, not additions.
Which months are cheaper?
That last graphic makes it clearer that Dunedin’s rents vary in a regular pattern, but it’s difficult to see exaclty read the axis in enough detail to see which months are low and high. To understand this we need a monthplot:
…or a monthplot of the detrended series:
These graphics show that the months that have the lowest rents lodged are actually in the middle of the year – June and July.
The last two graphics were made with the benefit of stl
and monthplot
from the standard stats
package, not related to ggseas
at all:
More
There’s more to ggseas
than these decomposition plots. It also offers indexing, rolling average, and seasonal adjustment “stats” that integrate into the standard ggplot
graphic production line. Check out the new vignette. Any bugs or feature requests please post as issues on GitHub.
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.