% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/chunk_images.R
\name{gg_chunk}
\alias{gg_chunk}
\title{ggplot chunk}
\usage{
gg_chunk(value, width = 1, height = 0.2, unit = "in", res = 300, alt = "")
}
\arguments{
\item{value}{gg objects, stored in a list column; or a list
of 'ggplot' objects.}

\item{width, height}{size of the resulting png file.}

\item{unit}{unit for width and height, one of "in", "cm", "mm".}

\item{res}{resolution of the png image in ppi}

\item{alt}{alternative text for the image (used for accessibility)}
}
\description{
This function is used to insert mini gg plots into
flextable with functions:
\itemize{
\item \code{\link[=compose]{compose()}} and \code{\link[=as_paragraph]{as_paragraph()}},
\item \code{\link[=append_chunks]{append_chunks()}},
\item \code{\link[=prepend_chunks]{prepend_chunks()}}.
}
}
\note{
This chunk option requires package officedown in a R Markdown
context with Word output format. With Quarto (\code{format: docx}) or
\code{rmarkdown::word_document()}, the resulting file must be repaired
with \code{\link[=repair_docx]{repair_docx()}}.

PowerPoint cannot mix images and text in a paragraph, images
are removed when outputing to PowerPoint format.
}
\examples{
library(data.table)
library(flextable)
if (require("ggplot2")) {
  my_cor_plot <- function(x) {
    cols <- colnames(x)[sapply(x, is.numeric)]
    x <- x[, .SD, .SDcols = cols]
    cormat <- as.data.table(cor(x))
    cormat$var1 <- colnames(cormat)
    cormat <- melt(cormat,
      id.vars = "var1", measure.vars = cormat$var1,
      variable.name = "var2", value.name = "correlation"
    )
    ggplot(data = cormat, aes(x = var1, y = var2, fill = correlation)) +
      geom_tile() +
      coord_equal() +
      scale_fill_gradient2(
        low = "blue",
        mid = "white", high = "red", limits = c(-1, 1),
        guide = "none"
      ) +
      theme_void()
  }
  z <- as.data.table(iris)
  z <- z[, list(gg = list(my_cor_plot(.SD))), by = "Species"]
  ft <- flextable(z)
  ft <- mk_par(ft,
    j = "gg",
    value = as_paragraph(
      gg_chunk(value = gg, width = 1, height = 1)
    )
  )
  ft
}
}
\seealso{
Other chunk elements for paragraph:
\code{\link[=as_b]{as_b()}},
\code{\link[=as_bracket]{as_bracket()}},
\code{\link[=as_chunk]{as_chunk()}},
\code{\link[=as_equation]{as_equation()}},
\code{\link[=as_highlight]{as_highlight()}},
\code{\link[=as_i]{as_i()}},
\code{\link[=as_image]{as_image()}},
\code{\link[=as_qmd]{as_qmd()}},
\code{\link[=as_strike]{as_strike()}},
\code{\link[=as_sub]{as_sub()}},
\code{\link[=as_sup]{as_sup()}},
\code{\link[=as_word_field]{as_word_field()}},
\code{\link[=colorize]{colorize()}},
\code{\link[=grid_chunk]{grid_chunk()}},
\code{\link[=hyperlink_text]{hyperlink_text()}},
\code{\link[=linerange]{linerange()}},
\code{\link[=minibar]{minibar()}},
\code{\link[=plot_chunk]{plot_chunk()}}
}
\concept{chunk elements for paragraph}
