[R-sig-Geo] where does that additional outer margin comes from when using sp::image or sp::spplot on SpatialPixelsDataFRame data?

Frede Aakmann Tøgersen frtog at vestas.com
Thu Apr 10 15:31:49 CEST 2014


Hi

First, thank you for a great package.

I can't figure out where this additional outer margin comes from. The following script illustrates it. To download my data use the DropBox link.


library(sp)

## Here is a link to my data on my DropBox account
dropBoxFile <- "https://www.dropbox.com/s/9853s5pempoapzf/xyz.R"

## source(dropBoxFile)
## or if for security reasons then you're more secure to download through web browser
## inspect data before you source it ;-)

myBreaks <- seq(2,11.5, by = 0.5)
mycols1 <- c("#FFFFFF", "#D5D5D5", "#AAAAAA", "#808080", "#000080", "#0080BF",
             "#00FFFF", "#004000", "#009F00", "#00FF00", "#FF8000", "#FFBF00",
             "#FFFF00", "#800000", "#BF0000", "#FF0000", "#800080", "#BF40BF",
             "#FF80FF")

## Removing plot margins works for meuse.grid data set

data(meuse.grid)
meuse <- SpatialPixelsDataFrame(points = meuse.grid[c("x", "y")], data = meuse.grid)

dims <- meuse at grid@cells.dim

## on Windows
windows(width = dims[1], height = dims[2])

## on linux
## X11(width = 78, height = 104)

## first with plot margins
image(meuse[3], bg = "grey80")

## use all plot area for plot
par('plt')

par(mar=rep(0,4))

par('plt')

image(meuse[3], bg = "grey80")

## For my data a sort of margin is produced using sp plotting functions

dims <- xyz at grid@cells.dim
windows(width = dims[1], height = dims[2])
par('plt')

### there is both a white and grey "margin"
image(xyz, col = mycols1, bg = "grey80", aspect = "iso")

## can get rid of white margin
## but not the grey
par(mar=c(0,0,0,0))#, pty = "m")
par('plt')

## still a gray "margin"
image(xyz[1], col = mycols1, breaks = myBreaks, bg = "grey80", aspect = "iso")

## Also this is not working
spplot(xyz[1], at = myBreaks, col.regions = mycols1, aspect = "iso")

## same class of data
str(meuse)
str(xyz)


## I can get this to work
x <- unique(xyz$x)
y <- unique(xyz$y)
z <- xyz$z
dim(z) <- c(length(x), length(y))

image.default(x, y, z, breaks = myBreaks, col = mycols1, bg = "grey80")

Thank you for your help.


Yours sincerely / Med venlig hilsen
data

Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 



More information about the R-sig-Geo mailing list