Add a Plot to an Existing Plot

DESCRIPTION:
Adds a plot, of any kind, to the current plot. The location and size may be specified; otherwise, you will be prompted to input the location and/or size.

USAGE:
subplot(fun, x, y, size=c(1, 1), vadj=.5, hadj=.5, pars=NULL)

REQUIRED ARGUMENTS:
fun:
plotting function call. This may use any S-PLUS plot function other than brush or spin. Desired graphical parameters, such as cex or col, should be included inside the plot function arguments.

OPTIONAL ARGUMENTS:
x,y:
location of the plot region for fun, in user coordinates (see the usr graphical parameter). If x and y are of length 1, they (along with vadj and hadj) determine the location of the new plot. If x and y are vectors of length 2, they specify opposite corners of the plot region. A list containing x and y values may be supplied instead (as x). If x is missing, a call to locator is made to determine the placement.
size:
vector containing the width and height of the plot region for fun, in inches. If size and x are both missing, you are required to enter two points on the existing plot (with locator) to specify the opposite corners of the plot region.
vadj,hadj:
vertical and horizontal justification of the subplot region. 0 means bottom or right, .5 means center, 1 means left or top. This is only applicable if opposite corners of the plot region were not specified.
pars:
parameters that give information on the location and size for the subplot. This is typically the value from a previous call to subplot, and is used to add to that previous subplot.

VALUE:
an invisible vector of graphical parameters (ala par) that were in effect for the subplot.

SIDE EFFECTS:
a plot of the specified size at the given location is added to the current plot.

DETAILS:
The size specified includes the plot region only; the tick marks and axis labels are outside of this region. When used in multiple figure plots, the coordinates refer to the current plot within the figure.

The returned value can be used to add to the subplot.


BUGS:
If you request it to draw outside the figure region, subplot gets very confused and typically puts the subplot across the whole region.

SEE ALSO:
symbols , locator , par .

EXAMPLES:
usa(xlim=c(-76.3, -65), ylim=c(39.2, 47.6))
subpars <- subplot(usa()) # locator is used to place the new plot
subplot(box(), pars=subpars) # puts box around the small usa map
subplot(box()) # use locator to box the enlarged area
text(locator(1), "Enlarged Region")

year <- as.integer(dimnames(votes.repub)[[2]]) southwest <- match(c("California", "Nevada", "Utah", "New Mexico", "Arizona", "Colorado"), state.name) fun <- expression({ plot(year, votes.repub[s,], xlab="", ylab="", main="", type="l", cex=.5, xlim=c(1900, 1980), ylim=c(0, 100)) abline(h=50) }) rx <- c(101, 125); ry <- c(30.5, 42.5) usa(xlim=rx, ylim=ry) for (s in southwest) subplot(x=state.center$x[s], y=state.center$y[s], size=c(1.0,.6), fun=fun) title(main="Republican Votes in the Southwest")