Skip to content

Commit 8fcdd44

Browse files
authored
adds small section to ggsave() on writing to device (#3790)
* adds small section to ggsave() on writing to device * cleans text in saving-without-ggplot section and shifts code to examples section * closes #3755
1 parent b8ce6a9 commit 8fcdd44

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

R/save.r

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
#' containing the `%` sign, use `%%`. For example, `filename = "figure-100%%.png"`
1414
#' will produce the filename `figure-100%.png`.
1515
#'
16+
#' @section Saving images without ggsave():
17+
#'
18+
#' In most cases `ggsave()` is the simplest way to save your plot, but
19+
#' sometimes you may wish to save the plot by writing directly to a
20+
#' graphics device. To do this, you can open a regular R graphics
21+
#' device such as `png()` or `pdf()`, print the plot, and then close
22+
#' the device using `dev.off()`. This technique is illustrated in the
23+
#' examples section.
24+
#'
1625
#' @param filename File name to create on disk.
1726
#' @param plot Plot to save, defaults to last plot displayed.
1827
#' @param device Device to use. Can either be a device function
@@ -51,6 +60,13 @@
5160
#' file <- tempfile()
5261
#' ggsave(file, device = "pdf")
5362
#' unlink(file)
63+
#'
64+
#' # save plot to file without using ggsave
65+
#' p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
66+
#' png("mtcars.png")
67+
#' print(p)
68+
#' dev.off()
69+
#'
5470
#' }
5571
ggsave <- function(filename, plot = last_plot(),
5672
device = NULL, path = NULL, scale = 1,

man/ggsave.Rd

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

0 commit comments

Comments
 (0)