Xts cheat sheet. Seasonal decomposition in the ggplot2 universe with ggseas. The ggseas package for R, which provides convenient treatment of seasonal time series in the ggplot2 universe, was first released by me in February 2016 and since then has been enhanced several ways.

The latest version, 0.4.0, is now on CRAN. The improvements since I last blogged about ggseas include: added the convenience function tsdf() to convert a time series or multiple time series object easily into a data frame added stats for rolling functions (most likely to be rolling sums or averages of some sort) stats no longer need to be told the frequency and start date if the variable mapped to the x axis is numeric, but can deduce it from the data (thanks Christophe Sax for the idea and starting the code) series can be converted to an index (eg starting point = 100) added ggplot seasonal decomposition into trend, seasonal and irregular components, including for multiple series at once (thanks Paul Hendricks for the enhancement request) Installation can be done from CRAN:

Range Selector. You can add range selector to the bottom of a dygraph that provides a straightforward interface for panning and zooming.

For example: dygraph(nhtemp, main = "New Haven Temperatures") %>% dyRangeSelector() You can also specify an initial date range for the range selector: dygraph(nhtemp, main = "New Haven Temperatures") %>% dyRangeSelector(dateWindow = c("1920-01-01", "1960-01-01")) Twitter's R package for detecting breakouts in time series. With so many more devices and instruments connected to the "Internet of Things" these days, there's a whole lot more time series data available to analyze.

But time series are typically quite noisy: how do you distinguish a short-term tick up or down from a true change in the underlying signal? To solve this problem, Twitter created the BreakoutDetection package for R, which decomposes a time series into a series of segments of one of three types: Bfast breakpoints. #analyze breakpoints with the R package bfast #please read the paper #Verbesselt J, Hyndman R, Newnham G, Culvenor D (2010)

The Baseline. The left lane on the freeway, commonly known as the fast lane, is sometimes mistaken as the slowest lane on the planet.

It's especially weird when there aren't many cars on the road, and you're driving in the fast lane only to find yourself slowed down by the person in front of you who moves at 60% of the speed limit. The decent thing to do is for the slow person to switch to the right lane so that you can pass. But instead, he carries on with his slowness, so after a mile or two, you switch lanes to pass. You speed up, and then all of a sudden he speeds way up, only to make you the slow one. R Financial Time Series Plotting. As with all of R, the ability to easily chart financial time series is the result of an iterative progression driven by the collaboration of an extremely dedicated group of open source volunteers.

With the release of rCharts, I thought it would be interesting to document the timeline of this progression. For each step in the timeline, I will include a link to the source code (svn or github) of the package and a minimal example to demo the "out-of-the-box" capability. Displaying time series, spatial and space-time data with R: stories of space and time. This is the accompanying website of the book "Displaying time series, spatial and space-time data with R" to be published with Chapman&Hall/CRC.

This book will provide methods to display time series, spatial and space-time data using R. The code of each method will be detailed and commented through practical examples with real data. This website publishes the code and main graphics of each chapter. More on Horizon Charts. #look at steps in constructing a horizon plot version #of #do horizon of percent above or below 10 month / 200 day moving average require(lattice) require(latticeExtra)

Apple Compared to Others with ggthemes. Require(ggplot2) #to get ggthemes from jrnold github if you have not installed #require(devtools) #install_github("ggthemes","jrnold") require(ggthemes)

Generating polygon boundaries for plotting simple time series data with missing data. December 19, 2012 Tags: plotting, polygon, R-project Every so often I want to plot some data with pretty upper and lower error bounds, such as temperature data through time, perhaps with the maximum and minimum temperature range or standard error bounds for averaged data.

The polygon( ) function can make those sorts of pretty plots. However, I’ll often have chunks of missing data for periods of time, so I have to break up the polygons that go with the plotted data. I could swear I wrote a function to do this several months ago, but it’s lost in a pile of other scripts, so I re-wrote a function to accomplish the task.

Quantmod: examples. If there was one area of R that was a bit lacking, it was the ability to visualize financial data with standard financial charting tools. By virtue of no other package implementing this, quantmod took up the call and took a shot at providing a solution. What started with a single OHLC charting solution has grown into a highly configurable and dynamic charting facility as of version 0.3-4, with more coolness slated for 0.4-0 and beyond. For now, let's take a look at what its currently in place: Financial Charts in quantmod: Most of the charting functionality is designed to be used interactively. Let's get charting! Introducing chartSeries chartSeries is the main function doing all the work in quantmod. By default any series that is.OHLC is charted as an OHLC series.

The default choice ['auto'] lets the software decide, candles where they'd be visible clearly, matchsticks if many points are being charted, and lines if the series isn't of an OHLC nature. Ryan Peek on using xts and ggplot for time-series data. At Davis R Users’ Group today, Ryan Peek gave a presentation on how he takes data from his field instruments and visualizes it in R. Here are his notes. The original *.Rmd file and data can be found here XTS is a very helpful package when working with time series data. I work with temperature and flow data frequently, so the ability to work with timeseries, and particularly to shift intervals (from 15 min to hourly or daily) can be very handy. Once data has been re-worked, ggplot2 is a great package to plot data of all types. Shading and Points with xtsExtra plot.xts. Visualize multivariate time series – R is my friend.

A few days ago a colleague came to me for advice on the interpretation of some data. The dataset was large and included measurements for twenty-six species at several site-year-plot combinations. A substantial amount of effort had clearly been made to ensure every species at every site over several years was documented. I don’t pretend to hide my excitement of handling large, messy datasets, so I offered to lend a hand. We briefly discussed a few options and came to the conclusion that simple was better, at least in an exploratory sense. Even More JGB Yield Charts with R lattice. See the last post for all the details. I just could not help creating a couple more. Variations on Favorite Plot - Time Series Line of JGB Yields by Maturity p2 <- xyplot(value ~ date | indexname, data = jgb.melt, type = "l", layout = c(length(unique(jgb.melt$indexname)), 1), panel = function(x, y, ...) { panel.abline(h = c(min(y), max(y))) panel.xyplot(x = x, y = y, ...) panel.text(x = x[length(x)/2], y = max(y), labels = levels(jgb.melt$indexname)[panel.number()], cex = 0.7, pos = 3) }, scales = list(x = list(tck = c(1, 0), alternating = 1), y = list(tck = c(1, 0), lwd = c(0, 1))), strip = FALSE, par.settings = list(axis.line = list(col = 0)), xlab = NULL, ylab = "Yield", main = "JGB Yields by Maturity Since Jan 2012")p2 <- p2 + layer(panel.abline(h = pretty(jgb.melt$value), lty = 3))p2 p4 <- xyplot(value ~ date | indexname, data = jgb.diff.melt, type = "h")