plot_gridSVG <- function( plot, ... ) {
# Arguments to either withold or modify
params <- c( "plot")
fun <- match.call()
args <- match( params, names( fun ), 0L )
names( args ) <- params
# Modify the original function and set to call gridsvg.
fun <- fun[ -args[c("plot")] ]
fun[[1]] <- as.name('gridsvg')
# Do the deed.
eval(fun)
print( plot )
dev.off()
}
# A ggplot to test
set.seed(1410) # Make the sample reproducible
dsmall <- diamonds[sample(nrow(diamonds), 100), ]
ggplot_spec <-
qplot(carat, price, data = dsmall, geom = c("point", "smooth"), span = 0.2)
# Default
suppressMessages( plot_gridSVG( plot = ggplot_spec, name = "ggplot_svg_default.svg") )
# Modified - when width and height are not present and a viewport is they are
# treated as 100% and setting, and the aspect ratio allows stretching.
rootAttrs <- list( width=NULL, height=NULL, preserveAspectRatio="none")
suppressMessages(
plot_gridSVG( plot = ggplot_spec, name = "ggplot_svg_attrs.svg",
rootAttrs = rootAttrs) )