File: subplot.s

package info (click to toggle)
hmisc 5.2-4-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,044 kB
  • sloc: asm: 28,905; f90: 590; ansic: 415; xml: 160; fortran: 75; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 793 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
subplot <- function (fun, x, y = NULL, size = c(1, 1), vadj = 0.5,
                     hadj = 0.5, pars = NULL) {
  old.par <- par(no.readonly = TRUE)
  on.exit(par(old.par))
  if (missing(x))
    x <- locator(2)

  xy <- xy.coords(x, y)
  if (length(xy$x) != 2) {
    pin <- par("pin")
    tmp <- cnvrt.coords(xy$x[1], xy$y[1], "usr")$plt
    x <- c(tmp$x - hadj * size[1]/pin[1], tmp$x + (1 - hadj) *
           size[1]/pin[1])
    y <- c(tmp$y - vadj * size[2]/pin[2], tmp$y + (1 - vadj) *
           size[2]/pin[2])
    xy <- cnvrt.coords(x, y, "plt")$fig
  }
  else {
    xy <- cnvrt.coords(xy, , "usr")$fig
  }

  if(length(pars)) par(pars)
  par(plt = c(xy$x, xy$y), new = TRUE)
  if(is.function(fun))fun() else fun
  tmp.par <- par(no.readonly = TRUE)

  return(invisible(tmp.par))
}