Learn R Programming

imager (version 0.42.19)

implot: 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, ...)

Value

an image

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)

Author

Simon Barthelme

See Also

plot, capture.plot

Examples

Run this code
if (FALSE) {
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)
}

Run the code above in your browser using DataLab