I am trying to export rasters from the rasterViz package as jpg or png. I am struggling to:
- completely trim white border
- keep transparency for NAs
So far:
library(raster)
library(rasterVis)
# Toy Data
m <- matrix(seq(0,100,length.out=15000),150,100)
r <- raster(m, xmn=0,ymn=0,xmx=nrow(m),ymx=ncol(m))
jpeg(file = "test.jpg", bg = "transparent", height=nrow(r), width=ncol(r))
levelplot(t(r), contour=T, margin=F, scales = list(draw=FALSE), colorkey=NULL,
par.settings = list(axis.line = list(line=0), mar=c(0,0,0,0), omi=c(0,0,0,0),
xaxt='n', yaxt='n', bg='transparent'))
dev.off()
...still has a white border and transparency isn't working (for the border at least). I'm also a little confused about needing to transpose the raster to plot.
For context; I need to preserve the aspect ratio and exactly trim to the extends so that I can use the images as map tiles elsewhere. It isn't feasible to do manual post processing.