Viewing

Example 002




setwd("/Users/rockel/work/R/examples/example002")

#
# plot 1 figure on one page
#
#... Example for Precipitation with GPCC color bar
gpcchpcolours<-c("#FFFF82","#F0F000","#82FF82","#00FF00","#00C800","#009600","#00A0FF","#0064FF","#0000FF","#8C1EDC","#A000A0","#BE0082","#BE005A","#BE0000")
levels_gpcc<-c(0.,1.,10.,25.,50.,75.,100.,150.,200.,300.,400.,600.,800.,10000.)
ncfile<-"TOT_PREC.nc"
pdffile<-"exp002.pdf"
title<-"CCLM monthly precipitation"
col<-gpcchpcolours
levels<-levels_gpcc
varname<-"TOT_PREC"
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,2),2,1, byrow=T), height=c(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,2),2,1, byrow=T), height=c(1,lcm(2.5)),respect=T)
}
par(mar=c(0.5,0.8,0.5,0.8))
tmp <- plotmap(file=ncfile, varname=varname,col=col,rivers=F,cities=F,sponge=0,grid.txt=T,levels=levels, hires=F,map.lwd=1,interior=T)
par(mai=c(0.5,0.5,0.35,0.5))
plot_colourbar(tmp,triangle_ends=c(FALSE,TRUE))
mtext(title, 3, line=-2,outer=T, font=1, cex=1.4)
dev.off()
 Viewing