ProcessTrends.Com
Home
Charts - Graphs
Climate Trends
Global Warming
R Resources
LearnR Toolkit
Excel Resources
Google Maps
What's New
  About       Contact
 Search Site RSS

   1/8/2011

 

Using R for Advanced Charts
When you need to build charts beyond Excel's capabilities

New Learn R Toolkit
Complete Slide, Video and R Script Toolkit to Help Excel Users Quickly Learn R

 

Visit my blog: http://chartsgraphs.wordpress.com
Should I Use R R Lattice Beats Excel Stacked Area Trend Charts Anatomy of An R Chart Script Step Chart in R Boxplot with R R Resources
Change Points in Trend Chart R Works with Factors R Panel Chart Beats Excel Panel Chart Dynamic Trend Chart with Slope and Annotation Monthly Trend Chart with Annual Average and :Lowess Smoother Time Series Regression of Global Temperatures, El Nino-La Nina, Volcanoes
Temperature Anomaly Data Displays Getting Familiar w R Video
wmv version
 
Interactive Regression Decadal Trends in Long Term Trend Chart Consolidated Temperature Data RClimate

Should I Use R?               (See comparison of Excel & R Trellis Charts: video)

In pursuing my interests in data visualization, I have found several authors who have really had an impact on my graphical analysis thinking:

Edward Tufte - I first started my data visualization journey when I by read Tufte's Visual Display of Quantitative Information. While comfortable with Tufte's concepts, I found I needed more concrete examples and tools. This lead me to Naomi Robbins's book.

Naomi  Robbins' Creating More Effective Graphs book opened my eyes to a wide array of practical charting techniques not available in Excel. I was particularly interested in dot plots and trellis plots. Robbins' book is where I first learned about the R, S, and S Plus statistical and graphics languages.  Her chart examples and discussion lead me to William Cleveland's and Paul Murrell's books.

William Cleveland' s Elements of Graphing Data and  Visualizing Data books showed me that I was just scratching the surface of graphical analysis with default Excel charts. In addition to trellis displays, Cleveland's books showed me important concepts like banking to 45o and locally weighted  regression (Lowess). 

Paul Murrrell's R Graphics  showed me the power of the R graphics package.

As I read Robbins, Cleveland and Murrell's books, I saw a number of data analysis and charting capabilities that I wanted to add to my repertoire:

While trying to make these advanced Excel based charts,  I often asked myself the question "...should I use R for this chart instead of  Excel". Based on Robbins' book, I knew that these charts were readily available in R.

Reluctant to take on the R learning curve, I developed several of the advanced charts in Excel and VBA. I knew it was taking more time than it would to use a high quality statistical analysis and graphing package. I felt that it was better to use a tool that I knew and avoid the learning curve of a package like R.

I made good progress building dot plots, box plots and banking to 45o tools in Excel. Trellis charts  and Lowess smoothing proved a real challenge in Excel. Trellis charts allow the user to show multivariate data much more effectively than Excel's default charts. I looked into R again  and considered using R for my trellis charting needs. Rather than switch to R at that time, I started developing horizontal and vertical panel charts in Excel, wanting to be able to automate the development of a full trellis chart.

I searched high and low for a reasonable Lowess algorithm that I could incorporate into Excel. No luck.

I finally developed a set of VBA procedures to build a full trellis chart.  When I completed the Excel - VBA trellis chart, I reconsidered R because I now know what it will take for me to develop the trellis advanced charting that was already available in R.

Why reinvent trellis charts in Excel when they were readily available in R?  To answer this question, I needed to find out how difficult the R learning curve was, I already knew what it takes to develop these tools in Excel - VBA.

Trellis Chart in Excel and R

This video shows my Excel VBA trellis chart tool as well as the results of my 2 day R learning curve.

Based on my Excel - VBA trellis chart development time versus R trellis chart learning curve time, I will be using R for graphics that is not part of Excel's standard tools kit. I'd rather use a proven tool by a R programmer than reinvent my own graphic wheel in Excel.

I have a long way to go in mastering data analysis and time series analysis. I'd rather spend my time learning and using analysis  techniques rather than coaxing Excel to do what R can already do.

R Resources

Type Description Link
Software Comprehensive R Archival Network (CRAN)

CRAN

Tutorials
CRAN Kickstarting R

Kickstarting R

Illinois State University: Dong-Yun Kim

ISU

UCLA Resources for R

UCLA

Kansas University: Paul Johnson

RTips

Videos Decision Science News: Dan Goldstein

Video 1
Video 2

Excel & R Using R Within Excel  

(top)

R Lattice Beats Excel's Stacked Area Trend Chart

See Charts & Graphs blog for my post on why R lattice plots are much more effective than Excel's stacked area trend charts.

Here's the link to the source data file.

Here's the R script I used.

### Script to work with BP Oil's Oil Consumption - M Barrels/day Data
# D Kelly O'Day - Oct. 3, 2008; http://processtrends.com & http://chartsgraphs.wordpress.com
library(lattice)
my_ar <- c(1) # User changeable aspect ratio
# *** Please edit for correct path to your source data file
my_data <- read.table("c:/R_home/CG/oil_cons_trend.csv", sep =",", header=TRUE)
# *****
tp1 <- xyplot(Value ~ Year |Parameter, data = my_data, type = "l",
main="World Oil Consumption Trends - million barrels per day \n 1965 to 2007 ",
sub = "Data Source: BP Statistical Review of World Energy 2008",
xlab="",
ylab="Million barrels per day",
par.settings=list(axis.text=list(cex=0.8), fontsize=list(text=10)),
par.strip.text=list(cex=0.8))
update(tp1, aspect = my_ar)

