Skip to content

Commit 1f27ffe

Browse files
authored
Update ggsave docs (#5351)
1 parent 6e78749 commit 1f27ffe

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

R/save.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626
#' @param plot Plot to save, defaults to last plot displayed.
2727
#' @param device Device to use. Can either be a device function
2828
#' (e.g. [png]), or one of "eps", "ps", "tex" (pictex),
29-
#' "pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf" (windows only).
29+
#' "pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf" (windows only). If
30+
#' `NULL` (default), the device is guessed based on the `filename` extension.
3031
#' @param path Path of the directory to save plot to: `path` and `filename`
3132
#' are combined to create the fully qualified file name. Defaults to the
3233
#' working directory.
3334
#' @param scale Multiplicative scaling factor.
34-
#' @param width,height,units Plot size in `units` ("in", "cm", "mm", or "px").
35-
#' If not supplied, uses the size of current graphics device.
35+
#' @param width,height Plot size in units expressed by the `units` argument.
36+
#' If not supplied, uses the size of the current graphics device.
37+
#' @param units One of the following units in which the `width` and `height`
38+
#' arguments are expressed: `"in"`, `"cm"`, `"mm"` or `"px"`.
3639
#' @param dpi Plot resolution. Also accepts a string input: "retina" (320),
3740
#' "print" (300), or "screen" (72). Applies only to raster output types.
3841
#' @param limitsize When `TRUE` (the default), `ggsave()` will not
@@ -48,12 +51,17 @@
4851
#' ggplot(mtcars, aes(mpg, wt)) +
4952
#' geom_point()
5053
#'
54+
#' # here, the device is inferred from the filename extension
5155
#' ggsave("mtcars.pdf")
5256
#' ggsave("mtcars.png")
5357
#'
58+
#' # setting dimensions of the plot
5459
#' ggsave("mtcars.pdf", width = 4, height = 4)
5560
#' ggsave("mtcars.pdf", width = 20, height = 20, units = "cm")
5661
#'
62+
#' # passing device-specific arguments to '...'
63+
#' ggsave("mtcars.pdf", colormodel = "cmyk")
64+
#'
5765
#' # delete files with base::unlink()
5866
#' unlink("mtcars.pdf")
5967
#' unlink("mtcars.png")
@@ -138,7 +146,6 @@ parse_dpi <- function(dpi, call = caller_env()) {
138146

139147
plot_dim <- function(dim = c(NA, NA), scale = 1, units = "in",
140148
limitsize = TRUE, dpi = 300, call = caller_env()) {
141-
142149
units <- arg_match0(units, c("in", "cm", "mm", "px"))
143150
to_inches <- function(x) x / c(`in` = 1, cm = 2.54, mm = 2.54 * 10, px = dpi)[units]
144151
from_inches <- function(x) x * c(`in` = 1, cm = 2.54, mm = 2.54 * 10, px = dpi)[units]

man/ggsave.Rd

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)