Learn R Programming

iplots (version 1.1-8)

iraster: Add a bitmap (raster) image to the current iPlot.

Description

iraster adds a raster image as an iObj to the given iPlot. Position in the plot is specified by bottom-left and top-right points of the image.

Usage

iraster(x1, y1, x2, y2, img, ..., plot = iplot.cur())

Arguments

x1, y1, x2, y2

coordinates of the bottom-left (x1, y1) and top-right (x2, y2) corner. Alternatively, x1 can be a vector of length 4 specifying the four values, or x1 and x2 can be vectors of length 2 specifying one point each

img

image to draw. It can be either a raster, file name, binary connection or a raw vector containing an image in a common image format such as PNG or JPEG. If it is a raster, then the raster is first encoded into PNG format and passed as raw vector.

...

additional arguments that will be passed to iobj.opt if present.

plot

parent plot for the image

Value

Resulting iObject.

Details

The current implementation uses Java's ImageIO API to read the image, so the supported formats will depend on your Java implemetation. Raster objects (i.e., of class "raster", "nativeRaster"), matrices and arrays) are simply passed to png::writePNG(img) so for anything other than computationally constructed objects it is more efficient to use the encoded image.

See Also

iobj.opt

Examples

Run this code
# NOT RUN {
## very silly example ...
iplot(0:20/20, 0:20/20)
## get a sample image (R logo) from the png package
fn <- system.file("img", "Rlogo.png", package="png")
## put this image behind all points
iraster(0, 0, 1, 1, fn, layer=-2)
## you can use a raster but it's less eficient
## this one goes to the top layer where iObjs reside normally
iraster(0, 0, 0.5, 0.5, png::readPNG(fn))
# }

Run the code above in your browser using DataLab