Lattice full plot area
Asked Answered
J

1

7

I want to delete R's default margin around the lattice plot. This means that I want to get rid of all the white spaces beyond the red rectangular. Here is the example:

library (raster)
library(rasterVis)

f <- system.file("external/test.grd", package="raster")
r <- raster(f)
levelplot(r, margin=T)

enter image description here

Justinajustine answered 18/9, 2015 at 17:3 Comment(0)
H
7

You can adjust the margins with the layout.heights and layout.widths arguments to lattice.options:

lattice.options(
  layout.heights=list(bottom.padding=list(x=0), top.padding=list(x=0)),
  layout.widths=list(left.padding=list(x=0), right.padding=list(x=0))
)
levelplot(r, margin=TRUE)

enter image description here

Select the image above (e.g. by clicking to the right of it and dragging left) to verify that the margins are as expected.

However, white space will still fill the horizontal extent of the graphics device, so you need to either adjust the xlim so that the white space is within the plot rather than outside it, or just adjust the width of the device appropriately. I did the latter, which might take a bit of trial and error if plotting to a file, but which is straightforward if plotting to an x11/windows/quartz device (just resize the pane).

Hildegardhildegarde answered 18/9, 2015 at 22:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.