Visualize global temperature change by rWBclimate and rMaps package

The Purpose of report

I want to confirm that …

Anyway, Thanks ropensci(rWBclimate package) and ramnathv(rMaps package)!!!

Install packages

You can install packages to run the codes below:

library(devtools)
install_github("rWBclimate", "ropensci")
install_github('ramnathv/rCharts@dev')
install_github('ramnathv/rMaps')

Needless to say, you need to install devtools also.

Download data with rWBclimate package

You can download data from Climate Data API(World Bank) as the following:

library(rWBclimate)
# Load country name(ISO3C) 
data(maps)
# Combine country names
all.country <- c(
  Africa_country, 
  Asia_country, 
  Eur_country, 
  NoAm_country, 
  Oceana_country, 
  SoAm_country)
# I'm not sure that why UMI's data does not exists.
# But we need to remove this one to avoid some errors.
all.country <- all.country[all.country!="UMI"]
# Get histrorical yearly tem
hist.temp.ac <- get_historical_temp(all.country, "year")
# I recommend you to save the data after download because it's a bit big
#save(hist.temp.ac, file="hist_temp_ac.RData")
# You can load the saved data as the following:  
#load("hist_temp_ac.RData")

Visualize global temperature change data

You can visualize the data you downloaded with rMaps as the following codes:

library(rMaps)
Note: the specification for class "Datamaps" in package 'rMaps' seems equivalent to one from package 'rCharts': not turning on duplicate class definitions for this class.
Note: the specification for class "Leaflet" in package 'rMaps' seems equivalent to one from package 'rCharts': not turning on duplicate class definitions for this class.
# round the temparature data for simplicity
hist.temp.ac$data <- round(hist.temp.ac$data)
# ichoropleth function gives us the way to make an animated choropleths
# Because hist.temp.ac data contains from 1901 to 2009 
# and its little bit too heavy to visualize at one,
# I use the data from 1950 to 2009
map <- ichoropleth(
  data~locator, 
  pal="YlOrRd", 
  data=subset(hist.temp.ac, year>1950),
  map="world", 
  animate="year",
  play=TRUE,
  ncuts=9)
# for RPubs html output
map$show("iframesrc", cdn = TRUE)
# you can just write "map" to visualize in your computer
# control the above plot region
writeLines("<style>iframe.rChart{ width: 100%; height: 600px;}</style>")

Enjoy!! @teramonagi