Templates for the position and background of a ggplot inset.

inset_position(type = "default", size = 0.2, margin = 0.025)

inset_background(type = "default")

inset_templates(type)

## Arguments

type character, name of template. numeric, width (length-1) or width and height (length-2) of inset. See details. numeric, x-axis margin (length-1) or x- and y-axis margins (length-2) around corner insets. See details.

## Value

a list of arguments passed to either inset_pos or inset_bg in meme.

## Details

inset_position and inset_background assist with some basic options for position and background of the optional ggplot inset graphic. inset_templates can be used to view the available templates. See examples. If a template is not available to suit your needs, provide your own argument list to meme in the form of, e.g., inset_pos = list(w = 0.95, h = 0.6, x = 0.5, y = 0.325).

## Size and position

The coordinate system for the meme plot ranges from zero to one in x and y. The width, height and (x,y) center defined by inset_position arguments therefore take values between zero and one.

The default position is for an inset plot that takes up 95% of the width and 60% of the height of the meme plot, with 2.5% margins on the sides and bottom. Other templates include four corner thumbnails. To use these, set type equal to "tl", "tr", "br" or "bl", for top right, top left, bottom right and bottom left, respectively. There is also a "center" type.

When specifying the corner or center inset types, the inset is a square thumbnail with width and height of 0.2 units (20%) and 0.025 (2.5%) margins from the edges of the plot. However, these templates are not absolute. You can further adjust the size and distance from the edges using size and margin. These arguments can be scalar, in which case the inset remains square and the margins are equal. If a length-2 vector, size can provide unique width and height for a rectangular inset. Similarly, margin can provide different margins for the distance to a side vs. the top or bottom edge of the meme plot.

For type = "center", size is used but margin is ignored, giving you control over the thumbnail size. Appending the letter q to a corner thumbnail template ID, e.g. type = "blq", yields a quadrant plot. In contrast to type = "center", these types allow for user control over margins for plots of fixed coverage area. Specifying the right combination of size and margin with a corner thumbnail template can be used to create a quadrant plot, but using a quadrant template simplifies this.

size and margin are provided for convenience, adding more control over the position templates. If you require more specific size and position control, simply pass your own 4-argument list as described above. This is the structure generated by inset_position for any type and expected by meme.

## Background

For inset_background, the few templates all revolve around the type = "default" template. type = "sq" simply removes the rounded corners. "op" provides a fully opaque white background instead of the default 50% transparency. "opsq" does both. "blank" hides the background panel. There is no substantial need to provide many templates because, as with inset_position, inset_background generates a simple list of a few arguments that can be easily provided to meme explicitly without the use of inset_background.

## Examples

inset_templates("position")
#>  [1] "default" "tl"      "tr"      "br"      "bl"      "tlq"     "trq"
#>  [8] "brq"     "blq"     "center" inset_templates("background")
#> [1] "default" "op"      "sq"      "opsq"    "blank"  inset_position()
#> $w #> [1] 0.95 #> #>$h
#> [1] 0.6
#>
#> $x #> [1] 0.5 #> #>$y
#> [1] 0.325
#> inset_position("br")
#> $w #> [1] 0.2 #> #>$h
#> [1] 0.2
#>
#> $x #> [1] 0.875 #> #>$y
#> [1] 0.125
#> inset_position("brq", margin = 0.05)
#> $w #> [1] 0.4 #> #>$h
#> [1] 0.4
#>
#> $x #> [1] 0.75 #> #>$y
#> [1] 0.25
#> inset_position("br", size = 0.4, margin = 0)
#> $w #> [1] 0.4 #> #>$h
#> [1] 0.4
#>
#> $x #> [1] 0.8 #> #>$y
#> [1] 0.2
#> inset_background()
#> $fill #> [1] "#FFFFFF50" #> #>$col
#> [1] NA
#>
#> $r #> [1] 0.025snpc #> inset_background("opsq") #>$fill
#> [1] "#FFFFFF"
#>
#> $col #> [1] NA #> #>$r
#> [1] 0snpc
#> inset_background("blank")
#> $fill #> [1] NA #> #>$col
#> [1] NA
#>
#> \$r
#> [1] 0snpc
#>