graph2bitmap | R Documentation |
Save the currently active R graph or a graph passed as an object or function to bitmap format with sensible defaults
graph2bitmap( x = NULL, file = "Rplot", fun = NULL, type = c("PNG", "JPG", "TIF"), aspectr = NULL, width = NULL, height = NULL, dpi = 300, scaling = 100, font = ifelse(Sys.info()["sysname"] == "Windows", "Arial", "Helvetica")[[1]], bg = "white", cairo = TRUE, tiffcompression = c("lzw", "rle", "jpeg", "zip", "lzw+p", "zip+p"), jpegquality = 99, ... ) graph2png(...) graph2tif(...) graph2jpg(...)
x |
given |
file |
name of output file. Any extension is ignored and added according to the requested output type. If file already exists it is overwritten. |
fun |
plot passed on as a function used to create it; useful especially for base R plots. |
type |
desired output type - |
aspectr |
desired width to height aspect ratio. If set to |
width |
desired width in inches; can be combined with a desired aspect ratio aspectr. |
height |
desired height in inches; can be combined with a desired aspect ratio aspectr. |
dpi |
desired output in dpi; defaults to 600 dpi. |
scaling |
scale width & height by a certain percentage. |
font |
desired font to use for labels in PNG and TIFF output; defaults to
|
bg |
desired background colour, e.g. |
cairo |
logical, specifying whether or not to use |
tiffcompression |
compression to use for |
jpegquality |
quality of |
... |
any other options are passed on to |
No return value
graph2png()
: Save currently active R graph to png file
graph2tif()
: Save currently active R graph to TIF file
graph2jpg()
: Save currently active R graph to JPEG file
Tom Wenseleers
graph2office
, graph2vector
, graph2svg
, graph2pdf
,
graph2eps
# Create a file name filen <- tempfile(pattern = "ggplot") # or # filen <- paste("YOUR_DIR/ggplot") # Generate graphical output library(ggplot2) library(datasets) x <- qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width, alpha = I(0.7)) plot.fun <- function() { print(qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width, alpha = 0.7)) } # There are 3 ways to use graph2bitmap(): ### 1. Pass the plot as an object graph2png(x = x, file = filen, dpi = 400, height = 5, aspectr = 4) graph2tif(x = x, file = filen, dpi = 400, height = 5, aspectr = 4) graph2jpg(x = x, file = filen, dpi = 400, height = 5, aspectr = 4) ### 2. Get the plot from current screen device x graph2png(file = filen, dpi = 400, height = 5, aspectr = 4) graph2tif(file = filen, dpi = 400, height = 5, aspectr = 4) graph2jpg(file = filen, dpi = 400, height = 5, aspectr = 4) ### 3. Pass the plot as a function graph2png(file = filen, fun = plot.fun, dpi = 400, height = 5, aspectr = 4) graph2tif(file = filen, fun = plot.fun, dpi = 400, height = 5, aspectr = 4) graph2jpg(file = filen, fun = plot.fun, dpi = 400, height = 5, aspectr = 4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.