implot {imager} | R Documentation |
Plot objects on image using base graphics
Description
This function lets you use an image as a canvas for base graphics, meaning you can use R functions like "text" and "points" to plot things on an image. The function takes as argument an image and an expression, executes the expression with the image as canvas, and outputs the result as an image (of the same size).
Usage
implot(im, expr, ...)
Arguments
im |
an image (class cimg) |
expr |
an expression (graphics code to execute) |
... |
passed on to plot.cimg, to control the initial rendering of the image (for example the colorscale) |
Value
an image
Author(s)
Simon Barthelme
See Also
plot, capture.plot
Examples
## Not run:
b.new <- implot(boats,text(150,50,"Boats!!!",cex=3))
plot(b.new)
#Draw a line on a white background
bg <- imfill(150,150,val=1)
implot(bg,lines(c(50,50),c(50,100),col="red",lwd=4))%>%plot
#You can change the rendering of the initial image
im <- grayscale(boats)
draw.fun <- function() text(150,50,"Boats!!!",cex=3)
out <- implot(im,draw.fun(),colorscale=function(v) rgb(0,v,v),rescale=FALSE)
plot(out)
## End(Not run)
[Package imager version 1.0.2 Index]