Set up a chunk hook for manually saved plots.
library(knitr)
knit_hooks$set(custom.plot = hook_plot_custom)
A single plot.
library(ggplot2)
qplot(speed, dist, data = cars)
gridSVG::grid.export(fig_path(".svg"))
library(ggplot2)
p = qplot(speed, dist, data = cars)
p + geom_smooth()
gridSVG::grid.export(fig_path("1.svg"))
p + geom_jitter()
gridSVG::grid.export(fig_path("2.svg"))
See the source document of this post at http://stackoverflow.com/q/23852753/559676