graph2vector {export} | R Documentation |
Save currently active R graph to vector format
Description
Save the currently active R graph or a graph passed as an object or function to vector format with sensible defaults
Usage
graph2vector(
x = NULL,
file = "Rplot",
fun = NULL,
type = "SVG",
aspectr = NULL,
width = NULL,
height = NULL,
scaling = 100,
font = ifelse(Sys.info()["sysname"] == "Windows", "Arial", "Helvetica")[[1]],
bg = "white",
colormodel = "rgb",
cairo = TRUE,
fallback_resolution = 600,
...
)
graph2svg(...)
graph2pdf(...)
graph2eps(...)
Arguments
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. |
scaling |
scale width & height by a certain percentage. |
font |
desired font to use for labels; defaults to |
bg |
desired background colour, e.g. |
colormodel |
desired colormodel in |
cairo |
logical indicating whether or not to use the |
fallback_resolution |
resolution in dpi to use to rasterize non-supported
vector graphics (e.g. semi-transparent vector elements in |
... |
any other options are passed on to |
Value
No return value
Functions
-
graph2svg()
: Save currently active R graph to SVG format -
graph2pdf()
: Save currently active R graph to PDF format -
graph2eps()
: Save currently active R graph to EPS format
Author(s)
Tom Wenseleers
See Also
graph2office
, graph2bitmap
, graph2png
, graph2tif
, graph2jpg
Examples
# 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 graph2vector():
### 1. Pass the plot as an object
graph2svg(x=x, file=filen, aspectr=2, font = "Times New Roman",
height = 5, bg = "white")
graph2pdf(x=x, file=filen, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2eps(x=x, file=filen, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
### 2. Get the plot from current screen device
if (interactive()) { # Because the example uses screen devices
x
graph2svg(file=filen, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2pdf(file=filen, aspectr=2, font = "Times New Roman",
height = 5, bg = "white")
graph2eps(file=filen, aspectr=2, font = "Times New Roman",
height = 5, bg = "white")
}
### 3. Pass the plot as a function
if (interactive()) { # Because the example uses screen devices
graph2svg(file=filen, fun = plot.fun, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2pdf(file=filen, fun=plot.fun, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
graph2eps(file=filen, fun=plot.fun, aspectr=2, font = "Arial",
height = 5, bg = "transparent")
}