get_margin: Get margins for a ggplot2 plot or map based on style or...

View source: R/get_paper.R

get_marginR Documentation

Get margins for a ggplot2 plot or map based on style or distance

Description

This function works in combination with the get_paper() function to make it easier to position a map on a page before saving to file. This is primarily useful when using a map or plot created with ggplot2 as part of a print document format that is composed outside of R using a page layout application such as Adobe InDesign.

Usage

get_margin(
  margin = NULL,
  paper = NULL,
  orientation = NULL,
  dist = NULL,
  unit = "in",
  plot_width = NULL,
  header = 0,
  footer = 0
)

Arguments

margin

Margin style (options include "extrawide", "wide", "standard", "narrow", "none"), Additional "auto" option to generate margin based on line length is planned but not yet implemented. Default: NULL (equivalent to "none").

paper

Paper, Default: 'letter'.

orientation

Orientation "portrait", "landscape", or "square", Default: 'portrait'.

dist

Margin distance (single value used to all sides), Default: NULL

unit

Unit for margin distance, Default: 'in'.

plot_width

Plot or map width in units. If paper and plot_width are provided, margins are half the distance between the two evenly distributed. This sets the margin distance for height as well as width so does not work well with header and footers and should be improved in the future.

header, footer

Header and footer height in units; defaults to 0. Please note: headers and footers are not currently supported for "px" units.

Value

A ggplot2::margin() element intended for use with ggplot2::element_rect() and the plot.background theme element.

See Also

ggplot2::margin()

Examples

get_margin("standard")

get_margin("none")

get_margin(dist = 25, unit = "mm")

get_margin(paper = "letter", plot_width = 5.5)

elipousson/overedge documentation built on Aug. 13, 2022, 7:41 p.m.