-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
reporter-figure.Rmd
65 lines (50 loc) · 1.69 KB
/
reporter-figure.Rmd
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: "Example 11: Figure"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Example 11: Figure}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
### Create a Report with a Figure
RTF, PDF, HTML, and DOCX also support plots produced with the ggplot2 package. Use
the `create_plot()` function to create plot content for a report. The
plot can be added to the report with the `add_content()` function, just
like tables and text.
If you want to add a custom image from another charting
package, you may also pass a path to a JPEG file on the `create_plot()` function.
The `write_report()` function will then get the image and insert it into
the report at the specified location.
```{r eval=FALSE, echo=TRUE}
library(reporter)
library(ggplot2)
# Create temporary path
tmp <- file.path(tempdir(), "example10.pdf")
# Prepare data
dat <- mtcars[order(mtcars$cyl), ]
# Generate plot
p <- ggplot(dat, aes(x=disp, y=mpg)) + geom_point()
# Define plot object
plt <- create_plot(p, height = 4, width = 8) %>%
titles("Figure 1.0", "MTCARS Mileage By Displacement", blank_row = "none") %>%
footnotes("* Motor Trend, 1974")
# Add plot to report
rpt <- create_report(tmp, output_type = "PDF") %>%
set_margins(top = 1, bottom = 1) %>%
options_fixed(font_size = 12) %>%
page_header("Sponsor", "Study: cars") %>%
add_content(plt) %>%
page_footer(Sys.time(), "Confidential", "Page [pg] of [tpg]")
# Write out report
res <- write_report(rpt)
# View report
# file.show(tmp)
```
<img src="../man/images/plot.png"/>
Next: [Example 12: Styles and Themes](reporter-styles.html)