Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lattice full plot area

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

like image 744
Geo-sp Avatar asked Sep 18 '15 17:09

Geo-sp


People also ask

What is a lattice in R?

Lattice is a powerful and elegant high-level data visualization system for R, inspired by Trellis graphics. It is designed with an emphasis on multivariate data, and in particular allows easy conditioning to produce "small multiple" plots.

What is Xyplot R?

The xyplot() function of the lattice package allows to build a scatterplot for several categories automatically. Scatter section Data to Viz. The lattice library offers the xyplot() function. It builds a scatterplot for each levels of a factor automatically.

Which of this is limitation of lattice plots?

Sometimes awkward to specify an entire plot in a single function call. Annotation in plot is not intuitive. Use of panel functions and subscripts difficult to wield and requires intense preparation. Cannot “add” to the plot once it's created.

What function creates a scatter plot in lattice package?

The xyplot() function can be used to create a scatter plot in R using the lattice package.


1 Answers

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).

like image 55
jbaums Avatar answered Dec 15 '22 03:12

jbaums