Learn R Programming

crosstable (version 0.3.2)

body_add_gg2: Alternative to officer::body_add_gg() which uses ggplot syntax

Description

Alternative to officer::body_add_gg() which uses ggplot syntax

Usage

body_add_gg2(
  doc,
  value,
  width = 6,
  height = 5,
  units = getOption("crosstable_units", "in"),
  style = getOption("crosstable_style_image", doc$default_styles$paragraph),
  res = 300,
  ...
)

Arguments

doc

an rdocx object

value

ggplot object

width, height

width and height. Can be abbreviated to w and h.

units

units for width and height

style

paragraph style

res

resolution of the png image in ppi (passed to the argument dpi of ggplot2::ggsave())

...

other arguments to be passed to ggplot2::ggsave()

Value

The docx object doc

Examples

Run this code
# NOT RUN {
if(require("ggplot2") && capabilities(what = "png")){
  library(officer)
  p = ggplot(data = iris ) +
    geom_point(mapping = aes(Sepal.Length, Petal.Length))
  
  options(crosstable_units="cm")
  options(crosstable_style_image="centered")
  doc = read_docx() %>%
    body_add_normal("Text before") %>% 
    body_add_gg2(p, w=14, h=10, scale=1.5) %>% #or units="cm" instead of using options
    body_add_normal("Text after")
  #write_and_open(doc)
}
# }

Run the code above in your browser using DataLab