Learn R Programming

inlmisc (version 0.4.3)

GetInsetLocation: Determine Location for Inset Graphics

Description

This function determines the location that may be used to position an inset graphics in the main plot region.

Usage

GetInsetLocation(dx, dy, loc = "bottomright", inset = 0, pad = 0,
  padin = 0)

Arguments

dx, dy

'numeric'. Width and height of the inset graphics, respectively.

loc

'character'. Single keyword used to specify the position of the inset in the main plot region: "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right", or "center" to denote inset location.

inset

'numeric'. Vector of length 2 giving the inset distance from the margins as a fraction of the main plot region. Value is recycled as necessary.

pad

'numeric'. Vector of length 2 giving the padding distance from the margins in user coordinate units. Value is recycled as necessary.

padin

'numeric'. Vector of length 2 giving the padding distance from the margins in inches. Value is recycled as necessary.

Value

Returns a 'numeric' vector of length 2 giving the user coordinates for the bottom-left corner of the inset.

Examples

Run this code
# NOT RUN {
graphics::plot(NA, NA, xlim = c(0, 100), ylim = c(0, 1),
               xlab = "x", ylab = "y", xaxs = "i", yaxs = "i")
dx <- 20; dy <- 0.2
xy <- GetInsetLocation(dx, dy, loc = "bottomleft")
graphics::rect(xy[1], xy[2], xy[1] + dx, xy[2] + dy, border = "red")
graphics::points(xy[1], xy[2], pch = 16, xpd = TRUE)
print(xy)

xy <- GetInsetLocation(dx, dy, loc = "bottomleft", inset = 0.05)
graphics::rect(xy[1], xy[2], xy[1] + dx, xy[2] + dy, border = "pink")
graphics::points(xy[1], xy[2], pch = 16)
print(xy)

xy <- GetInsetLocation(dx, dy, loc = "topright", padin = 0.5)
graphics::rect(xy[1], xy[2], xy[1] + dx, xy[2] + dy, border = "blue")

xy <- GetInsetLocation(dx, dy, loc = "left", pad = c(5, 0))
graphics::rect(xy[1], xy[2], xy[1] + dx, xy[2] + dy, border = "green")

xy <- GetInsetLocation(dx, dy, loc = "center")
graphics::rect(xy[1], xy[2], xy[1] + dx, xy[2] + dy, border = "brown")

# }

Run the code above in your browser using DataLab