Call rasterImage to plot image from (xleft,
ybottom) to either xright or ytop, shrinking one
toward the center to avoid distortion.
angle specifies a rotation around the midpoint
((xleft+xright)/2, (ybottom+ytop)/2). This is
different from rasterImage, which rotates
around (xleft, ybottom).
NOTE: The code may change in the future. The visual
image with rotation looks a little off in the examples
below, but the code seems correct. If you find an example
where this is obviously off, please report to the
maintainer – especially if you find a fix for this.
a raster object, or an object that can be coerced to one by
as.raster.
xleft
a vector (or scalar) of left x positions.
ybottom
a vector (or scalar) of bottom y positions.
xright
a vector (or scalar) of right x positions.
ytop
a vector (or scalar) of top y positions.
angle
angle of rotation in degrees, anti-clockwise about the centroid
of image.
NOTE: rasterImage rotates around
(xleft, ybottom). rasterImage
rotates around the center ((xleft+xright)/2,
(ybottom+ytop)/2). See the examples.
interpolate
a logical vector (or scalar) indicating whether to apply linear
interpolation to the image when drawing.
xsub, ysub
subscripts to subset image
...
graphical parameters (see par).
Details
1. imagePixels = number of (x, y) pixels in image. Do this
using dim(as.raster(image))[2:1], because the first dimension of
image can be either x or y depending on class(image).
For example link[EBImage]{Image} returns dim with x
first then y and an optional third dimension for color. A simple
3-dimensional array is assumed by rasterImage to have
the y dimension first. as.raster puts all these in a
standard format with y first, then x.
2. imageUnits <- c(x=xright-xleft, ytop-ybottom)
3. xyinches = (x, y) units per inch in the current plot, obtained
from xyinch.
4. Compute pixel density (pixels per inch) in both x and y
dimension: pixelsPerInch <- imagePixels * xyinches / imageUnits.
5. Compute imageUnitsAdj solving 4 for imageUnits and replacing
pixelsPerInch by the max pixel density: imageUnitsAdj <- imagePixels
* xyinches / max(pixelsPerInch).
6. (dX, dY) = imageUnitsAdj/2 = half of the (width, height)
in plotting units.
a named vector giving the values of xleft,
ybottom, xright, and ytop
passed to rasterImage.
(rasterImage returns NULL,
at least for some inputs.) This shows the adjustment,
shrinking toward the center and rotating as desired.