R Graphics Devices for 'Office' Vector Graphics Output

Vector Graphics devices for 'Microsoft PowerPoint' and 'Microsoft Excel'. Functions extending package 'officer' are provided to embed 'DrawingML' graphics into 'Microsoft PowerPoint' presentations and 'Microsoft Excel' workbooks.


rvg package

R-CMD-check version cranlogs

rvg provides two graphics devices that produce Vector Graphics outputs in DrawingML format for Microsoft PowerPoint with dml_pptx() and for Microsoft Excel with dml_xlsx(). These formats let users edit the graphic elements (editable graphics) within PowerPoint or Excel and have a very good rendering.

These raw XML outputs cannot be used as is. The dml() function is a simple wrapper that marks plot instructions as Vector Graphics instructions, so they can be added to an Office document via officer:

  • in PowerPoint with officer::ph_with()
  • in Excel with officer::sheet_add_drawing()
library(rvg)
library(ggplot2)
library(officer)

my_vec_graph <- dml(code = barplot(1:5, col = 2:6))

doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with(doc, my_vec_graph, location = ph_location_fullsize())
print(doc, target = "my_plot.pptx")

For Excel workbooks, pass a dml() object to officer::sheet_add_drawing():

doc <- read_xlsx()
doc <- sheet_add_drawing(doc, sheet = "Feuil1",
  value = dml(code = barplot(1:5, col = 2:6)),
  left = 1, top = 2, width = 6, height = 6)
print(doc, target = "vg.xlsx")

By default, these graphics are editable; element edition can be disabled with option editable = FALSE.

Note that xl_add_vg() will be deprecated in favor of officer::sheet_add_drawing().

Installation

You can get the development version from GitHub:

devtools::install_github("davidgohel/rvg")

Install the CRAN version:

install.packages("rvg")

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("rvg")

0.4.2 by David Gohel, 6 months ago


https://ardata-fr.github.io/officeverse/, https://davidgohel.github.io/rvg/


Report a bug at https://github.com/davidgohel/rvg/issues


Browse source code at https://github.com/cran/rvg


Authors: David Gohel [aut, cre] , ArData [cph] , Bob Rudis [ctb] (the javascript code used by function set_attr) , Francois Brunetti [ctb] (clipping algorithms)


Documentation:   PDF Manual  


GPL-3 license


Imports gdtools, grDevices, officer, Rcpp, rlang, systemfonts, xml2

Suggests grid, testthat

Linking to Rcpp, systemfonts

System requirements: libpng


Imported by autoslider.core, bfw, eoffice, export, jsmodule, officedown, presenter, rrtable, survC, thinkr.

Suggested by SUMO, agrobox, autocodebook, diagFDR, esquisse, openxlsx2.


See at CRAN