add_ggplot: Create an HTML fragment for an embedded ggplot image

Description Usage Arguments Value Examples

View source: R/add_ggplot.R

Description

Add an ggplot plot inside the body of the email with this helper function.

Usage

1
2
3
4
5
6
7
8
add_ggplot(
  plot_object,
  width = 5,
  height = 5,
  alt = NULL,
  align = c("center", "left", "right", "inline"),
  float = c("none", "left", "right")
)

Arguments

plot_object

The ggplot2 plot object.

width

The width of the output plot in inches.

height

The height of the output plot in inches.

alt

Text description of image passed to the alt attribute inside of the image (<img>) tag for use when image loading is disabled and on screen readers. Defaults to the ggplot2 plot object's title, if exists. Override by passing a custom character string or "" for no text.

align

The alignment to be used for the image. If not "inline", the image will appear in its own block, i.e. there will not be text to the left or right of it.

float

The float value to be used for the image. If not "none", text will flow around the image, and the align argument will be ignored.

Value

An HTML fragment that can be placed inside the message body wherever the plot image should appear.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
library(ggplot2)

# Create a ggplot plot
plot <-
  ggplot(
    data = mtcars,
    aes(x = disp, y = hp,
        color = wt, size = mpg)) +
  geom_point()

# Create an HTML fragment that
# contains an the ggplot as an
# embedded plot
plot_html <-
  add_ggplot(plot_object = plot)

# Include the plot in the email
# message body by simply referencing
# the `plot_html` object
email <-
  compose_email(
    body = md(
      c(
"Hello!

Here is a plot that will change
the way you look at cars forever.\n",
plot_html,
"Let me know what you think
about it!"
      )
    )
  )

if (interactive()) email

rich-iannone/blastula documentation built on Oct. 17, 2020, 8:59 p.m.