add object into a new shape in the current slide. This
function is able to add all supported outputs to a presentation
and should replace calls to older functions starting with
ph_with_*
.
ph_with(x, value, location, ...)# S3 method for character
ph_with(x, value, location, ...)
# S3 method for numeric
ph_with(x, value, location, format_fun = format, ...)
# S3 method for factor
ph_with(x, value, location, ...)
# S3 method for logical
ph_with(x, value, location, format_fun = format, ...)
# S3 method for block_list
ph_with(x, value, location, is_list = FALSE, ...)
# S3 method for unordered_list
ph_with(x, value, location, ...)
# S3 method for data.frame
ph_with(
x,
value,
location,
header = TRUE,
first_row = TRUE,
first_column = FALSE,
last_row = FALSE,
last_column = FALSE,
...
)
# S3 method for gg
ph_with(x, value, location, res = 300, ...)
# S3 method for plot_instr
ph_with(x, value, location, res = 300, ...)
# S3 method for external_img
ph_with(x, value, location, use_loc_size = TRUE, ...)
# S3 method for fpar
ph_with(x, value, location, ...)
# S3 method for empty_content
ph_with(x, value, location, ...)
# S3 method for xml_document
ph_with(x, value, location, ...)
an rpptx object
object to add as a new shape. Supported objects are vectors, data.frame, graphics, block of formatted paragraphs, unordered list of formatted paragraphs, pretty tables with package flextable, editable graphics with package rvg, 'Microsoft' charts with package mschart.
a placeholder location object.
It will be used to specify the location of the new shape. This location
can be defined with a call to one of the ph_location functions. See
section "see also"
.
further arguments passed to or from other methods. When
adding a ggplot
object or plot_instr
, these arguments will be used
by png function.
format function for non character vectors
experimental paramater to make block_list formated as an unordered list. This should evolve in the next versions.
display header if TRUE
logical for PowerPoint table options
resolution of the png image in ppi
if set to FALSE, external_img width and height will be used.
character
: add a character vector to a new shape on the
current slide, values will be added as paragraphs.
numeric
: add a numeric vector to a new shape on the
current slide, values will be be first formatted then
added as paragraphs.
factor
: add a factor vector to a new shape on the
current slide, values will be be converted as character and then
added as paragraphs.
block_list
: add a block_list
made
of fpar
to a new shape on the current slide.
unordered_list
: add a unordered_list
made
of fpar
to a new shape on the current slide.
data.frame
: add a data.frame to a new shape on the current slide. Use
package flextable
instead for more advanced formattings.
gg
: add a ggplot object to a new shape on the
current slide. Use package rvg
for more advanced graphical features.
plot_instr
: add an R plot to a new shape on the
current slide. Use package rvg
for more advanced graphical features.
external_img
: add a external_img
to a new shape
on the current slide.
When value is a external_img object, image will be copied
into the PowerPoint presentation. The width and height
specified in call to external_img
will be
ignored, their values will be those of the location,
unless use_loc_size is set to FALSE.
fpar
: add an fpar
to a new shape
on the current slide as a single paragraph in a block_list
.
empty_content
: add an empty_content
to a new shape
on the current slide.
xml_document
: add an xml_document object to a new shape on the
current slide. This function is to be used to add custom openxml code.
ph_location_type, ph_location, ph_location_label, ph_location_left, ph_location_right, ph_location_fullsize, ph_location_template
# NOT RUN {
fileout <- tempfile(fileext = ".pptx")
doc <- read_pptx()
doc <- add_slide(doc, layout = "Two Content",
master = "Office Theme")
doc <- ph_with(x = doc, value = c("Un titre", "Deux titre"),
location = ph_location_left() )
doc <- ph_with(x = doc, value = iris[1:4, 3:5],
location = ph_location_right() )
anyplot <- plot_instr(code = {
barplot(1:5, col = 2:6)
})
doc <- add_slide(doc)
doc <- ph_with(
doc, anyplot,
location = ph_location_fullsize(),
bg = "#00000066", pointsize = 12)
if( require("ggplot2") ){
doc <- add_slide(doc)
gg_plot <- ggplot(data = iris ) +
geom_point(mapping = aes(Sepal.Length, Petal.Length),
size = 3) +
theme_minimal()
doc <- ph_with(x = doc, value = gg_plot,
location = ph_location_fullsize(),
bg = "transparent" )
doc <- ph_with(x = doc, value = "graphic title",
location = ph_location_type(type="title") )
}
doc <- add_slide(doc, layout = "Title and Content",
master = "Office Theme")
img.file <- file.path( R.home("doc"), "html", "logo.jpg" )
doc <- ph_with(x = doc, external_img(img.file, 100/72, 76/72),
location = ph_location_right(), use_loc_size = FALSE )
svg_file <- file.path(R.home(component = "doc"), "html/Rlogo.svg")
if( require("rsvg") ){
doc <- ph_with(x = doc, external_img(svg_file),
location = ph_location_left(),
use_loc_size = TRUE )
}
# block list ------
bl <- block_list(
fpar(ftext("hello world", shortcuts$fp_bold(color = "pink"))),
fpar(
ftext("hello", shortcuts$fp_bold()),
ftext("hello", shortcuts$fp_italic(color="red"))
))
doc <- add_slide(doc)
doc <- ph_with(x = doc, value = bl,
location = ph_location_type(type="body") )
# fpar ------
hw <- fpar(ftext("hello world", shortcuts$fp_bold(color = "pink")))
doc <- add_slide(doc)
doc <- ph_with(x = doc, value = hw,
location = ph_location_type(type="body") )
# unordered_list ----
ul <- unordered_list(
level_list = c(1, 2, 2, 3, 3, 1),
str_list = c("Level1", "Level2", "Level2", "Level3", "Level3", "Level1"),
style = fp_text(color = "red", font.size = 0) )
doc <- add_slide(doc)
doc <- ph_with(x = doc, value = ul,
location = ph_location_fullsize() )
print(doc, target = fileout )
# }
Run the code above in your browser using DataLab