Site icon R-bloggers

NASA GISS’s Annual Global Temperature Anomaly Trends

[This article was first published on Climate Charts & Graphs I » RClimate Script, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

NASA’s Goddard Institute for Space Studies (GISS)  has released their December, 2014 anomaly data, showing that 2014 was the warmest year in the warmest decade in the 1880 – 2014 instrumental temperature record period.

NASA’s results are consistent with the Japanese Meteorological Agency report (here)

 

Here is my R script for those who would like to reproduce my chart.

 

############## RClimate Script: GISS Annual Temperature Anomaly ###########################
##                   http:chartsgraphs.wordpress.com    1/16/15                            ##
############################################################################################
  library(plyr); library(reshape)
 ## File Download and File
  url <- c("http://data.giss.nasa.gov/gistemp/tabledata/GLB.Ts+dSST.txt")
  file <- c("GLB.Ts+dSST.txt")
  download.file(url, file)

## 1st 8 rows and the last 12 rows contain instructions
## Find out the number of rows in the file, and exclude the last 12
    rows <- length(readLines(file)) - 12
## Read file as  char vector, one line per row, Exclude first 8 rows
    lines <- readLines(file, n=rows)[8:rows]
## Data Manipulation, R vector
## Use regexp to replace all the occurences of **** with NA
    lines2 <- gsub("\*{3,5}", " NA", lines, perl=TRUE)
## Convert the character vector to a dataframe
    df <- read.table(
      textConnection(lines2), header=TRUE, colClasses = "character")
    closeAllConnections()
## Select monthly data in first 13 columns
    df <- df[,c(1,14)]
## Convert all variables (columns) to numeric format
    df <- colwise(as.numeric) (df)
    df[,2] <- df[,2]/100
    names(df) <- c("Year", "anom")
## Remove rows where Year=NA from the dataframe
    df <- df [!is.na(df$Year),]
## Find last report month and last value
    GISS_last <- nrow(df)
    GISS_last_yr <- df$Year[GISS_last]
    GISS_last_temp <- df$anom[GISS_last]
## Calc decade averages
  dec_mean<- as.numeric(14)
  dec_st <- as.numeric(14)
  dec_end <- as.numeric(14)
 # yr_n <- as.integer(df$Year)
  base_yr <- 1870
  df$dec_n <-  (as.numeric((df$Year - base_yr) %/% 10) * 10) + base_yr
 # df <- data.frame(df, dec_n)
  for (i in 1:13) {dec_st[i] = base_yr+ i*10
     dec_sub <- subset(df, dec_n == dec_st[i], na.rm=T)
     dec_mean[i] <- mean(dec_sub$anom)
     }
 dec_st[14] <- 2020              # Need to have for last step line across decade
 dec_mean[14] <- dec_mean[13]
 dec<- data.frame(dec_st, dec_mean)
#### Plot function
  plot_func <- function() {
  par(las=1); par(ps=12)
  par(oma=c(2.5,1,1,1)); par(mar=c(2.5,4,2,1))
# specify plot yr min & max
  p_xmin <- 1880;   p_xmax <- GISS_last_yr+10
  title <- paste("GISS Land and Sea Temperature Annual Anomaly Trend n", p_xmin, " to ",
   GISS_last_yr, sep="")
  plot(df[,1], df[,2], type = "l", col = "grey",
     xlim = c(p_xmin, p_xmax), ylab = "Temperature Anomaly - C (1951-1980 Baseline)",
     xlab="", main = title,cex.main = 1,cex.lab=0.8,cex.axis=0.85)
  points(GISS_last_yr, GISS_last_temp, col = "red", pch=19)
  last_pt <- paste( GISS_last_yr, ", ", GISS_last_yr, " @ ", GISS_last_temp, "C",sep="")
  points(dec$dec_st, dec$dec_mean, type="s", col="blue")
## add legend
  legend(1880,0.6, c("Decade Mean Anomaly", "Annual Anomaly" ,GISS_last_temp), 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 = T, bg = "white", bty="o", cex = .75, box.col="white")


Filed under: Citizen Climate Science, Global Warming, RClimate Script Tagged: Climate Trends, R scripts

To leave a comment for the author, please follow the link and comment on their blog: Climate Charts & Graphs I » RClimate Script.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.