R Panel Chart Beats Excel Panel Chart

In this post, I show how to make a 3 variable time series panel chart in R. As an Excel panel chart pioneer, I can tell you that it is very difficult and messy to produce this type of panel chart in Excel. The example R panel chart uses R’s a step chart format for one plot and R’s vertical line format for the other 2 plots. Several of R’s dynamic capabilities, not inherently available in Excel, are also used. No helper series are needed and the chart can easily be regenerated each month as new data is available.

Here’s The R Panel Chart

First, let’s take a look at the chart to see what’s so good about R charting.

Panel Charts

I started making Excel panel charts in May, 2006. Since then, I worked to improve my techniques and began to automate panel charts. Finally, I was able to make automated lattice charts in Excel-VBA. When I compared the effort needed to make the Excel-VBA code for lattice plots versus using R’s readily available lattice plot capabilities, I realized how much more powerful R was for doing the types of charts I wanted to make. Why try to reinvent the wheel in Excel when R can do it better, faster, easier?

In this video I discuss trellis – lattice plots, my automated Excel – VBA trellis plot and my R version of the same trellis plot and why it is so much easier to produce panel charts with R.

Since my Excel – VBA versus R experiment, I have used R for all of my panel – lattice – trellis charts.

In this current panel chart example, I chart 3 time series. Since Excel doesn’t have a convenient panel chart capability, some users would be tempted to place the 3 series on the same plot, possibly using 2 Y axis scales or rescaling each series. Rather than compromise the data visualization quality of the chart, I recommend using R for multivariate time series.

Each series is plotted in its own panel with appropriate Y axis scale suited to the data range for the variable. I have used R’s step chart format for the monthly RSS temperature data series and R’s thin vertical line format for the monthly NINO34 and SATO Index data series. The NINO34 data is color coded so that values > 0 are red and value < 0 are blue.

The panels are annotated to assist the reader in interpreting the data. The RSS temperature and NINO34 series highlight the last data points and provide the actual values to give the reader the most up-to-date information. The SATO Index panel explains the volcano – Sato Index relationship and points out previous major eruptions.

The 2nd line of the title is dynamically generated to indicate the update month. Likewise, the lower right footer is dynamically generated to reflect print data for the chart.

R Script

The R script is shown below. I have extensively commented my code to make it easier for me to reuse it for other charts. The script file is here and the data file is here.

I also have spent considerable time in Excel to create readable graphics when using this Lattice package in R is clearly better and also easier. I also find it strange that Excel does not have these Trellis-chart type capabilities, since this is such a common and useful tool. Especially Office 2007 with the improved graphics in Excel. Anyway, THANK YOU for the R code here, amazing!

You could make things much easier on yourself if you used xyplot in lattice or if you used ggplot2. Unlike another commenter, I have used both ggplot2 and lattice and I much prefer lattice. (by the way, I’m doubtful this commenter really has used lattice if he didn’t notice that you weren’t actually using it above).