Example 004
setwd("/Users/rockel/work/R/examples/example004")
##
## plot 12 months on one page
##
# t2m difference model-obs in K
delta_t2m<-c("#3F007D","#1D00BB","#0000EC","#064774","#0EA50D","#69CE6C","#FFFFFF","#FFFFFF","#FFFF75","#FFFF0D","#FFD000","#FFA100","#FF5000","#FF1000")
levels_t2m=c(-100., -6., -5., -4., -3., -2., -1., 0., 1., 2., 3., 4., 5., 6., 100.)
ncfile<-"T_2M_diff_cclm-eobs_1980-1984_mm_ym.nc"
pdffile<-"exp004.pdf"
title<-"CCLM - ECAD 1981-1985 Monthly Mean"
col<-delta_t2m
levels<-levels_t2m
varname<-"T_2M"
nc <- nc_open(ncfile)
#ratio <- length(nc$dim$lat$vals) / length(nc$dim$lon$vals) # geographical
ratio <- length(nc$dim$rlat$vals) / length(nc$dim$rlon$vals) # rotated
nc_close(nc)
# decide whether landscape or portrait looks prettier
if (ratio > 1.) {
pdf(pdffile, width=8.27,height=11.69,paper="special")
par(oma=c(3,2,5,2))
layout(matrix(c(1:12,13,13,13),5,3, byrow=T), height=c(1,1,1,1,lcm(2.5)),respect=T)
} else {
pdf(pdffile, width=11.69,height=8.27,paper="special")
par(oma=c(3,2,5,2))
layout(matrix(c(1:12,13,13,13,13),4,4, byrow=T), height=c(1,1,1,lcm(2.5)),respect=T)
}
par(mar=c(0.5,0.5,0.5,0.5))
labels=c("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC")
#labels=c("Winter","Spring","Summer","Autumn") # use adj=0.2 in the legend function below
for (i in 1:12) {
tmp <- plotmap(file=ncfile, varname=varname,col=col,na.col="gray",rivers=F,cities=F,sponge=0,i.time=i,grid.txt=F,levels=levels, hires=F,map.lwd=1,interior=T)
legend("topleft",labels[i], bg="white", adj=0.5) # white box, black outline
#legend("topleft",labels[i], bg="white", box.col="white",adj=0.5) # white box
#legend("topleft",labels[i], adj=0.5) # black outline
#legend("topleft",labels[i], adj=0.5, bty="n") # just the text
}
par(mai=c(0.5,1.5,0.35,1.5))
plot_colourbar(tmp,triangle_ends=c(TRUE,TRUE))
mtext(title, 3, line=1,outer=T, font=1, cex=1.3)
dev.off()