Title: | Scale Graphics Devices Using Plot Dimensions |
---|---|
Description: | Figures rendered on graphics devices are usually rescaled to fit pre-determined device dimensions. 'plotscale' implements the reverse: desired plot dimensions are specified and device dimensions are calculated to accommodate marginal material, giving consistent proportions for plot elements. Default methods support grid graphics such as lattice and ggplot. See "example('devsize')" and "vignette('plotscale')". |
Authors: | Tim Bergsma |
Maintainer: | Tim Bergsma <[email protected]> |
License: | GPL-3 |
Version: | 0.1.6 |
Built: | 2024-10-15 03:00:01 UTC |
Source: | https://github.com/cran/plotscale |
Coerces to PDF. Generic, with default method.
as.pdf(x, ...)
as.pdf(x, ...)
x |
object |
... |
passed arguments |
Other as.pdf: as.pdf.default
Other devices: as.pdf.default
,
as.png.default
, as.png
example(as.pdf.default)
example(as.pdf.default)
Converts object to PDF. By default, device is scaled by plot size. Device is automatically closed and file argument is returned.
## Default S3 method: as.pdf(x, width = getOption("plotscale_pdf_width", 3), height = getOption("plotscale_pdf_height", 3), devsize = if (scaled) "devsize" else "unscaled", scaled = getOption("plotscale_scaled", TRUE), onefile = TRUE, file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf", ...)
## Default S3 method: as.pdf(x, width = getOption("plotscale_pdf_width", 3), height = getOption("plotscale_pdf_height", 3), devsize = if (scaled) "devsize" else "unscaled", scaled = getOption("plotscale_scaled", TRUE), onefile = TRUE, file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf", ...)
x |
object |
width |
desired plot width |
height |
desired plot height |
devsize |
a function of x, width, height, and ... that calculates device size |
scaled |
whether to rescale width and height by plot size |
onefile |
logical: passed to |
file |
file name passed to |
... |
other arguments to |
(invisible) the file argument
Other as.pdf: as.pdf
Other devices: as.pdf
,
as.png.default
, as.png
options(example.ask = FALSE) options(device.ask.default = FALSE) library(lattice) as.pdf(xyplot(2~3),file = tempfile())
options(example.ask = FALSE) options(device.ask.default = FALSE) library(lattice) as.pdf(xyplot(2~3),file = tempfile())
Coerces to PNG. Generic, with default method.
as.png(x, ...)
as.png(x, ...)
x |
object |
... |
passed arguments |
Other as.png: as.png.default
Other devices: as.pdf.default
,
as.pdf
, as.png.default
example(as.png.default)
example(as.png.default)
Converts object to PNG. By default, device is scaled by plot size. Device is automatically closed and filename argument is returned.
## Default S3 method: as.png(x, width = getOption("plotscale_png_width", 3), height = getOption("plotscale_png_height", 3), devsize = if (scaled) "devsize" else "unscaled", res = getOption("plotscale_res", 300), units = "in", scaled = getOption("plotscale_scaled", TRUE), filename = "Rplot%03d.png", ...)
## Default S3 method: as.png(x, width = getOption("plotscale_png_width", 3), height = getOption("plotscale_png_height", 3), devsize = if (scaled) "devsize" else "unscaled", res = getOption("plotscale_res", 300), units = "in", scaled = getOption("plotscale_scaled", TRUE), filename = "Rplot%03d.png", ...)
x |
object |
width |
desired plot width |
height |
desired plot height |
devsize |
a function of x, width, height, and ... that calculates device size |
res |
passed to |
units |
NOT passed to |
scaled |
whether to rescale width and height by plot size |
filename |
file name passed to |
... |
other arguments to |
(invisible) the filename argument
Other as.png: as.png
Other devices: as.pdf.default
,
as.pdf
, as.png
options(example.ask = FALSE) options(device.ask.default = FALSE) library(lattice) as.png(xyplot(2~3), filename = tempfile())
options(example.ask = FALSE) options(device.ask.default = FALSE) library(lattice) as.png(xyplot(2~3), filename = tempfile())
Coerce to class 'size'. Generic, with method for list.
as.size(x, ...)
as.size(x, ...)
x |
object |
... |
ignored |
Other generic functions: devsize
,
plotsize
, unscaled
Other devsize: devsize.default
,
devsize
, print.size
,
unscaled.default
, unscaled
Other plotsize: plotsize.default
,
plotsize
, print.size
Other size: as.size.list
Coerce list to class 'size'.
## S3 method for class 'list' as.size(x, ...)
## S3 method for class 'list' as.size(x, ...)
x |
object |
... |
ignored |
Other size: as.size
Determines the size of a device. Generic, with default method.
devsize(x, ...)
devsize(x, ...)
x |
object |
... |
other arguments |
Other generic functions: as.size
,
plotsize
, unscaled
Other devsize: as.size
,
devsize.default
, print.size
,
unscaled.default
, unscaled
example(devsize.default)
example(devsize.default)
Determines smallest device width and height that give a plot width
and height at least as large as the supplied width
and height
.
Plot width and height are determined by plotsize
(e.g., by the dimensions
of the first panel as for plotsize.default
).
## Default S3 method: devsize(x, width, height, device = list(width = width * 1.1, height = height * 1.1), digits = getOption("plotscale_devsize_digits", 2), plotsize = getOption("plotscale_plotsize", "plotsize"), width.major = TRUE, optimize.minor = TRUE, check.aspect = TRUE, verbose = getOption("plotsize_verbose", FALSE), ...)
## Default S3 method: devsize(x, width, height, device = list(width = width * 1.1, height = height * 1.1), digits = getOption("plotscale_devsize_digits", 2), plotsize = getOption("plotscale_plotsize", "plotsize"), width.major = TRUE, optimize.minor = TRUE, check.aspect = TRUE, verbose = getOption("plotsize_verbose", FALSE), ...)
x |
object |
width |
desired plot width in inches |
height |
desired plot height in inches |
device |
length 2 named list suggesting initial width and height for device |
digits |
|
plotsize |
a function of x, width, height, digits and ... that returns a named list with elements 'width' and 'height' giving dimensions of x |
width.major |
whether to optimize width first for fixed aspect plots (used internally) |
optimize.minor |
whether to minor dimension for fixed aspect plots (used internally) |
check.aspect |
whether to adjust width and height to conform to fixed aspect (used internally) |
verbose |
whether to explain the process |
... |
other arguments passed to fun |
length 2 named list giving device width and height in inches (class 'size')
Other devsize: as.size
,
devsize
, print.size
,
unscaled.default
, unscaled
options(example.ask = FALSE) options(device.ask.default = FALSE) library(lattice) data(iris) x <- xyplot(Petal.Width~Petal.Length, groups = Species, data = iris) devsize(x, width = 4, height = 4, digits = 1, verbose = TRUE) devsize(x, width = 4, height = 5, digits = 1, verbose = TRUE) x <- update(x, aspect = 1) devsize(x, width = 4, height = 4, digits = 1, verbose = TRUE) devsize(x, width = 4, height = 5, digits = 1, verbose = TRUE) devsize(splom(iris[,1:4]), width = 4, height = 4) devsize(xyplot(Sepal.Length ~ Sepal.Width | Species, data = iris), width = 4, height = 4) library(ggplot2) p <- ggplot(data = iris, mapping = aes(y = Sepal.Length, x = Sepal.Width)) + geom_point() + facet_wrap(~Species) devsize(p, width = 4, height = 4) devsize(p + theme(aspect.ratio = 1), width = 4, height = 4)
options(example.ask = FALSE) options(device.ask.default = FALSE) library(lattice) data(iris) x <- xyplot(Petal.Width~Petal.Length, groups = Species, data = iris) devsize(x, width = 4, height = 4, digits = 1, verbose = TRUE) devsize(x, width = 4, height = 5, digits = 1, verbose = TRUE) x <- update(x, aspect = 1) devsize(x, width = 4, height = 4, digits = 1, verbose = TRUE) devsize(x, width = 4, height = 5, digits = 1, verbose = TRUE) devsize(splom(iris[,1:4]), width = 4, height = 4) devsize(xyplot(Sepal.Length ~ Sepal.Width | Species, data = iris), width = 4, height = 4) library(ggplot2) p <- ggplot(data = iris, mapping = aes(y = Sepal.Length, x = Sepal.Width)) + geom_point() + facet_wrap(~Species) devsize(p, width = 4, height = 4) devsize(p + theme(aspect.ratio = 1), width = 4, height = 4)
Determines the size of a plot. Generic, with default method.
plotsize(x, ...)
plotsize(x, ...)
x |
object |
... |
other arguments |
Other generic functions: as.size
,
devsize
, unscaled
Other plotsize: as.size
,
plotsize.default
, print.size
example(plotsize.default)
example(plotsize.default)
Determines the size of a grid graphics plot conditional on device dimensions.
Size is defined as physical width and height in inches
of the first encountered panel as rendered on a device with the
specified width and height. pdf()
is used as the evaluation
device. 'First encountered panel' is resolved by evaluating the
output of a call to current.vpTree
for the
first viewport name containing 'panel' or 'subpanel'. The latter
takes precedence if available, for intuitive handling of output from
splom
.
## Default S3 method: plotsize(x, width, height, digits = getOption("plotscale_plotsize_digits", 3), pattern = c("subpanel\\b", "panel\\b"), index = 1, ...)
## Default S3 method: plotsize(x, width, height, digits = getOption("plotscale_plotsize_digits", 3), pattern = c("subpanel\\b", "panel\\b"), index = 1, ...)
x |
object |
width |
device width in inches |
height |
device height in inches |
digits |
|
pattern |
character: vector of search patterns to identify critical viewport set; first non-empty set is retained |
index |
integer: select this element of the critical viewport set |
... |
other arguments passed to |
length 2 named list giving width and height in inches (class 'size') for the first panel
Other plotsize: as.size
,
plotsize
, print.size
options(ask.default = FALSE) options(device.ask.default = FALSE) library(lattice) p <- xyplot(2~3) plotsize(p, width = 7, height = 7)
options(ask.default = FALSE) options(device.ask.default = FALSE) library(lattice) p <- xyplot(2~3) plotsize(p, width = 7, height = 7)
Print object of class 'size', as returned by devsize
and plotsize
.
## S3 method for class 'size' print(x, ...)
## S3 method for class 'size' print(x, ...)
x |
object |
... |
ignored |
Other plotsize: as.size
,
plotsize.default
, plotsize
Other devsize: as.size
,
devsize.default
, devsize
,
unscaled.default
, unscaled
Determines the size of an unscaled device. Generic, with default method.
unscaled(x, ...)
unscaled(x, ...)
x |
object |
... |
other arguments |
Other generic functions: as.size
,
devsize
, plotsize
Other devsize: as.size
,
devsize.default
, devsize
,
print.size
, unscaled.default
example(plotsize.default)
example(plotsize.default)
Determines the size of an unscaled device. Width and height are interpreted directly as device dimensions rather than plot dimensions.
## Default S3 method: unscaled(x, width, height, ...)
## Default S3 method: unscaled(x, width, height, ...)
x |
object |
width |
desired width in inches |
height |
desired height in inches |
... |
other arguments |
Other devsize: as.size
,
devsize.default
, devsize
,
print.size
, unscaled