PPT.AddShape: Add various shapes

View source: R/shapes.R

PPT.AddShapeR Documentation

Add various shapes

Description

Add various shapes to a slide. YOu can position it and modify a limited number of aspects of its appearance (color etc.). However, not all the parameters for all shapes can be implemented.

Usage

PPT.AddShape(
  ppt,
  shape.type = 1,
  top = 0.05,
  left = 0.05,
  width = 0.9,
  height = 0.9,
  fill.color = "grey",
  fill.transparency = 0,
  line.color = "black",
  line.type = 1,
  line.size = 1,
  maxscale = 1,
  newslide = FALSE
)

Arguments

ppt

The ppt object as used in R2PPT.

shape.type

The shape to add. The possible types are documented in the MsoAutoShapeType enumeration in Microsoft's MSDN docu (e.g. rectangle = 1, rounded rectangle = 5, left arrow = 34).

top, left

Vertical and horizontal placement of the shape. Either as fraction of slides dimensions or as pixel value. Values bigger than maxscale are interpreted as pixels.#'

width, height

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

fill.color

Background color either as hex value or R color name.

fill.transparency

Transparency of filling ([0,1], default is 0 = opaque.).

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).

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.

newslide

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

Author(s)

Mark Heckmann

Examples

## Not run: 

# open new PPT presentation
p <- PPT.Init(visible=T, method = "RDCOMClient")  


## EXAMPLE 1 ##

# Look up the shape type number in the "MsoAutoShapeType enumeration". 
# It is one integer, e.g. rectangle = 1, just google it.

p <- PPT.AddBlankSlide(p)
# add a rectangle
p <- PPT.AddShape(p, shape.type= 1, height=.4, width =.4, left=.05, top=.05)
# add a rounded rectangle
p <- PPT.AddShape(p, shape.type= 5, height=.4, width =.4, left=.05, top=.55)
# add a triangle 
p <- PPT.AddShape(p, shape.type= 7, height=.4, width =.4, left=.55, top=.05)
# add a smiley
p <- PPT.AddShape(p, shape.type= 17, height=.4, width =.4, left=.55, top=.55)



## EXAMPLE 2 ##

# add many type of shapes on one slide in two loops to get an 
# overview what shapes exist. The fill and line parameters are 
# randomly modified to get a variety of shapes.
p <- PPT.AddBlankSlide(p)
cols <- colors()   # all named R colors
i <- 0             # counter
set.seed(0)        # make sampling redproducible

# loop over left and top to alter position of shape
for ( left in seq(.05, .85, by=.1) ) {
  for ( top in seq(.05, .85, by=.1) ) {
    i <- i + 1
    p <- PPT.AddShape(p, 
                      shape.type= i,                               # go though shapes one by one 1,2,....
                      height=.08, width =.08,                      # height and width of shape
                      left=left, top=top,                          # shape position is modified in each loop 
                      fill.transparency = sample(c(0,.3, .7), 1),  # use different transparencies
                      fill.color = cols[i],                        # go through all colors for filling
                      line.color = sample(cols, 1),                # random line color
                      line.size = sample(1:30/10, 1),              # random line size
                      line.type = sample(1:8, 1)                   # random line type
                      )
  }
}



## End(Not run)


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