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
Run the code above in your browser using DataLab