PPT.AddGraphicstoSlide2: Adding a graphic to a slide.

View source: R/graphics.R

PPT.AddGraphicstoSlide2R Documentation

Adding a graphic to a slide.

Description

PPT.AddGraphicstoSlide2 is a modified version of PPT.AddGraphicstoSlide from R2PPT. The PPT.AddGraphicstoSlide function has the drawback that it requires the size of the graphic to be supplied by the user. If the size is not supplied correctly, the graphic is deformed. This function keeps the apsect ration intact and offers many additional features for placing the image on the slide.

Usage

PPT.AddGraphicstoSlide2(
  ppt,
  file,
  width = 0.9,
  height = 0.8,
  left = 0.05,
  top = 0.1,
  hjust = 0.5,
  vjust = 0.5,
  frame = list(),
  proportional = TRUE,
  newslide = TRUE,
  maxscale = 1,
  display.frame = FALSE,
  display.image = TRUE,
  line.color = "black",
  line.type = 1,
  line.size = 0,
  shadow.visible = FALSE,
  shadow.type = 21,
  shadow.color = "black",
  shadow.x = 3,
  shadow.y = 3,
  shadow.transparency = 0.6,
  z.order = 0
)

Arguments

ppt

The ppt object as used in R2PPT.

file

Path to the graphic file.

width, height

Width / height of graphic. For values smaller than maxscale (default is 1) refers to a proportion of the current slide's width. Values bigger than maxscale are interpreted as pixels.

top, left

Horizontal und vertical alignment of graphic inside frame. Either a string ("center", "left", "right") or ("center", "top", "bottom") or a numerical value. Numerical values bigger than maxscale are interpreted as absolute pixels, smaller ones as proportions.

hjust, vjust

Horizontal und vertical alignment of image inside frame. Either a string ("center", "left", "right") or ("center", "top", "bottom") or a numerical value between [0,1]. Values bigger than maxscale are used for absolute horizontal und vertical offset.

proportional

Logical (default TRUE). Whether scaling preserves the aspect ratio of the graphic. See details section for additional information.

newslide

Logical (default is TRUE) Whether the graphic will be placed on a new slide.

maxscale

Threshold below which values are interpreted as proportional scaling factors for the width and height argument. Above the threshold values are interpreted as pixels.

display.frame

Add a shape representing the frame into which the image is placed. This makes it easier when developing new slides (default FALSE).

display.image

Whether or not the image should be added (default TRUE).

line.color

Color of text either as hex value or color name.

line.type

1 = solid (default), 2-8= dots, dashes and mixtures. See MsoLineDashStyle Enumeration for details.

line.size

Thickness of line (default1).

shadow.visible

Show shadow (default FALSE).

shadow.type

1-20, see MsoShadowType enumeration (default 21).

shadow.color

Color of shadow (default "black").

shadow.x, shadow.y

Size of shadow.

shadow.transparency

Shadow strength.

z.order

(numeric). Set z-order. An integer corresponding to the MsoZOrderCmd Enum (e.g. 0 = front, 1 = back).

Note

The common use case is to add graphics and scale them while preserving their aspect ratio. In the case this this is not wanted the argument proportional can be set to FALSE. When the aspect ratio is preserved and both arguments width and height are supplied, the graphic is scaled so that it will not exceed the size given by one of these values. This is useful when adding a lot of graphics of different size. Only using width may result in graphics exceeding the slide vertically and vice versa. using both parameters (the default) will cause the graphic to be scaled so it will fit the slide regardless of its dimensions.

Author(s)

Mark Heckmann

Examples

## Not run: 
  
  #### EXAMPLE ####
  
  # add PNG that comes with the packages
  file <- system.file("image_1.png", package = "R2PPTaddons")
  p <- PPT.Init(visible=TRUE, method="RDCOMClient")
  p <- PPT.AddGraphicstoSlide2(p, file)

  # the argument file is vectorized, so it takes multiple images
  folder <- system.file(package = "R2PPTaddons")
  files <- list.files(folder, pattern = ".png", full.names = T)
  p <- PPT.AddGraphicstoSlide2(p, files)    
  
  
  #### MORE EXAMPLES ####
  
  p <- PPT.Init(visible=TRUE, method="RDCOMClient")
  file <- system.file("image_1.png", package = "R2PPTaddons")
  
  # the image is placed within a frame. To get a better understanding
  # what happens first only the frame is displayed. Afterwards the image is added.
  p <- PPT.AddGraphicstoSlide2(p, file, display.frame = TRUE, display.image = FALSE) 
  p <- PPT.AddGraphicstoSlide2(p, file, newslide=F)    
  
  # width and height values smaller than maxscale (default is 1) 
  # are interpreted as a proportions of the slide width/height. Values 
  # greater than 1 are taken as absolute pixel width/height.
  p <- PPT.AddGraphicstoSlide2(p, file, width=.5)
  p <- PPT.AddGraphicstoSlide2(p, file, height=.5)

  # using pixel width/height instead of proportions of 
  # available slide width/height
  p <- PPT.AddGraphicstoSlide2(p, file, width=400)
  p <- PPT.AddGraphicstoSlide2(p, file, width=400, left=0)
  
  # one can also fit the image completely to the frame potentially 
  # destroying the image's aspect ration, i.e. distorting it
  p <- PPT.AddGraphicstoSlide2(p, file, width=400, height=100, proportional=FALSE)
  
  # position the image on slide
  p <- PPT.AddGraphicstoSlide2(p, file, left=0, width =.5)
  p <- PPT.AddGraphicstoSlide2(p, file, top=0, height =.5)
  
  # aligment of image inside the frame
  p <- PPT.AddGraphicstoSlide2(p, file, width=400, display.frame = T)
  p <- PPT.AddGraphicstoSlide2(p, file, width=400, vjust="top",display.frame = T)
  p <- PPT.AddGraphicstoSlide2(p, file, width=400, vjust=0,display.frame = T)
  p <- PPT.AddGraphicstoSlide2(p, file, width=400, vjust="bottom",display.frame = T)
  p <- PPT.AddGraphicstoSlide2(p, file, width=400, vjust=1, display.frame = T)
  p <- PPT.AddGraphicstoSlide2(p, file, width=400, vjust=400, display.frame = T)

## End(Not run)

markheckmann/R2PPTaddons documentation built on Oct. 16, 2023, 8:03 p.m.