Skip to content

Commit 28af4a3

Browse files
committed
document
1 parent bc21069 commit 28af4a3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

R/save.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#' @param scale Multiplicative scaling factor.
3535
#' @param width,height Plot size in units expressed by the `units` argument.
3636
#' If not supplied, uses the size of the current graphics device.
37+
#' Alternatively, these can be set to `derived()` in order to use innate
38+
#' plot dimensions for output. This is useful when the
39+
#' `theme(panel.widths, panel.heights)` options are set to absolute units.
3740
#' @param units One of the following units in which the `width` and `height`
3841
#' arguments are expressed: `"in"`, `"cm"`, `"mm"` or `"px"`.
3942
#' @param dpi Plot resolution. Also accepts a string input: "retina" (320),
@@ -200,6 +203,8 @@ plot_dim <- function(width = NA, height = NA, scale = 1, units = "in",
200203
from_inches <- function(x) x * c(`in` = 1, cm = 2.54, mm = 2.54 * 10, px = dpi)[units]
201204

202205
if (is.derived(width) || is.derived(height)) {
206+
# To size from plot if width or height are derived
207+
# TODO: use gtable::as.gtable when implemented
203208
if (is.ggplot(plot)) {
204209
plot <- ggplotGrob(plot)
205210
}
@@ -216,6 +221,7 @@ plot_dim <- function(width = NA, height = NA, scale = 1, units = "in",
216221

217222
if (is.unit(width)) {
218223
if (has_null_unit(width)) {
224+
# When plot has no absolute dimensions, fall back to device size
219225
width <- NA
220226
} else {
221227
width <- from_inches(convertWidth(width, "in", valueOnly = TRUE))
@@ -224,6 +230,7 @@ plot_dim <- function(width = NA, height = NA, scale = 1, units = "in",
224230

225231
if (is.unit(height)) {
226232
if (has_null_unit(height)) {
233+
# When plot has no absolute dimensions, fall back to device size
227234
height <- NA
228235
} else {
229236
height <- from_inches(convertHeight(height, "in", valueOnly = TRUE))

man/ggsave.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)