Would you like to be able to generate a GISS temperature anomaly trend chart on your PC with just 1 line of R script? What about downloading the R script to your PC so that you can edit the script to fit your needs?
In this post I present my first RClimate Script so that users with just a little R experience who have R and 2 R libraries up and running on their PC can retrieve the latest NASA file on monthly GISS temperature anomalies, generate a trend chart and calculate the anomaly trend rate in 1-2 minutes.
Getting Climate Data in Users Hands
There are many high quality on-line climate data files like NASA’s GISS file, however, file formats are often difficult to work with, users may need to merge multiple files to get the proper data coverage and the date time intervals may need to be aggregated from daily to monthly or annual averages. Trying to download, manipulate, adjust, average and merge large data files with tools like Excel can be downright difficult.
Many climate observers who read posts on Open Mind, Blackboard, Climate Observations would like to make additional iterations of the original, however, in many cases this is just to time consuming. If we give the readers access to the post data set and analysis, the readers can then reproduce /adjust the charts/analysis as they see fit.
My goal is to make it easy for interested climate observers to get their hands on the actual climate data behind climate trend posts. I hope to make it really easy for R beginners to reproduce my climate charts and data analysis.
My First RClimate Script
Here’s a trend chart of NASA’s GISS Land and Sea Temperature Anomaly for the period 1880-2009 which includes a trend line for the period 1990 – 2009.
Let’s take a quick look at the source data file (link) to see the raw data behind the chart.
I wrote an R script program, giss_mo_anom_r.doc, to generate this trend chart from the NASA file. Here’s what it does:
- Downloads and reads the on-line NASA data
- Converts values to degrees C (divide by 100)
- Converts the 18 column per year array to a 1 column per year-month time series
- Subset the full data set and generates a liner regression for a user specified time period, 1990-2009 in our example.
- Generates trend chart with trend line and trend rate
A user with R and 2 libraries (plyr, reshape) installed on his/her PC and an internet connection can copy/paste the following 1 line of R script into an R Console and automatically generate this chart.
source() lets you run an existing R script, in this case it is stored on my WordPress account. Experienced R users will notice that the R script file type is doc not the traditional R. I had to use the doc type because WordPress’ security features would not accept an R file type.
This single line of R script reads my GISS R script program on my WordPress account, runs it on your PC and generate the chart.
Pretty easy! You can find out more about R’s source capabilities by typing ?source on your R console.
How Can I Change the Trend Period?
I used the 1990 to most recent month to calculate the trend line and rate. You have another idea, you’d like to look at the 2000 – to present or some other period!
To do this, you need 3 lines of R script so that you can download and save the R script on to your R working directory , use file.edit() to bring it into your R editor so that you can edit it to your heart’s content.
link <- "https://chartsgraphs.files.wordpress.com/2010/01/giss_mo_anom_r.doc" download.file(link, "GISS_mo_anom.R") file.edit("GISS_mo_anom.R")
To change the trend line period, look for r_xmin and r_xmax in the script and set them to whatever values you want. Once you have finished editing the script, save it and rerun it to try out your new chart.
If you like your revised version of my R script, you can save it to rerun next month and get the latest NASA GISS update with your trendline settings without doing anything extra. Any NASA adjustments to their historic data set will be included because my R script program reads the most current version of NASA’s file.
So try my 3 line script. Let me know what you come up with.