body_add_gg: add ggplot

Description Usage Arguments Examples

View source: R/docx_add.R

Description

add a ggplot as a png image into an rdocx object

Usage

1
body_add_gg(x, value, width = 6, height = 5, style = NULL, ...)

Arguments

x

an rdocx object

value

ggplot object

width

height in inches

height

height in inches

style

paragraph style

...

Arguments to be passed to png function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
if( require("ggplot2") ){
  doc <- read_docx()

  gg_plot <- ggplot(data = iris ) +
    geom_point(mapping = aes(Sepal.Length, Petal.Length))

  if( capabilities(what = "png") )
    doc <- body_add_gg(doc, value = gg_plot, style = "centered" )

  print(doc, target = tempfile(fileext = ".docx") )
}

Example output

Loading required package: ggplot2
[1] "/work/tmp/tmp/RtmppbCh3M/file74ea6848e103.docx"

officer documentation built on July 24, 2018, 9:02 a.m.