Skip to content

Instantly share code, notes, and snippets.

@Jianghao
Created November 5, 2014 10:36
Show Gist options
  • Save Jianghao/7f1fbc9b58586867fa22 to your computer and use it in GitHub Desktop.
Save Jianghao/7f1fbc9b58586867fa22 to your computer and use it in GitHub Desktop.
Visualize worldclim.org data
# title : 01-Visualize.R
# purpose : Visualize worldclim.org data
# reference : rasterVis package help page
# producer : Prepared by Jianghao Wang
# address : In IGSNRR, CAS, China
# ----------------------------------------------------------
library(plyr)
library(rasterVis)
library(rgdal)
# change the work directory first
# setwd("/wps/home/wangjh/project/worldclim.org/arc-min-5/")
list <- dir(getwd(), recursive = T, pattern = (".tif$"))
name <- ldply(strsplit(list, ".tif"), "[", 1)[,1]
output <- paste0(name, ".png")
for (i in 1:length(list)){
cat("--->", i, "/", length(list), output[i], "\n")
r <- raster(readGDAL(list[i]))
mapTheme <- rasterTheme(region = rev(brewer.pal(9, "RdBu")))
plt <- levelplot(r, margin = F, par.settings = mapTheme,
# set the maxpixels corresponding to output file size, the default if 1e5
# acr-min-5 = 1800 * 4320
maxpixels=7776000,
main=name[i],
panel = function(...) {
panel.fill(col = "grey")
panel.levelplot(...)
},
xlim = c(-180, 180), ylim = c(-90, 90),
xscale.components=xscale.raster.subticks,
yscale.components=yscale.raster.subticks,
cut = 50, colorkey=list(space='right'))
png(output[i], width = 4320, height = 2000, res = 300)
print(plt)
dev.off()
}
### End of script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment