| subplot | R Documentation |
Embed a subplot in an existing plot at specified coordinates.
subplot(
expr,
x,
y = NULL,
log = NULL,
size = c(1, 1),
vadj = 0.5,
hadj = 0.5,
inset = c(0, 0),
type = c("plt", "fig"),
pars = NULL
)
expr |
an expression defining the plot to be embedded |
x, y |
coordinates of the new plot given by a keyword (see details)
or values accepted by |
log |
character, |
size |
the size of the plot in inches if |
vadj |
vertical adjustment of the plot when |
hadj |
horizontal adjustment of the plot when |
inset |
1 or 2 numbers representing the proportion of the plot to
inset the subplot from edges when |
type |
character string of |
pars |
a list of parameters to be passed to |
The coordinates for expr may be given by a keyword passed to
x (similar to legend). x will be grepped for
"right", "left", "top", and/or "bottom", and the coordinates for
expr will be automatically calculated; see examples.
If x and y are numeric and length 1, these will be used as
the center of the plotting region; if length 2, these will be used as the
minimum and maximum coordinates of the plotting region (similarly if
x is missing and the user is prompted by locator to
give the coordinates interactively).
The list of graphical parameters used when drawing expr, useful for
adding an additional subplot after subplot has finished.
TeachingDemos::subplot; http://sickel.net/blogg/?p=688;
inset
plot(1)
subplot(plot(density(rnorm(100)), ann = FALSE), 1.2, 1.2)
subplot(plot(density(rnorm(100)), ann = FALSE, axes = FALSE), 'bottomright')
## Not run:
## augment a map
library('maptools')
data(state.vbm)
plot(state.vbm, fg = NULL)
tmp <- cbind(state.vbm$center_x, state.vbm$center_y)
for (i in 1:50) {
tmp2 <- as.matrix(USArrests[i, c(1, 4)])
tmp3 <- max(USArrests[, c(1, 4)])
subplot({
barplot(matrix(tmp2), ylim = c(0, tmp3), yaxt = 'n', col = 1:2,
beside = TRUE, border = 1:2)
}, x = tmp[i, 1], y = tmp[i, 2], size = c(.1, .1))
}
legend('bottomright', legend = colnames(USArrests)[c(1, 4)], fill = 1:2)
## End(Not run)
set.seed(1)
tmp <- rnorm(25)
qqnorm(tmp)
qqline(tmp)
pars <- subplot(hist(tmp, ann = FALSE), 0, -1)
## wrong way to add a reference line to histogram
abline(v = 0, col = 2, lwd = 2)
## right way to add a reference line to histogram
op <- par(no.readonly = TRUE)
par(pars)
abline(v = 0, col = 3, lwd = 2)
par(op)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.