I have been using R to maintain a rather large stack of raster layers (over 700 layers of data for sub-Saharan Africa). Each layer looks as follows http://hcapi.harvestchoice.org/v2.0/core/?varCode=SALUM&format=tif
I need to batch generate PNG images for print media, as well as thumbnails of the layers.
Using R raster package, I can easily plot each layer and apply custom color tables and legends. I run into problems when trying to generate small thumbnails with no title and axis (see an example below). I cannot find any option to have the raster plot occupy the full size of the graphic device, regardless of any graphic parameter I pass to par().
Here is reproducible code:
library(rgdal)
library(raster)
url <- "http://hcapi.harvestchoice.org/v2.0/core/?varCode=SALUM&format=tif"
download.file(url, "./r.zip", "curl")
unzip("r.zip")
r <- raster("./SALUMSSAtif.tif")
cc <- c("#AFF1E9", "#9ddfa3", "#87CD58", "#CDAF19", "#761200", "#94725F", "#D61F00")
png("./SALUMSSAtif.png", width=200, height=200)
par(mar=c(0,0,0,0), oma=c(0,0,0,0), xaxs="i", yaxs="i")
plot(r, col=cc, main=NULL, legend=F, axes=F)
dev.off()
This produces the attached plot that's badly off-center and too small. Any idea how to remove all the plot margins using raster::plot or another method?
Thanks, --Mel.