add_new_page: New page

Description Usage Arguments Examples

Description

This function adds a new page to the report where the visual element(s) can be placed.

Usage

1
2
3
4
5
6
7
add_new_page(..., plot = ggplot2::ggplot(), need_header = FALSE,
  need_footer = FALSE, header_color = "#3d3c3c", footer_color = "#f4f4f4",
  logo = NA, logo_size = NULL, footer_text = "", theme = c("basic",
  "flashy"), plot_area_layout = NULL, plot_vpos = 1, plot_hpos = 1,
  extra_layout_params = function() { }, extra_plot_params = function() { },
  title = myprettyreport.env$report_title,
  subtitle = myprettyreport.env$report_subtitle)

Arguments

...

Other arguments passed on to methods. It is only for technical usage.

plot

A ggplot2 object to visualize. Default value is ggplot2() which creates a skeleton ggplot2 object.

need_header

Logical. if TRUE header is needed.

need_footer

Logical. if TRUE footer is needed.

header_color

Character string which specifies the color of the header. Only HEX color codes are accepted (e.g. #ffffff). Default value is "#3d3c3c".

footer_color

Character string which specifies the color of the footer. Only HEX color codes are accepted (e.g. #ffffff). Default value is "#f4f4f4".

logo

Name of the logo file which has been already loaded into R. I recommend to use magick::image_read function to load images into R. Default value is NA which means that nothing will appear in place of the logo.

logo_size

Numeric value which specifies the size of the logo. Default value is NULL which means that the original size of the logo file will be used.

footer_text

Character string value which is implemented mainly for displaying the current page number of the report but it can be used for other purpose. Default value is "".

theme

Character string which specifies the theme of the report. Possible values are "basic" and "flashy". Try both themes and check the differences.

plot_area_layout

Custom layout can be defined with the grid::grid.layout() function. Check the example section for more details.

plot_vpos

Numerical value which specifies the vertical position of the plot. It only works if plot_area_layout parameter is also specified.

plot_hpos

Numerical value which specifies the horizontal position of the plot. It only works if plot_area_layout parameter is also specified.

extra_layout_params

User defined grid functions can be passed in the PDF report to modify the header or the footer region. It has to be defined as a dummy function, see the example section for more details.

extra_plot_params

User defined grid functions can be passed in the PDF report to modify the plot region. It has to be defined as a dummy function, see the example section for more details.

title

Character string which allows to set up user defined title to a single report page. The default value is the previously defined start_report() title parameter.

subtitle

Character string which allows to set up user defined subtitle to a single report page. The default value is the previously defined start_report() subtitle parameter.

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
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
# minimal example
# it generates a PDF file which contains a skeleton ggplot object.
start_report() %>%
  add_new_page() %>%
  end_report()

# add a ggplot2 object to a report
library(ggplot2)
sample_plot <- ggplot(data = mtcars, mapping = aes(x = wt, y = mpg)) +
  geom_point() +
  stat_smooth(method = 'lm')
start_report() %>%
  add_new_page(plot = sample_plot) %>%
  end_report()

# add multiple pages manually to a report
sample_plot2 <- ggplot(mpg, aes(displ, hwy, colour = class)) +
  geom_point()
start_report() %>%
  add_new_page(plot = sample_plot) %>%
  add_new_page(plot = sample_plot2) %>%
  end_report()

# add multiple plot to a single report page
# in this case plot_area_layout and horizontal
# and vertical postion of the plot also have to be defined.
start_report() %>%
  add_new_page(
      plot = list(sample_plot, sample_plot2),
      plot_hpos = c(1, 2),
      plot_vpos = c(1, 2),
      plot_area_layout = grid::grid.layout(2, 2,
                                           width = c(1, 1),
                                           heigh = c(1, 1))
  ) %>%
  end_report()

# alternatively other libraries can be used
# for plotting multiple ggplot objects to a single report page. The result
# will be the same.
library(patchwork)

multiple_plot_one_page <- sample_plot + patchwork::plot_spacer() +
                          patchwork::plot_spacer() + sample_plot2 +
                          patchwork::plot_layout(ncol = 2, nrow = 2)

start_report() %>%
  add_new_page(
    plot = multiple_plot_one_page
  ) %>%
  end_report()
# add extra grid parameters to a report
rp_e_plot_params = function() {
   grid::grid.text("example text")
}
start_report() %>%
  add_new_page(
    plot = sample_plot,
    extra_plot_params = rp_e_plot_params
  ) %>%
  end_report()

tarkomatas/myprettyreport documentation built on May 9, 2019, 7:40 a.m.