add_multiple_page: Add multiple page

Description Usage Arguments Examples

Description

This function allows us to create multiple report page automatically from a list which contains ggplot objects. It helps to simplify the code when it is required to create multiple report pages to a single report. This function has same parameters as add_new_page() function except plot and page_number parameters.

Usage

1
add_multiple_page(..., plot, page_number = c("default"))

Arguments

...

Other add_new_page() arguments passed on to methods. Check the documentation of add_new_page() function for more details.

plot

A list of ggplot2 objects to visualize.

page_number

Character string value which defines the page number generator method. The default value "default" means that every page will have a page number in the bottom right corner in a format of paste0(seq(first_page, last_page), " / ", last_page). See the example section for more details. Set the value of this paramter to NULL if you want to just ignore this feature.

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
# minimal example
library(ggplot2)
sample_plot <- ggplot(data = mtcars, mapping = aes(x = wt, y = mpg)) +
  geom_point() +
  stat_smooth(method = 'lm')
sample_plot2 <- ggplot(mpg, aes(displ, hwy, colour = class)) +
  geom_point()
plot_list <- list(sample_plot, sample_plot2, ggplot())
start_report() %>%
  add_multiple_page(
    plot = plot_list
  ) %>%
  end_report()

# multiple report page and multiple plot in one page at the same time
# Need to create a list which contains sublists:
plot_list <- list(
  list(sample_plot, sample_plot2),
  list(sample_plot2, sample_plot)
)

start_report() %>%
  add_multiple_page(
    plot = plot_list,
    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()
# custom page number
plot_list <- list(sample_plot, sample_plot2)
custom_page_number <- paste0("page: ", seq(1, length(plot_list)))

start_report() %>%
  add_multiple_page(
    plot = plot_list,
    need_footer = TRUE,
    page_number = custom_page_number
  ) %>%
  end_report()

# ignore automatic page number feature
start_report() %>%
  add_multiple_page(
    plot = plot_list,
    need_footer = TRUE,
    page_number = NULL
  ) %>%
  end_report()

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