Skip to content

6. Visualization and animation

Rasmus E. Benestad edited this page Oct 15, 2020 · 4 revisions

Basic visualization

Standard plots for esd-objects

The main data visualization is provided through plot and map methods, however, there are additional more sophisticated methods for producing additional graphs. For esd-objects such as station, field, eof, pca, and ds the standard visualization uses S3-type functions (for a station-object x, the command plot(x) uses plot.station(x)). E.g.:

plot(x,...)

and

map(x,FUN,...)

In the latter example, when the argument 'FUN' is not null, map(x,FUN) produces a colored map returning the values obtained by applying the function 'FUN' on 'x'. For instance, if 'FUN' is the standard deviation, typing 'map(x,FUN='sd')' will produce a map of standard deviations for each location. This applies also for other esd objects such field.

Example 1

To load daily precipitation data recorded at bjornholt type

data(bjornholt) ; x <- bjornholt

To plot the time series, type

plot(x)

To produce a map centered on the location, type

map(x,xlim=c(lon(x)-10,lon(x)+10),cex=2,add.text=T,full.names=T)

Example 2

To produce a map of mean values at weather stations from the NACD dataset, type

> X <- station(src='NACD',param='t2m')

> map(X,FUN='mean',add.text=T,xlim=c(-20,40),ylim=c(40,90))

Other types of graphics

  • diagnose gives an overview of station records and where there is valid data or quality of various post-processed results.
  • vis shows a data matrix for a single station where x-axis is the day in the year and y-axis each year.
  • graph provides an alternative way of presenting downscaled results from a multi-model ensemble.
  • wheel shows a wheel where the angle represents the day of the year and colours the year for precipitation and temperature.
  • balls produces fancy symbols
  • climvar shows the seasonal variations in e.g. year-to-year variance on a daily basis.
  • corfield shows correlation maps
  • cumugram shows the accumulated mean or sum for the given year compared to previous years.
  • scatter.hexbin
  • scatter.sunflower
  • windrose plots windroses for one station wind data
  • vec draws arrows, e.g. on top of a contour-plot.

Using the esd-package as an engine in Shiny apps

The website OpenClimateDataPrototype is test site for an R-Shiny app that presents daily climate data from a network of stations. The code for app is avialable from GitHub.

Using esd to make animations.

To create animations we need to invoke packages such as animate. E.g.

library(esd)
library(animation)

## Make a map of SSTs and with wind arrows superimposed
  frame <- function(x1,x2,x3,it) {
    cat('.')
    par(bg='black',col.axis='white',col.lab='white',col.main='white')
    y1 <- subset(x1,it=it)
    y2 <- subset(x2,it=it)
    y3 <- subset(x3,it=it)
    map(y1,projection='sphere',main=paste(month.abb[month(y1)],year(y1)),lonR=-140,style='night',
        colbar=list(breaks=seq(-5,35,by=1)),new=FALSE)
    vec(y2,y3,projection='sphere',lonR=120,r=1.1,a=0.7,length=0.03,nx=70,ny=70,new=FALSE)
  }

print('Get data')
sst <- retrieve('~/data/ERA5/ERA5_sst_mon.nc',it=c(2015,2018))
u10 <- retrieve('~/data/ERA5/ERA5_u+v_mon.nc',param='u10',it=c(2015,2018))
v10 <- retrieve('~/data/ERA5/ERA5_u+v_mon.nc',param='v10',it=c(2015,2018))
n <- length(index(sst))
print(n)

print('GIF:')
saveGIF({for (i in 1:n) frame(sst,u10,v10,i)},
        movie.name="elninoanim.gif",interval=0.5)

See the results here