Remove white space from levelplot plotting Google map

918 views Asked by At

I'm trying to get rid of some white space produced by levelplot in the rasterVis package. I'm using the dismo package to get a Google map, then using levelplot to plot it. However, there is a thin strip of white around the map. How do I remove that white space?

library(dismo)
library(rasterVis)

g_map = gmap(extent(c(-79,-58,36,50)),type="satellite",zoom=7,lonlat=TRUE,scale=1)


g_map_lv = levelplot(g_map,maxpixel=ncell(g_map),col.regions=g_map@legend@colortable,at=0:255,panel=panel.levelplot.raster,interpolate=TRUE,colorkey=FALSE,margin=FALSE,scales="sliced")

enter image description here

1

There are 1 answers

0
Oscar Perpiñán On BEST ANSWER

The outer rows and columns of the g_map object are NA. For example:

g_map[1,1]

You can remove them with trim before plotting:

g_map <- trim(g_map)