ph_with_gg: add ggplot to a pptx presentation

Description Usage Arguments Examples

View source: R/ppt_ph_with.R

Description

add a ggplot as a png image into an rpptx object

Usage

1
2
3
4
ph_with_gg(x, value, type = "body", index = 1, width = NULL,
  height = NULL, ...)

ph_with_gg_at(x, value, width, height, left, top, ...)

Arguments

x

a pptx device

value

ggplot object

type

placeholder type

index

placeholder index (integer). This is to be used when a placeholder type is not unique in the current slide, e.g. two placeholders with type 'body'.

width, height

image size in inches

...

Arguments to be passed to png function.

left, top

location of the new shape on the slide

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
if( require("ggplot2") ){
  doc <- read_pptx()
  doc <- add_slide(doc, layout = "Title and Content",
    master = "Office Theme")

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

  if( capabilities(what = "png") ){
    doc <- ph_with_gg(doc, value = gg_plot )
    doc <- ph_with_gg_at(doc, value = gg_plot,
      height = 4, width = 8, left = 4, top = 4 )
  }

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

Example output

Loading required package: ggplot2
[1] "/work/tmp/tmp/RtmpwggIPs/file514724763f47.pptx"

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