(top)

Anatomy of an R Chart Script

See Charts & Graphs blog for my post on my walkthrough of an R script..

Here's the link to the R script file..

(top)

Making a Step Chart with R

See Charts & Graphs blog for my post on how to make a step chart with R.

Here are the links to R script file and data file.

(top)

Making a Boxplot with R

See my Charts & Graphs blog post on how to make a boxplot with R.

Here are the links to the R script and data file for boxplots.

(top)

 
Showing Change Points in a Trend Chart with R

See my Charts & Graphs blog post on how to add change points to a trend chart.

Here are the links to the R script, ENSO and GISS temp data files for the trend chart with change points..

If you try the script, be sure to change the source data file path to the actual folder where you saved the data files.

(top)

R Works With Factors

See my Charts & Graphs blog post on how R handles categorical variables and hte power of factors in data analysis and plotting.

Here are the links to the R script  and Enso_GISS temp data file for the trend chart with change points..

If you try the script, be sure to change the source data file path to the actual folder where you saved the data files.

(top)

 

Monthly Trend Chart with Annual Averages and Lowess Smoother Fit

This R script shows the long term global land and sea temperature trends,  showing  monthly and annual anomalies, long term trend (lowess fit [(f = 0.15]) as well as the 2001-2008 trend. I prepared this chart using R. 

 

See my Charts & Graphs post here.

The R script file is here.

(top)

Dynamic Trend Chart with Trend Line and Annotation

R script to automatically generate a trend chart from web based global temperature data.  The R script allows me to update my plot each month as soon as the source file is updated. The plot is self documenting so that the chart reader can see the data period,  the overall trend line, slope for trend line; the last data point is highlighted and value given. Date stamp and name are included in the margin.

See my Chart & Graphs post here.

R Script file link.

 

(top)

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 say that it would be very difficult and messy to produce a comparable chart in Excel.  The example R chart uses panel chart, step chart, error bar and dynamic capabilities not inherently available in Excel. No helper series are needed and the chart can easily be regenerated each month as new data is available.

See my Chart & Graphs post here.

Data file is here.

R script file is here.

 

 

(top)

Time Series Regression of Global Temperature, El Nino - La Nina and Volcanic Events

In a previous post, I showed how to make a 3 panel chart displaying RSS temperature anomalies,  El Nino- La Nina (NINO34 index) and volcanic event (SATO Index) time series data.  While time series charts can give a visual impression of how time series are related, time series regression provides much more information, including leading - lagging relationships between the time series.

In this post, I analyze the RSS, NINO34 and SATO time series using a simple trend line and a multiple regression model with lag periods for the independent variables. The post demonstrates some of  R 's regression analysis and data lagging capabilities. Links to the R script and data files are provided.

See my Chart & Graphs post here.

Data file is here.

R script file is here.

(top)

Interactive Regression with rpanel Package

Hadley Wickham's Crantastic site currently lists 1,531 R packages.  This post shows how I used the is rpanel  package to build an interactive regression tool.  This is similar to the interactive regression tool I built in Excel.  

Excel users often add check boxes, drop down lists to add some interactive capabilities to worksheets. rpanel provides the same type of capability in the R environment. 

rpanel has been developed by Adrian Bowman, et al at the University of Glasgow, Department of Statistics. They have several excellent support documents and scripts at this link

The script and source data file are available at these links.

  script              data

(top)

Temperature Anomaly Data Displays

Is there a single "best" way to display temperature anomaly data? The answer is obvious - NO! The best display depends on what we are trying to show.  Statistical charts compare one variable with one or more other variables.

Since our display option affects how we interpret the data, it is important to be clear on what we are comparing. In this post I want to show 3 ways to display temperature anomaly data and the implications that the display method has on our interpretation of the data. I'll use a map, a trend chart and a dot plot.

See my Chart & Graphs post here.

 

 

 

top)

 

 

 

 

 

 

 

 


Decadal Trend Rate in Long Term Trend Chart

See my Charts & Graphs blog post here

R script here
Consolidated Temperature Data

Global Climate Trends

There are many blogs and web sites (small sample: 1, 2, 3, 4, 5, 6) with multiple opinions on global climate trends. Some sites are data oriented and others are opinion oriented. What is a charter to think?

My advice, take a look at the data for yourself. As an Excel or R charter, why not analyze it yourself to get a better appreciation for what is going on.

To help you get started, I've developed a consolidated monthly CSV file that presents  the 5 major global land and ocean temperature anomaly data series: GISS, NOAA, HADCrut3, RSS and UAH.

Google Spreadsheet

Here's the link to my Google spreadsheet of the monthly data. I've  tried to simply download and consolidate the raw data as provided by the source sites. My goal has been to present the data in a simple CSV format so that Excel and R charters could evaluate the trends without having to struggle through the  re-formatting process.

R Script

The source files are a little messy from a charting standpoint, each needs its own reformat procedure. I've posted my R script at this link.



(top)