Learn R Programming

blastula (version 0.2.1)

add_ggplot: Helper function for adding an ggplot

Description

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

Usage

add_ggplot(plot_object, width = 5, height = 5)

Arguments

plot_object

the ggplot plot object.

width

the width of the output plot in inches.

height

the height of the output plot in inches.

Value

a character object with an HTML fragment that can be placed inside the message body wherever the plot image should appear.

Examples

Run this code
# NOT RUN {
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,
    height = 5,
    width = 7)

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

  Here is a very important plot \\
  that will change the way you \\
  look at cars forever.

  {plot_html}

  So useful, right?
  ") %>% preview_email()
# }

Run the code above in your browser using DataLab