Function to create a plot specification that can be
added as content to a report. The
create_plot function can
be used to include charts, graphs, and figures on a statistical report.
The function only supports plot objects returned by
It does not support the Base R
create_plot(x, height, width)
The height of the plot in the specified units of measure.
The width of the plot in the specified units of measure.
The plot specification.
To add a plot to a report, use the
create_plot function. The
function allows you to set a width and height for the plot. The
function will preserve any other geometries you apply to the plot. See
add_content function to control page breaking and
blanks spaces above or below the plot.
A plot specification accepts a
page_by function. If a page by
is applied to the plot, the plot data will be subset by the page by
variable, and re-run for each subset.
library(reporter) library(ggplot2) library(magrittr) # Create temp file path tmp <- file.path(tempdir(), "mtcars.rtf") # Create ggplot p <- ggplot(mtcars, aes(x=cyl, y=mpg)) + geom_point() # Create plot object plt <- create_plot(p, height = 4, width = 8) rpt <- create_report(tmp, output_type = "RTF") %>% page_header("Client", "Study: XYZ") %>% titles("Figure 1.0", "MTCARS Miles per Cylinder Plot") %>% set_margins(top = 1, bottom = 1) %>% add_content(plt) %>% footnotes("* Motor Trend, 1974") %>% page_footer("Time", "Confidential", "Page [pg] of [tpg]") # Write out report write_report(rpt) # Uncomment to view RTF file # shell.exec(tmp)