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)
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.
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.
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.
The xyplot() function can be used to create a scatter plot in R using the lattice package.
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)
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With