## # RClimate Script: RSS_lo_temp_anomaly.R ######### ## Script stored on http://chartsgraphs.wordpress.com account for Users to source() ## ## ## Download and process RSS MSU Satellite Data = TLT Temp Anomaly Trend Land & Ocean ## ## Developed by D Kelly O'Day to demonstrate use of source() function for climate data ## ## http:chartsgraphs.wordpress.com 2/5/10 ## ############################################################################################ ## Get Monthly anomaly data link<- "http://www.remss.com/data/msu/monthly_time_series/RSS_Monthly_MSU_AMSU_Channel_TLT_Anomalies_Land_and_Ocean_v03_2.txt" mo_RSS_in <- read.table(link, skip = 3, sep = "", header = F, as.is = T, colClasses = c(rep("numeric",3), rep("NULL", 8)), comment.char = "#", na.strings = c("*", "-",-99.9, -999.9), col.names = c("yr", "mo", "RSS_lo", rep("",8))) yr_frac <- mo_RSS_in$yr + (mo_RSS_in$mo-1)/12 # yr_frac simplifies calcs ## Create new data frame RSS_df <- data.frame(yr_frac, mo_RSS_in) ## Get last mo, yr and anomaly to highlight last reading c <- nrow(RSS_df) # Find number of data rows lmo <- RSS_df$mo[c] # Fimd last month of data lyr <- RSS_df$yr[c] lyr_frac <- RSS_df$yr_frac[c] # Find last year frac of data lRSS <- RSS_df$RSS_lo[c] # Find last reading ## Calc annual avg; vector must be sorted by date and include full monthly data for each year RSS_ann <- subset(RSS_df, RSS_df$yr >= 1979 & RSS_df$yr <2010) $ set df to fulll years annavg= function(x) apply (array(x,dim=c(12,length(x)/12)),2,mean) a_RSS <- annavg(RSS_ann$RSS_lo) n <- length(a_RSS) # number items sin vector a_RSS[n+1] <- a_RSS[n] # add last yr so that step function will show across last yr a_RSS <- ts(a_RSS, start=1979, freq=1) ## Create RSS plot function pl_func <- function(){ par(mfrow=c(1,1));par(oma=c(3,1,4,1)); par(mar=c(2,4,0,0)); par(ps=10) par(las=1); par(ps = c(9)) ; par(bty="l") plot(yr_frac, RSS_lo, type="l", col ="grey", xlab = "", ylab = expression(paste("RSS Temperature Anomaly - ",degree,"C")), xlim=c(1979, 2012), ylim=c(-0.6, 0.80), xaxs="i", yaxs="i", axes = TRUE, cex.axis = 0.95, cex.lab = 0.95) abline(h=0, col = "grey") points(a_RSS, type = "s", col = "blue") # show annual avg as blue step # Plot annotation n_text <- 0.9 # use to control note font size # Establish plot titles title_3 <- expression(paste("RSS Land & Ocean Temperature Anomalies - ",degree, "C", sep="")) title_2 <- paste("Period: 1/1979 to ",lmo,"/",lyr, sep="") mtext(title_3, side = 3, line = 3, adj = 0.5) mtext(title_2, side = 3, line = 2, adj = 0.5, cex = n_text) mtext( "RSS Version 3.2 - MSU/AMSU TLT", side = 3,line = 1, adj=.5, cex = n_text) # Establish plot notes text(1980, 0.7, " Area: 70S to 82.5N", col = "black", pos =4, cex = n_text) # Highlight last reading points(lyr_frac, lRSS, col="red",pch=16) note <- paste(lmo, "/", lyr, " @ ", lRSS," C", sep="") # add legend legend(2000,-0.2, c("Annual Mean Anomaly", "Monthly Anomaly" ,note), col = c("blue", "grey", "red"), text.col = "black", lty = c(1,1,0),pch=c(0,0,16),pt.cex=c(0,0,1), merge = F, bg = "white", bty="o", cex = .75, box.col="white") # Add margin notes for name and plot date # mtext(link, side = 1, line = 2, adj=0.5, cex=0.8) # link too long to fit on plot mtext("D Kelly O'Day, http://ChartsGraphs.Wordpress.Com", side = 1, line = 3, adj = 0, cex = 0.9) mtext(format(Sys.time(), "%m/%d/ %Y"), side = 1, line = 3, adj = 1, cex = 0.9) } pl_func()