embedPlot | R Documentation |
Embed a new plot in a relative position of an existing plot region
embedPlot( expr = expression({ plot(1, t = "n", axes = FALSE, xlab = "", ylab = "") text(1, 1, font = 3, labels = "embedPlot error:\nexpression\nnot defined") }), at = c(0.5, 0.95, 0.6, 0.95) )
expr |
expression. Defines a call to a new plot (must contain a high-level call). Use curly brackets to contain multiple line evaluations. Other 'par()' changes should be done outside of the call to 'embedPlot'. |
at |
numeric vector. Four values between 0-1 ('at = c(x0, x1, y0, y1)'), defining the region of the new plot relative to the original plot region. |
An embedded plot in a relative position of the existing plot.
Inspired by Stackoverflow answer by Allan Cameron: (https://stackoverflow.com/a/63114977/1199289)
# error given when expression argument missing image(volcano) embedPlot() # addition of histogram image(volcano) embedPlot( expr = expression(hist(c(volcano), main = "", xlab = "")), at = c(0.6, 0.95, 0.6, 0.95)) # addition of elevation scale image(volcano) embedPlot( expr = expression({ imageScale(volcano, axis.pos = 1) mtext("Elevation [m]", side = 1, line = 2)}), at = c(0.5, 0.95, 0.9, 0.95)) # example mixing log scales, and demo of par changes set.seed(1) x = runif(100, min = 1, max = 1e5) y = runif(100, min = 1, max = 1e5) plot(x, y, log = "xy", xlab = "", ylab = "", col = 2) tmp <- par(ps = 8, no.readonly = TRUE) embedPlot(expression(plot(x, y, xlab = "", ylab = "", cex = 0.5)), at = c(0.1, 0.5, 0.2, 0.5)) par(tmp) embedPlot(expression(plot(x, y, xlab = "", ylab = "", cex = 0.5, log = "xy")), at = c(0.1, 0.5, 0.65, 0.95))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.