# NOT RUN {
# see Volcano example at help(image)
# create image object:
myimg <- list(image=volcano-min(volcano), col=terrain.colors(max(volcano)-min(volcano)))
# create emoty plot window:
emptyPlot(1,1, main='Volcano images')
# add image topleft corner:
plot_image(img=myimg, xrange=c(0,.25), yrange=c(.75,1), add=TRUE)
# add transparent image as overlay:
myimg$col <- alpha(myimg$col, f=.25)
plot_image(img=myimg, add=TRUE, fill.plotregion=TRUE, bty='n')
# add image:
myimg$col <- topo.colors(max(myimg$image))
plot_image(img=myimg, xrange=c(0.125,.375), yrange=c(.5,.875), add=TRUE)
# add some points and lines:
points(runif(10,0,1), runif(10,0,1), type='o')
# keep ratio:
emptyPlot(1,1, main='Volcano images')
# I would like to add an image in the following field:
rect(xleft=0, xright=.5, ybottom=0, ytop=.3, col='gray', border=NA)
# add image with keep.ratio=true
plot_image(img=myimg, xrange=c(0,.5), yrange=c(0,.3),
add=TRUE, keep.ratio=TRUE, border=NA)
# as y-side is longest, this side will be fitted in
# the rectangle and the x position adjusted with adj:
plot_image(img=myimg, xrange=c(0,.5), yrange=c(0,.3),
add=TRUE, keep.ratio=TRUE, border=2, adj=0.5)
plot_image(img=myimg, xrange=c(0,.5), yrange=c(0,.3),
add=TRUE, keep.ratio=TRUE, border=3, adj=1)
# keep.ratio and border:
plot_image(img=myimg, xrange=c(0,1), yrange=c(0,1),
keep.ratio=TRUE, adj=0.5)
plot_image(img=myimg, xrange=c(0,.5), yrange=c(0,1),
keep.ratio=TRUE, adj=0.5)
emptyPlot(1,1, axes=FALSE)
plot_image(img=myimg, xrange=c(0,1), yrange=c(0,1),
add=TRUE, keep.ratio=TRUE, adj=0.5)
# }
Run the code above in your browser using DataLab