EVOLUTION-MANAGER
Edit File: ggsave.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Save a ggplot (or other grid object) with sensible defaults</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for ggsave {ggplot2}"><tr><td>ggsave {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Save a ggplot (or other grid object) with sensible defaults</h2> <h3>Description</h3> <p><code>ggsave()</code> is a convenient function for saving a plot. It defaults to saving the last plot that you displayed, using the size of the current graphics device. It also guesses the type of graphics device from the extension. </p> <h3>Usage</h3> <pre> ggsave( filename, plot = last_plot(), device = NULL, path = NULL, scale = 1, width = NA, height = NA, units = c("in", "cm", "mm"), dpi = 300, limitsize = TRUE, ... ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>filename</code></td> <td> <p>File name to create on disk.</p> </td></tr> <tr valign="top"><td><code>plot</code></td> <td> <p>Plot to save, defaults to last plot displayed.</p> </td></tr> <tr valign="top"><td><code>device</code></td> <td> <p>Device to use. Can either be a device function (e.g. <code><a href="../../grDevices/html/png.html">png()</a></code>), or one of "eps", "ps", "tex" (pictex), "pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf" (windows only).</p> </td></tr> <tr valign="top"><td><code>path</code></td> <td> <p>Path of the directory to save plot to: <code>path</code> and <code>filename</code> are combined to create the fully qualified file name. Defaults to the working directory.</p> </td></tr> <tr valign="top"><td><code>scale</code></td> <td> <p>Multiplicative scaling factor.</p> </td></tr> <tr valign="top"><td><code>width, height, units</code></td> <td> <p>Plot size in <code>units</code> ("in", "cm", or "mm"). If not supplied, uses the size of current graphics device.</p> </td></tr> <tr valign="top"><td><code>dpi</code></td> <td> <p>Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Applies only to raster output types.</p> </td></tr> <tr valign="top"><td><code>limitsize</code></td> <td> <p>When <code>TRUE</code> (the default), <code>ggsave</code> will not save images larger than 50x50 inches, to prevent the common error of specifying dimensions in pixels.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Other arguments passed on to the graphics device function, as specified by <code>device</code>.</p> </td></tr> </table> <h3>Details</h3> <p>Note: Filenames with page numbers can be generated by including a C integer format expression, such as <code style="white-space: pre;">%03d</code> (as in the default file name for most R graphics devices, see e.g. <code><a href="../../grDevices/html/png.html">png()</a></code>). Thus, <code>filename = "figure%03d.png"</code> will produce successive filenames <code>figure001.png</code>, <code>figure002.png</code>, <code>figure003.png</code>, etc. To write a filename containing the <code style="white-space: pre;">%</code> sign, use <code>%%</code>. For example, <code>filename = "figure-100%%.png"</code> will produce the filename <code style="white-space: pre;">figure-100%.png</code>. </p> <h3>Saving images without ggsave()</h3> <p>In most cases <code>ggsave()</code> is the simplest way to save your plot, but sometimes you may wish to save the plot by writing directly to a graphics device. To do this, you can open a regular R graphics device such as <code>png()</code> or <code>pdf()</code>, print the plot, and then close the device using <code>dev.off()</code>. This technique is illustrated in the examples section. </p> <h3>Examples</h3> <pre> ## Not run: ggplot(mtcars, aes(mpg, wt)) + geom_point() ggsave("mtcars.pdf") ggsave("mtcars.png") ggsave("mtcars.pdf", width = 4, height = 4) ggsave("mtcars.pdf", width = 20, height = 20, units = "cm") # delete files with base::unlink() unlink("mtcars.pdf") unlink("mtcars.png") # specify device when saving to a file with unknown extension # (for example a server supplied temporary file) file <- tempfile() ggsave(file, device = "pdf") unlink(file) # save plot to file without using ggsave p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() png("mtcars.png") print(p) dev.off() ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>