mypdf: Paper size for PDF files

Description Usage Arguments Details Value References See Also Examples

View source: R/plotting.R

Description

mypdf is a wrapper for pdf from the grDevices package. The difference is that mypdf determines the width and the height of the plotting region from a given standard paper format using paper_size. max_rgb_constrast is a helper functions for arranging colours.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
  mypdf(file, ...)

  ## S3 method for class 'character'
 mypdf(file, paper = "a4r",
    prop = 0.9, ...)

  paper_size(x, ...)

  ## S3 method for class 'numeric'
 paper_size(x, landscape = FALSE,
    series = c("A", "B", "C"), ...)

  ## S3 method for class 'character'
 paper_size(x, landscape = FALSE,
    inches = FALSE, ...)

  max_rgb_contrast(x, ...)

  ## Default S3 method:
 max_rgb_contrast(x, ...)

Arguments

file

Passed as ‘file’ argument to pdf from the grDevices package. See there for details.

paper

Character scalar like the eponymous argument of pdf, but here it is passed to paper_size to determine the ‘width’ and the ‘height’ of the plotting region.

prop

Numeric vector. Its values should be between 0 and 1. Its first element is multiplied with the width of paper to yield the width of the plotting region. Its last element is multiplied with the height of paper to yield the height of the plotting region.

x

Numeric or character vector for determining the paper size. If a numeric vector, specifying paper sizes in the ‘DIN’ series. If a character vector, the full names of well-known paper formats such as ‘a4’, ‘letter’, etc.

For max_rgb_contrast, the names or hexadecimal codes of the colours to be sorted. Might also be an integer vector, see col2rgb from the grDevices package for details. Duplicate RGB coordinates and unknown names will cause an error.

landscape

Logical scalar. If FALSE, ‘portrait’ paper orientation is assumed. For the character method, this has only an effect for paper size specifiers such as ‘letter’ that do not belong to the ‘DIN’ series. For the ‘DIN’ series, append ‘R’ to the specifier to obtain ‘landscape’ orientation.

inches

Logical scalar. If TRUE, output unit is inches, otherwise millimetres.

series

Character scalar indicating the ‘DIN’ series to assume.

...

Optional arguments passed to other methods, e.g., to pdf from the grDevices package.

Details

The computation of the paper size is done numerically for the DIN series, whereas a look-up table is used for the other formats.

max_rgb_contrast arranges colours so as to achieve that neighbouring colours are most distinct with respect to their RGB coordinates. This is done as follows: (1) Euclidean distances between the RGB coordinates of the input colours are calculated; (2) the distances are log-transformed and inverted; (3) a principal-coordinate analysis is conducted on these inverted distances; (4) the input colours are sorted according to the first principal coordinate.

Note that this is probably only works for colour vectors of small to moderate size, and that the resulting vector could as well be used in reverse order (see the examples).

Value

mypdf returns NULL. As a side effect, file is opened. paper_size yields a numeric matrix with columns ‘width’ and ‘height’ and x as row names (if it was a character vector). max_rgb_contrast returns a character vector (the rearranged input names).

References

https://en.wikipedia.org/wiki/Paper_size

See Also

grDevices::pdf grDevices::col2rg

Examples

 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
29
30
31
32
## Not run: 
  mypdf("example.pdf")
  ## create some plots...
  dev.off()

## End(Not run)

## paper_size()

query <- c("A4", "Letter", "unknown")
(x <- paper_size(query))
stopifnot(is.matrix(x), is.numeric(x), rownames(x) == query)
stopifnot(colnames(x) == c("height", "width"), is.na(x["unknown", ]))
(y <- paper_size(4))
stopifnot(identical(y, x[1L, , drop = FALSE]))

## max_rgb_contrast()

# with colours
(x <- max_rgb_contrast(c("darkred", "darkblue", "blue", "red")))
y <- c("darkblue", "red", "blue", "darkred")
stopifnot(identical(x, y) || identical(x, rev(y)))

# shades of grey 1
(x <- max_rgb_contrast(c("white", "grey", "black")))
y <- c("grey", "black", "white")
stopifnot(identical(x, y) || identical(x, rev(y)))

# shades of grey 2
(x <- max_rgb_contrast(c("white", "darkgrey", "lightgrey", "black")))
y <- c("lightgrey", "black", "white", "darkgrey")
stopifnot(identical(x, y) || identical(x, rev(y)))

pkgutils documentation built on May 2, 2019, 5:49 p.m.

Related to mypdf in pkgutils...