Title: | Sizing Plots and Files for Paper |
---|---|
Description: | A set of convenience functions extending grid, ggplot2, and patchwork to help you size plots and files for printing to paper, postcards, playing cards, and other physical media. |
Authors: | Eli Pousson [aut, cre, cph] |
Maintainer: | Eli Pousson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1 |
Built: | 2024-11-08 03:12:27 UTC |
Source: | https://github.com/elipousson/papersize |
A vector of supported area units derived from dist_units
and
units::valid_udunits()
.
area_unit_options
area_unit_options
A character vector with 41 names, plural names, and aliases for area units.
Convert a character vector with an aspect ratio to a numeric aspect ratio or get the aspect ratio for a given page that has an aspect ratio column.
as_asp( asp = NULL, page = NULL, orientation = NULL, flipped = FALSE, sep = ":", cols = c("width", "height"), ... )
as_asp( asp = NULL, page = NULL, orientation = NULL, flipped = FALSE, sep = ":", cols = c("width", "height"), ... )
asp |
Aspect ratio of width to height as a numeric value (e.g. 0.33) or
characters separated by a colon (e.g. "1:3"). If numeric, |
page |
If character, page is passed as the name parameter to
|
orientation |
Page orientation, Default: |
flipped |
If |
sep |
Separator character to use if asp is a character vector. Defaults to ":". |
cols |
Length 2 character vector with column names for page dimensions. Defaults to c("width", "height"). |
... |
Arguments passed on to
|
A numeric vector.
as_asp(8.5 / 11) as_asp("11:17") as_asp("3/2", sep = "/") as_asp(page = "letter") as_asp(page = "letter", orientation = "landscape") as_asp(page = "letter", orientation = "portrait", flipped = TRUE) as_asp(page = make_page_size(8.5, 11, "in"), flipped = TRUE)
as_asp(8.5 / 11) as_asp("11:17") as_asp("3/2", sep = "/") as_asp(page = "letter") as_asp(page = "letter", orientation = "landscape") as_asp(page = "letter", orientation = "portrait", flipped = TRUE) as_asp(page = make_page_size(8.5, 11, "in"), flipped = TRUE)
Coerce a character or named vector to a page data.frame using get_page_size() or make_page_size()
as_page(x, ..., cols = c("width", "height"), class = "data.frame")
as_page(x, ..., cols = c("width", "height"), class = "data.frame")
x |
A character vector passed to the name parameter of
|
... |
Arguments passed on to
|
cols |
Column names to use for width and height columns. Defaults to c("width", "height"). Must be length 2 and the first value is always used as as the width name and the second as the height. |
class |
Class of return object: "data.frame" (default) or "list" (only supported when input page size is a single row). |
A data.frame or list object with one or more page dimensions.
as_page(c(8.5, 11), units = "in") as_page("letter") as_page( list(name = "letter", w = 8.5, h = 11, units = "in"), cols = c("w", "h") )
as_page(c(8.5, 11), units = "in") as_page("letter") as_page( list(name = "letter", w = 8.5, h = 11, units = "in"), cols = c("w", "h") )
as_unit()
: Convert to a unit (allowing unit objects as units)
as_unit_type()
: Convert to unit type (or checking unit types)
convert_unit_type()
: Convert x from one unit type to another (preserving
names for named vectors)
is_unit_type()
: Is x a character vector with a unit type supported by the
grid package or a unit object with a supported type?
is_same_unit_type()
: Are x and y the same unit type?
Note, when as_unit_type()
is used on a margin object, it returns the unique
unit type as a length 1 character vector not a length 4 character vector as
you could expect with other length 4 input objects.
as_unit( x, units = NULL, data = NULL, recurse = FALSE, arg = caller_arg(x), call = parent.frame() ) as_unit_type( x, recurse = FALSE, data = NULL, valid_units = NULL, arg = caller_arg(x), call = parent.frame() ) convert_unit_type( x, from = NULL, to = NULL, typeFrom = "dimension", valueOnly = FALSE, ... ) is_unit_type(x, ...) is_same_unit_type(x, y, recurse = FALSE, data = NULL, valid_units = NULL)
as_unit( x, units = NULL, data = NULL, recurse = FALSE, arg = caller_arg(x), call = parent.frame() ) as_unit_type( x, recurse = FALSE, data = NULL, valid_units = NULL, arg = caller_arg(x), call = parent.frame() ) convert_unit_type( x, from = NULL, to = NULL, typeFrom = "dimension", valueOnly = FALSE, ... ) is_unit_type(x, ...) is_same_unit_type(x, y, recurse = FALSE, data = NULL, valid_units = NULL)
x |
A numeric vector. For |
units |
A character vector specifying the units for the corresponding numeric values. |
data |
This argument is used to supply extra information
for special |
recurse |
Whether to recurse into complex units. |
arg |
Passed to |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
valid_units |
Character vector with name or symbols for valid units.
Defaults to |
from |
Unit to convert from. If |
to |
Unit to convert to. Passed to unitTo parameter of
|
typeFrom |
Passed to typeFrom parameter of |
valueOnly |
Passed to valueOnly parameter of |
... |
Arguments passed on to
|
y |
Object to compare to x. |
A unit
class object, a character vector with a unit type, or a
logical vector.
inch <- as_unit(1, "in") inch as_unit(10, inch) as_unit(inch, "cm") as_unit(inch) convert_unit_type(inch, to = "cm") convert_unit_type(c(10, 100), from = "mm", to = "cm") is_unit_type("inch") is_unit_type("inchs") is_same_unit_type(inch, "in") is_same_unit_type("pt", "points")
inch <- as_unit(1, "in") inch as_unit(10, inch) as_unit(inch, "cm") as_unit(inch) convert_unit_type(inch, to = "cm") convert_unit_type(c(10, 100), from = "mm", to = "cm") is_unit_type("inch") is_unit_type("inchs") is_same_unit_type(inch, "in") is_same_unit_type("pt", "points")
Reference table of common playing card sizes for get_card()
. Data is a
subset of paper_sizes
which is also included with {sfext}
package.
card_sizes
card_sizes
A data frame with 5 rows and 6 variables:
name
Name of card
units
Units ("in" or "mm") for dimensions
width
Width in units
height
Height in units
orientation
Portrait (width less than height), landscape, or square
This function converts scale distances to actual units based on named standard_scales.
convert_dist_scale( dist = NULL, scale = NULL, standard = NULL, series = NULL, scale_unit = "in", scale_factor = NULL, actual_unit = NULL, dpi = 120, paper = NULL, orientation = NULL, ... )
convert_dist_scale( dist = NULL, scale = NULL, standard = NULL, series = NULL, scale_unit = "in", scale_factor = NULL, actual_unit = NULL, dpi = 120, paper = NULL, orientation = NULL, ... )
dist |
distance to convert. If paper is provided, dist is optional and paper width and height are used as dist. |
scale |
Scale name from |
standard |
Scale standard. Options include "USGS", "Engineering", or "Architectural". |
series |
Map series from |
scale_unit |
"mm" (converted to cm by dividing by 10), "cm", "px" (converted to inches by dividing by dpi), or "in". |
scale_factor |
factor for converting from scale_unit to actual_unit,
e.g. if 1" = 1', the scale factor is 12. optional if scale if provided;
defaults to |
actual_unit |
any unit supported by |
dpi |
dots per square inch (used as conversion factor for "px" to "in") |
paper |
Name of paper passed to |
orientation |
Page orientation, Default: |
... |
Arguments passed on to
|
If paper is not provided, return a vector of dist values converted from scale_unit to actual_unit based on scale_factor or information from standard_scales data.
If paper is provided, return a data.frame with converted distances appends as columns named actual_width and actual_height.
Other dist:
convert_dist_units()
,
is_dist_units()
Convert distance (and area) values between different units
convert_dist_units( dist, from = NULL, to = "meter", drop = FALSE, digits = NULL )
convert_dist_units( dist, from = NULL, to = "meter", drop = FALSE, digits = NULL )
dist |
Numeric or units object |
from |
Existing unit for dist, Default: |
to |
Unit to convert distance to, Default: 'meter' |
drop |
If |
digits |
Number of digits to include in result; defaults to |
Object created by units::set_units()
Other dist:
convert_dist_scale()
,
is_dist_units()
convert_dist_units(1, from = "mile", to = "km") convert_dist_units(3, from = "ft", to = "yard") mile <- units::set_units(1, "mi") convert_dist_units(mile, to = "feet") is_same_units(mile, "mile")
convert_dist_units(1, from = "mile", to = "km") convert_dist_units(3, from = "ft", to = "yard") mile <- units::set_units(1, "mi") convert_dist_units(mile, to = "feet") is_same_units(mile, "mile")
A vector of supported distance units pulled from dist_units
.
dist_unit_options
dist_unit_options
A character vector with 86 names, plural names, aliases, and symbols for distance units.
A subset of units supported by the units package accessible through the
units::valid_udunits()
function.
dist_units
dist_units
A data frame with 33 rows and 12 variables:
symbol
symbols
symbol_aliases
symbol aliases
name_singular
singular names
name_singular_aliases
singular name aliases
name_plural
character plural names
name_plural_aliases
plural name aliases
def
short definition
definition
definition
comment
comment
dimensionless
logical indicator for dimensionless units
source_xml
source XML
unit_opts
character vector with symbols, singular, and plural names for the unit
get_page_size()
filters paper_sizes
by one or more variables with option to
reorient page dimensions or convert page units.
get_paper()
is equivalent to get_page_size()
without the option to set
units, type, or reorient parameters.
get_card()
is equivalent to get_paper()
with type = "card"
and the
string "card" attached to the end of any provided name value supporting both
"Poker card" and "Poker" as a valid name.
get_page_dims()
returns the width and height of a single page.
convert_page_units()
uses convert_unit_type()
to convert the unit used
for page dimensions.
get_page_size( name = NULL, width = NULL, height = NULL, orientation = NULL, reorient = TRUE, units = NULL, type = NULL, ignore.case = TRUE ) get_paper(name = NULL, width = NULL, height = NULL, orientation = NULL) get_card(name = NULL, width = NULL, height = NULL, orientation = NULL) get_page_dims( page = NULL, width = NULL, height = NULL, orientation = NULL, cols = c("width", "height"), arg = caller_arg(page), call = parent.frame(), ... ) convert_page_units( page, units = NULL, valueOnly = TRUE, cols = c("width", "height"), ... )
get_page_size( name = NULL, width = NULL, height = NULL, orientation = NULL, reorient = TRUE, units = NULL, type = NULL, ignore.case = TRUE ) get_paper(name = NULL, width = NULL, height = NULL, orientation = NULL) get_card(name = NULL, width = NULL, height = NULL, orientation = NULL) get_page_dims( page = NULL, width = NULL, height = NULL, orientation = NULL, cols = c("width", "height"), arg = caller_arg(page), call = parent.frame(), ... ) convert_page_units( page, units = NULL, valueOnly = TRUE, cols = c("width", "height"), ... )
name |
Page name, e.g. "letter", not case sensitive, Default: |
width |
Page width in "in", "px" or "mm" units. Default: |
height |
Page height in "in", "px" or "mm" units. Default: |
orientation |
Page orientation, Default: |
reorient |
If |
units |
Units to convert page dimensions to using |
type |
Page type, Options include "paper", "social", "postcard",
"print", "card", or "screen". Default: |
ignore.case |
If |
page |
Used by |
cols |
Length 2 character vector with column names for page dimensions. Defaults to c("width", "height"). |
arg , call
|
Passed to |
... |
Additional parameters passed by |
valueOnly |
Passed to valueOnly parameter of |
A data.frame with page, paper, or card name and dimensions.
get_paper("letter") get_paper("letter", orientation = "landscape") get_page_size(orientation = "square", reorient = FALSE) get_page_size("ledger", units = "cm") get_card("Tarot") get_page_dims(get_paper("letter")) convert_page_units(get_paper("letter"), units = "cm")
get_paper("letter") get_paper("letter", orientation = "landscape") get_page_size(orientation = "square", reorient = FALSE) get_page_size("ledger", units = "cm") get_card("Tarot") get_page_dims(get_paper("letter")) convert_page_units(get_paper("letter"), units = "cm")
This function returns a scale from standard_scales based on a provided name, standard, and/or series.
get_scale(scale = NULL, standard = NULL, series = NULL)
get_scale(scale = NULL, standard = NULL, series = NULL)
scale |
Scale name from |
standard |
Scale standard. Options include "USGS", "Engineering", or "Architectural". |
series |
Map series from |
A tibble based on standard_scales with rows filtered to values that match parameters.
See paper_sizes[paper_sizes$type == "social",]$name
for support image
options.
get_social_size( name = NULL, platform = NULL, format = NULL, orientation = NULL )
get_social_size( name = NULL, platform = NULL, format = NULL, orientation = NULL )
name |
Image size name, Default: |
platform |
Social media platform, "Instagram", "Facebook", or "Twitter",
Default: |
format |
Image format, "post", "story", or "cover", Default: |
orientation |
Image orientation, Default: |
get_social_size("Instagram post") get_social_size(platform = "Twitter") get_social_size(format = "cover")
get_social_size("Instagram post") get_social_size(platform = "Twitter") get_social_size(format = "cover")
Save a plot or map then update the EXIF metadata for the title, author, and
create data. ggsave_ext()
also supports creating a file name based on a
sentence case name with spaces (e.g. "Baltimore city map") and appending a
label (e.g. "baltcity") as a prefix to the output file name.
map_ggsave_ext()
can take a list of {ggplot2} plots (e.g. a list of plot
generated by purrr::map()
) and create multiple files using the same
parameters or use the {gridExtras} package to create a single combined PDF
file.
ggsave_ext( plot = ggplot2::last_plot(), name = NULL, label = NULL, prefix = NULL, postfix = NULL, increment = NULL, filename = NULL, device = NULL, fileext = NULL, filetype = NULL, path = NULL, paper = NULL, orientation = NULL, width = NULL, height = NULL, asp = NULL, units = getOption("papersize.ggsave_units", "in"), scale = 1, dpi = 300, bgcolor = NULL, exif = FALSE, title = NULL, author = NULL, keywords = NULL, args = NULL, overwrite = TRUE, ask = FALSE, preview = FALSE, limitsize = TRUE, quiet = FALSE, ... ) ggsave_social( plot = ggplot2::last_plot(), image = "Instagram post", platform = NULL, format = NULL, orientation = NULL, name = NULL, filename = NULL, fileext = "jpeg", filetype = NULL, dpi = 72, width = 1080, height = 1080, units = "px", ... ) map_ggsave_ext( plot, name = NULL, label = NULL, prefix = NULL, postfix = "pg_", filename = NULL, device = NULL, fileext = NULL, filetype = NULL, path = NULL, overwrite = TRUE, ..., single_file = TRUE, onefile = TRUE )
ggsave_ext( plot = ggplot2::last_plot(), name = NULL, label = NULL, prefix = NULL, postfix = NULL, increment = NULL, filename = NULL, device = NULL, fileext = NULL, filetype = NULL, path = NULL, paper = NULL, orientation = NULL, width = NULL, height = NULL, asp = NULL, units = getOption("papersize.ggsave_units", "in"), scale = 1, dpi = 300, bgcolor = NULL, exif = FALSE, title = NULL, author = NULL, keywords = NULL, args = NULL, overwrite = TRUE, ask = FALSE, preview = FALSE, limitsize = TRUE, quiet = FALSE, ... ) ggsave_social( plot = ggplot2::last_plot(), image = "Instagram post", platform = NULL, format = NULL, orientation = NULL, name = NULL, filename = NULL, fileext = "jpeg", filetype = NULL, dpi = 72, width = 1080, height = 1080, units = "px", ... ) map_ggsave_ext( plot, name = NULL, label = NULL, prefix = NULL, postfix = "pg_", filename = NULL, device = NULL, fileext = NULL, filetype = NULL, path = NULL, overwrite = TRUE, ..., single_file = TRUE, onefile = TRUE )
plot |
Plot to save, defaults to last plot displayed. If plot is an
"magick-image" class object, it is converted to a plot using
|
name |
Plot name, used to create filename (if filename is |
label |
Label to combine with name converted to snake case with
|
prefix |
File name prefix. "date" adds a date prefix, "time" adds a
date/time prefix; defaults to |
postfix |
File name postfix; defaults to |
increment |
If |
filename |
File name to create on disk. |
device |
Device to use. Can either be a device function
(e.g. png), or one of "eps", "ps", "tex" (pictex),
"pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf" (windows only). If
|
fileext |
File type or extension. Optional if filename or path include a file extension. |
filetype |
File type (used if fileext is |
path |
Path of the directory to save plot to: |
paper |
Paper matching name from |
orientation |
Page orientation ("portrait", "landscape", or "square"). |
width , height
|
Plot size in units expressed by the |
asp |
Numeric aspect ratio used to determine width or height if only one
of the two arguments is provided; defaults to |
units |
One of the following units in which the |
scale |
Multiplicative scaling factor. |
dpi |
Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Applies only to raster output types. |
bgcolor |
Background color to optionally override |
exif |
If |
title |
Title to add to file metadata with exiftoolr, Default: |
author |
Author to add to file metadata to the "Author" and
"XMP-dc:creator" tags. Default: |
keywords |
Keyword(s) added to file metadata to "IPTC:Keywords" and
"XMP-dc:Subject" tags. Defaults to |
args |
Alternate arguments passed to |
overwrite |
If |
ask |
If |
preview |
If |
limitsize |
When |
quiet |
If |
... |
Arguments passed on to
|
image |
Image name passed to name parameter of |
platform |
Social media platform, "Instagram", "Facebook", or "Twitter",
Default: |
format |
Image format, "post", "story", or "cover", Default: |
single_file , onefile
|
If |
A vector of units supported by grid::unit()
grid_units
grid_units
A character vector with 34 abbreviated, singular, and plural unit names.
Create an inset with page size dimensions be added on top of the previous plot
inset_page_element( p, inset_page = NULL, left = NULL, bottom = NULL, right = NULL, top = NULL, align_to = "panel", on_top = TRUE, clip = TRUE, ignore_tag = FALSE, ... )
inset_page_element( p, inset_page = NULL, left = NULL, bottom = NULL, right = NULL, top = NULL, align_to = "panel", on_top = TRUE, clip = TRUE, ignore_tag = FALSE, ... )
p |
A grob, ggplot, patchwork, formula, raster, or nativeRaster object to add as an inset |
inset_page |
Page size data.frame to use for inset, Default: |
left , bottom , right , top
|
numerics or units giving the location of the
outer bounds. If given as numerics and inset_page is NULL, they will be
converted to npc units. All four are required if inset_page is |
align_to |
Specifies what |
on_top |
Logical. Should the inset be placed on top of the other plot or below (but above the background)? |
clip |
Logical. Should clipping be performed on the inset? |
ignore_tag |
Logical. Should autotagging ignore the inset? |
... |
Arguments passed on to
|
A inset_path
object
## Not run: if (interactive() && is_installed("ggplot2")) { library(ggplot2) p <- ggplot(mpg, aes(displ, fill = class)) + geom_bar() ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() + inset_page_element( p = p, inset_page = get_page_size("Poker card", orientation = "landscape"), left = unit(1, "in"), bottom = unit(1, "in") ) } ## End(Not run)
## Not run: if (interactive() && is_installed("ggplot2")) { library(ggplot2) p <- ggplot(mpg, aes(displ, fill = class)) + geom_bar() ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() + inset_page_element( p = p, inset_page = get_page_size("Poker card", orientation = "landscape"), left = unit(1, "in"), bottom = unit(1, "in") ) } ## End(Not run)
is_dist_units()
: Is x a units object with a units attribute in
dist_unit_options
or area_unit_options
?
get_dist_units()
: Get the distance units from x (if x is a sf or units
objects or a character string from dist_unit_options)
as_dist_units()
: Convert x to units using units::as_units
is_same_units()
: Do x and y have the same distance units attribute?
Names or symbols of valid distance units are allowed.
is_dist_units(x, arg = caller_arg(x)) get_dist_units(x, arg = caller_arg(x), call = parent.frame()) as_dist_units(x, units = NULL, arg = caller_arg(x), call = parent.frame()) is_same_units(x, y = NULL)
is_dist_units(x, arg = caller_arg(x)) get_dist_units(x, arg = caller_arg(x), call = parent.frame()) as_dist_units(x, units = NULL, arg = caller_arg(x), call = parent.frame()) is_same_units(x, y = NULL)
x , y
|
objects to check |
arg |
Used internally and passed to |
call |
The execution environment of a currently
running function, e.g. |
units |
Distance units to convert to. Must be one of dist_unit_options or area_unit_options. |
Other dist:
convert_dist_scale()
,
convert_dist_units()
mile <- units::set_units(1, "mi") is_dist_units("mi") is_dist_units(mile) is_same_units(mile, "mile") get_dist_units(mile) as_dist_units(1, "mi") as_dist_units(2, mile)
mile <- units::set_units(1, "mi") is_dist_units("mi") is_dist_units(mile) is_same_units(mile, "mile") get_dist_units(mile) as_dist_units(1, "mi") as_dist_units(2, mile)
magick::image_ggplot()
to make contact sheets for images
Wraps filenamr::read_exif()
, magick::image_ggplot()
, and page_layout()
to create contact shets for a folder of images.
make_contact_sheets( images, dims = NULL, ncol = NULL, nrow = NULL, captions = "{file_name}\n{date_created}", caption_size = 12, caption_position = "panel", image_margin = margins(0.1, unit = "in"), page = "letter", orientation = "portrait", image_max = NULL, image_fileext = NULL, tags = NULL, tz = NULL, save = FALSE, filename = NULL, ... )
make_contact_sheets( images, dims = NULL, ncol = NULL, nrow = NULL, captions = "{file_name}\n{date_created}", caption_size = 12, caption_position = "panel", image_margin = margins(0.1, unit = "in"), page = "letter", orientation = "portrait", image_max = NULL, image_fileext = NULL, tags = NULL, tz = NULL, save = FALSE, filename = NULL, ... )
images |
File path or data.frame from |
dims |
Image dimensions in same dimensions as page. Required. |
ncol , nrow
|
The dimensions of the grid to create. If both are |
captions |
Template for caption, passed to |
caption_size |
Caption size, passed to |
caption_position |
Caption position, passed to plot.caption.position for theme, Default: 'panel' |
image_margin |
Image margin passed Default: |
page |
Paper name or a data.frame with width and height columns.
Optional if width and height are both provided, Default: |
orientation |
Paper orientation, Optional if width and height are both provided, Default: 'landscape' |
image_max |
Maximum number of images to use for contact sheets. |
image_fileext |
Passed to fileext parameter of |
tags |
List of EXIF tags to read from files. If
|
tz |
Time zone to pass to |
save |
If |
filename |
File name to create on disk. |
... |
Additional parameters passed to |
A list of patchwork object or (if save = TRUE) invisibly return the list and save a file.
filenamr::read_exif()
glue::glue()
magick::editing()
, magick::image_ggplot()
ggplot2::labs()
, ggplot2::theme()
, ggplot2::margin()
Width and height or aspect ratio and either width or height are required. Units are also required. If orientation is provided, width and height may be reversed to match the provided orientation.
make_page_size( width = NULL, height = NULL, units, asp = NULL, orientation = NULL, name = NULL, dims = NULL, valid_units = NULL, cols = c("width", "height"), class = "data.frame", call = caller_env() )
make_page_size( width = NULL, height = NULL, units, asp = NULL, orientation = NULL, name = NULL, dims = NULL, valid_units = NULL, cols = c("width", "height"), class = "data.frame", call = caller_env() )
width , height
|
Page width and height. Both are required, if asp is
|
units |
Units for width and height. Required unless units is included in
dims. Passed to |
asp |
Aspect ratio. Required if only one of width or height are provided. |
orientation |
Page orientation, Default: |
name |
Optional name for paper size. Recommend avoiding duplication with
existing names in |
dims |
A list or data.frame that can be used to set width, height, units, and/or asp. |
valid_units |
Character vector with name or symbols for valid units.
Defaults to |
cols |
Column names to use for width and height columns. Defaults to c("width", "height"). Must be length 2 and the first value is always used as as the width name and the second as the height. |
class |
Class of return object: "data.frame" (default) or "list" (only supported when input page size is a single row). |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
A data.frame with columns named (by default) width, height, units, orientation, and asp or a list with those same names.
make_page_size(48, 24, "in", name = "Tabletop map") make_page_size(8.5, 8.5, "in", name = "Trimmed letter") make_page_size(5, asp = 1.25, units = "cm", class = "list")
make_page_size(48, 24, "in", name = "Tabletop map") make_page_size(8.5, 8.5, "in", name = "Trimmed letter") make_page_size(5, asp = 1.25, units = "cm", class = "list")
An extended version of ggplot2::margin()
with more flexibility in
specification. If margin is a margin class object it is returned as is. If
margin is length 1, the t, r, b, and l values are all set to that value. If
margin is length 2, the t and b are set to half the first value and the r and
l are set to half the second value. The ...
parameters also allow you to
use the same syntax as margin.
margins(margin = NULL, ..., unit = "in") is_margin(x) margin(t = 0, r = 0, b = 0, l = 0, unit = "pt") get_margin(margin = NULL, ..., unit = "in")
margins(margin = NULL, ..., unit = "in") is_margin(x) margin(t = 0, r = 0, b = 0, l = 0, unit = "pt") get_margin(margin = NULL, ..., unit = "in")
margin |
A numeric list or vector or a margin class object. For
|
... |
Additional numeric values combined with margin if provided. |
unit |
Default units for margins (ignored if margin is a margin class
object). Passed to |
x |
Object to check for class margin and unit |
t , r , b , l
|
Dimensions of each margin: top, right, bottom, and left. (To remember order, think trouble). |
ggplot2 package
margins(1, unit = "in") margins(c(2, 2), unit = "in") margins(list(1, 1, 1.5, 1), unit = "cm") margins(t = 1, r = 3, b = 1.5, l = 3, unit = "in") standard_margin <- get_margin("standard", unit = "in") is_margin(standard_margin) standard_margin
margins(1, unit = "in") margins(c(2, 2), unit = "in") margins(list(1, 1, 1.5, 1), unit = "cm") margins(t = 1, r = 3, b = 1.5, l = 3, unit = "in") standard_margin <- get_margin("standard", unit = "in") is_margin(standard_margin) standard_margin
A named list of additional reference data that currently includes only one data.frame: a reference table of margin sizes in "in" and "cm".
page_extras
page_extras
A length 1 list.
Use patchwork to lay out a list of fixed aspect plots on a larger page
page_layout( plots = NULL, page = NULL, width = NULL, height = NULL, orientation = "landscape", byrow = FALSE, guides = NULL, tag_level = NULL, design = NULL, paginate = TRUE, ncol = NULL, nrow = NULL, dims = NULL, images = FALSE, dpi = 120, call = caller_env() )
page_layout( plots = NULL, page = NULL, width = NULL, height = NULL, orientation = "landscape", byrow = FALSE, guides = NULL, tag_level = NULL, design = NULL, paginate = TRUE, ncol = NULL, nrow = NULL, dims = NULL, images = FALSE, dpi = 120, call = caller_env() )
plots |
Page name, a data.frame with width and height columns, or a list
of ggplot2 objects with card plots. Default: |
page |
Paper name or a data.frame with width and height columns.
Optional if width and height are both provided, Default: |
width , height
|
Paper width and height, Default: |
orientation |
Paper orientation, Optional if width and height are both provided, Default: 'landscape' |
byrow |
Analogous to |
guides |
A string specifying how guides should be treated in the layout.
|
tag_level |
A string ( |
design |
Specification of the location of areas in the layout. Can either
be specified as a text string or by concatenating calls to |
paginate |
If |
ncol , nrow
|
The dimensions of the grid to create. If both are |
dims |
Optional. Plot dimensions. Ignored if ncol and nrow are supplied.
Otherwise, if |
images |
Not yet implemented. If |
dpi |
Not yet implemented. Resolution. |
call |
The execution environment of a currently
running function, e.g. |
A patchwork
object or a list of patchwork
objects.
ggplot2::ggplot_build()
patchwork::wrap_plots()
, patchwork::plot_layout()
page_layout( plots = plot_cards("Poker", 6), page = "letter" )
page_layout( plots = plot_cards("Poker", 6), page = "letter" )
Convert a page size data.frame to a Grid layout object
page_to_layout( page, margins = NULL, region = NULL, ncol = 1, nrow = 1, gutter = NULL, widths = NULL, heights = NULL, units = "in", respect = TRUE, just = "center", cols = c("width", "height") )
page_to_layout( page, margins = NULL, region = NULL, ncol = 1, nrow = 1, gutter = NULL, widths = NULL, heights = NULL, units = "in", respect = TRUE, just = "center", cols = c("width", "height") )
page |
A page size data.frame from |
margins |
A numeric list or vector or a margin class object. Defaults to
|
region |
Optional. An additional page data.frame where the region width and height are used as the column width and row height. |
ncol |
An integer describing the number of columns in the layout. |
nrow |
An integer describing the number of rows in the layout. |
gutter |
Gutter width/height. Not yet implemented. |
widths |
A numeric vector or unit object describing the widths of the columns in the layout. |
heights |
A numeric vector or unit object describing the heights of the rows in the layout. |
units |
Passed to default.units parameter of |
respect |
A logical value or a numeric matrix. If a logical, this indicates whether row heights and column widths should respect each other. If a matrix, non-zero values indicate that the corresponding row and column should be respected (see examples below). |
just |
A string or numeric
vector specifying how the
layout should be
justified if it is not the same size as its parent viewport.
If there are two values, the first
value specifies horizontal justification and the second value specifies
vertical justification. Possible string values are: |
cols |
Column names to use for width and height columns. Defaults to c("width", "height"). Must be length 2 and the first value is always used as as the width name and the second as the height. |
A Grid layout object with the same width and height and default units as the input page size.
a8_layout <- page_to_layout( get_paper("A8", orientation = "landscape"), ncol = 2, nrow = 2 ) grid::grid.show.layout(a8_layout)
a8_layout <- page_to_layout( get_paper("A8", orientation = "landscape"), ncol = 2, nrow = 2 ) grid::grid.show.layout(a8_layout)
viewport
class objectCreate a viewport
class object with a width and height matching the
dimensions of a page data.frame and default.units that match the page units.
page_to_viewport(page, name = NULL, cols = c("width", "height"), ...)
page_to_viewport(page, name = NULL, cols = c("width", "height"), ...)
page |
A page data.frame from |
name |
A character value to uniquely identify the viewport once it has been pushed onto the viewport tree. |
cols |
Column names to use for width and height columns. Defaults to c("width", "height"). Must be length 2 and the first value is always used as as the width name and the second as the height. |
... |
Arguments passed on to
|
A viewport
class object with the same width and height as the
input page size.
vp <- page_to_viewport(get_paper("Poker card")) grid::grid.show.viewport(vp)
vp <- page_to_viewport(get_paper("Poker card")) grid::grid.show.viewport(vp)
Reference table of standard paper, postcard, photo print, social media image
sizes, and playing card sizes for get_page_size()
. Derived from
visioguy/PaperSizes repo, Adobe UK guide to photo sizes
and other sources. Data is identical to data included with {sfext}
package.
paper_sizes
paper_sizes
A data frame with 125 rows and 9 variables:
name
Name of paper
series
Series
standard
Standard
size
Size in series
units
Units ("in", "mm", or "px") for dimensions
width
Width in units
height
Height in units
orientation
Portrait (width less than height), landscape, or square
type
Type (paper, postcard, print, or social)
plot_cards()
takes a card that defines the dimensions of a card and creates
a list of plots using the specified aesthetics.
plot_cards( card, n = 1, orientation = "portrait", number = FALSE, color = "white", size = 5, family = NULL, fill = "gray20", border = FALSE, inset = grid::unit(c(5, 5), "mm"), linetype = "dashed", linewidth = 1, text = NULL, center = NULL )
plot_cards( card, n = 1, orientation = "portrait", number = FALSE, color = "white", size = 5, family = NULL, fill = "gray20", border = FALSE, inset = grid::unit(c(5, 5), "mm"), linetype = "dashed", linewidth = 1, text = NULL, center = NULL )
card |
Card name or data.frame with width and height columns. |
n |
Number of cards to plot, Default: 1 |
orientation |
Card orientation, Default: 'portrait' |
number |
If |
color |
Color for number, text, and border, Default: 'white' |
size |
Font size for number and text, Default: 5 |
family |
Font family for number and text, Default: 'Georgia' |
fill |
Length 1 or 2 character vector with color name. If length 2, the first value is assumed to be the card fill and the second value is assumed to be the inset border fill. Default: 'gray20' |
border |
If TRUE, add a border to the card. Default: FALSE |
inset |
Unit or numeric vector with inset distance for card border,
Default: |
linetype |
linetype for card border, Default: 'dashed' |
linewidth |
linewidth for card border, Default: 2 |
text |
Character vector with card text, Default: NULL |
center |
Position of card center, Default: c(0, 0) |
A list of plot objects where each item on the list is a card.
#' ## Not run: if (interactive() && is_installed("ggplot2")) { plot_cards("Tarot", n = 2, number = TRUE)[[2]] plot_cards("Poker", n = 1, number = TRUE, text = "♡️") } ## End(Not run)
#' ## Not run: if (interactive() && is_installed("ggplot2")) { plot_cards("Tarot", n = 2, number = TRUE)[[2]] plot_cards("Poker", n = 1, number = TRUE, text = "♡️") } ## End(Not run)
print_to_page(plot, page, newpage = TRUE, vp = NULL, ...) print_to_page_layout( plot, page, row_position = 1, col_position = 1, row_height = NULL, col_width = NULL, nrow = 1, ncol = 1, layout = NULL, parent = NULL, children = NULL, filename = NULL, ... )
print_to_page(plot, page, newpage = TRUE, vp = NULL, ...) print_to_page_layout( plot, page, row_position = 1, col_position = 1, row_height = NULL, col_width = NULL, nrow = 1, ncol = 1, layout = NULL, parent = NULL, children = NULL, filename = NULL, ... )
plot |
Plot to display |
page |
A page data.frame from |
newpage |
draw new (empty) page first? |
vp |
viewport to draw plot in |
... |
Arguments passed on to
|
row_position , col_position
|
Row and column position. If nrow is smaller than row_position or ncol is smaller than col_position, row_position is used for nrow or col_position is used for ncol instead. |
row_height , col_width
|
Row height and column width. |
nrow |
An integer describing the number of rows in the layout. |
ncol |
An integer describing the number of columns in the layout. |
layout |
Passed to |
parent |
A grid viewport object. |
children |
A vpList object. |
filename |
File name to create on disk. |
Invisibly returns the original plot using a viewport from
page_to_viewport()
.
## Not run: if (interactive() && is_installed("ggplot2")) { library(ggplot2) plot <- ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() print_to_page( plot, page = get_page_size("Tarot card") ) } ## End(Not run)
## Not run: if (interactive() && is_installed("ggplot2")) { library(ggplot2) plot <- ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() print_to_page( plot, page = get_page_size("Tarot card") ) } ## End(Not run)
Set page data.frame dimensions, orientation, or aspect ratio
set_page_asp: appends an aspect ratio column a page size data.frame
set_page_dims( page, dims = NULL, width = NULL, height = NULL, units = NULL, cols = c("width", "height") ) set_page_orientation( page, orientation = NULL, tolerance = 0.1, cols = c("width", "height") ) set_page_asp(page, flipped = FALSE, cols = c("width", "height"))
set_page_dims( page, dims = NULL, width = NULL, height = NULL, units = NULL, cols = c("width", "height") ) set_page_orientation( page, orientation = NULL, tolerance = 0.1, cols = c("width", "height") ) set_page_asp(page, flipped = FALSE, cols = c("width", "height"))
page |
If character, page is passed as the name parameter to
|
dims |
A vector or list with values in the same order as cols
(defaults to |
width , height
|
Page width and height. Both are required, if asp is
|
units |
Units for width and height. Required unless units is included in
dims. Passed to |
cols |
Column names to use for width and height columns. Defaults to c("width", "height"). Must be length 2 and the first value is always used as as the width name and the second as the height. |
orientation |
Page orientation, Default: |
tolerance |
Positive numeric value above or below 1 used to determine if an aspect ratio is square, landscape, or portrait. |
flipped |
If |
Set margins for page data.frame (adding body width, height, and asp)
set_page_margin( page = NULL, margins, unit = "in", cols = c("width", "height"), ... )
set_page_margin( page = NULL, margins, unit = "in", cols = c("width", "height"), ... )
page |
A character vector with a page size name or a data.frame. Passed
to x parameter of |
margins |
Passed to |
unit |
Unit used for the margin. If margin is a unit object, unit is ignored. If page uses different units, the margins are converted into the page units for consistency. |
cols |
Column names to use for width and height columns. Defaults to c("width", "height"). Must be length 2 and the first value is always used as as the width name and the second as the height. |
... |
Passed to |
A data.frame with the page dimensions and additional columns for body dimensions, body aspect ratio, and margins.
ggplot2::margin()
; set_page_dims()
; set_page_orientation()
;
set_page_asp()
Standard map scales derived from USGS 2002 report on map scales https://pubs.usgs.gov/fs/2002/0015/report.pdf
standard_scales
standard_scales
A data frame with 36 rows and 16 variables:
scale
Scale name
standard
Standard (USGS, architectural, or engineering)
series
Series name (USGS map scales only)
actual_ft
Scale distance for 1 ft actual.
actual_ft_unit
Unit of scale for 1 ft actual.
scale_in
Actual distance for 1 in scale.
scale_in_unit
Unit of actual distance for 1 in scale.
scale_in_accuracy
Accuracy of 1 in scale (approximate or exact)
scale_cm
Actual distance for 1 cm scale.
scale_cm_unit
Unit of actual distance for 1 cm scale.
scale_cm_accuracy
Accuracy of 1 cm scale (approximate or exact)
size_latlon
Standard size in latitude/longitude
size_latlon_unit
Unit of latitude/longitude size (minutes or degrees)
area_approx
Approximate actual area
area_approx_unit
Approximate area unit
series_status
Series status (select USGS map series are "abandoned")
Common architectural and engineering scales derived from FEMA guide to using scales https://www.usfa.fema.gov/downloads/pdf/nfa/engineer-architect-scales.pdf
Wrapper for ggplot2::theme() that passes as_asp() with flip = TRUE
to the
aspect.ratio argument to force a plot to match the aspect ratio of the
provided page.
theme_page(page, orientation = NULL, ...)
theme_page(page, orientation = NULL, ...)
page |
If character, page is passed as the name parameter to
|
orientation |
Page orientation, Default: |
... |
Arguments passed on to
|
A ggplot theme
class object with the aspect.ratio argument set to
match the page height / width.