The grobblR package allows R users the ability to intuitively create flexible, reproducible PDF reports comprised of aesthetically pleasing tables, images, plots and/or text. This is done by implementing grobs from the grid
and gridExtra
packages.
Within grobblR, the objects able to be converted to a grob are:
ggplot2
objectsNA
)You can install the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("calvinmfloyd/grobblR", build_vignettes = TRUE, force = TRUE)
grob_row()
) and grob-columns (grob_col()
) within the overall grob-layout (grob_layout()
).2 x 2
grid system on a 100mm x 100mm
(millimeters is the default unit in grobblR) page, we would simply write:library(grobblR)
grob_layout(
grob_row(grob_col(1), grob_col(2)),
grob_row(grob_col(3), grob_col(4)),
height = 100,
width = 100
) %>%
view_grob()
grob_row()
’s tell the grob_layout()
that the user wants two rows on the outermost layer, and since there are two grob_col()
’s within each of the grob_row()
’s, the result is a 2 x 2
grid.2 x 2
grid - we could have a layout where the first row has two columns and the second has one:R6
package.grob_layout(
grob_row(
border = TRUE,
grob_col(border = TRUE, 1),
grob_col(border = TRUE, 2)
),
grob_row(
border = TRUE,
grob_col(border = TRUE, 3),
grob_col(
border = TRUE,
grob_row(border = TRUE, grob_col(border = TRUE, 4)),
grob_row(border = TRUE, grob_col(border = TRUE, 5))
)
),
height = 100,
width = 100
) %>%
view_grob()
p
(standing for proportion) parameter within both grob_row()
and grob_col()
.p
is 1, but sizes change if p
differs from that.grob_layout(
grob_row(p = 1, border = TRUE, grob_col('1')),
grob_row(p = 2, border = TRUE, grob_col('2')),
height = 100,
width = 100
) %>%
view_grob()
p = 2
is given twice the height of the grob-row with p = 1
.grob_layout(
grob_row(height = 25, border = TRUE, grob_col('1')),
grob_row(height = 50, border = TRUE, grob_col('2')),
grob_row(height = 25, border = TRUE, grob_col('3')),
height = 100,
width = 100,
padding = 0
) %>%
view_grob()
aes_list
parameter and the ga_list()
function within grob_col()
, the aesthetics of individual grobs can be adjusted to how the user intends them to appear.?grobblR::ga_list
for a full list and description for each of the possible aesthetic options.background_color
as an element within aes_list
:mat = matrix(1:4, nrow = 2, byrow = TRUE)
grob_layout(
grob_row(
grob_col(
mat,
aes_list = ga_list(background_color = "gray90")
)
),
height = 100,
width = 100
) %>%
view_grob()
grob_matrix()
and alter_at()
.alter_at()
once the grob_matrix()
object is initialized.ggplot2
plot is stretched or squished depending on what the dimensions of the allotted space are:data(iris)
library(ggplot2)
gg1 = ggplot(
data = iris,
mapping = aes(
x = Sepal.Length,
y = Sepal.Width,
color = Species
)
) +
geom_point() +
guides(color = FALSE)
gg2 = ggplot(
data = iris,
mapping = aes(
x = Sepal.Length,
y = Petal.Length,
color = Species
)
) +
geom_point() +
guides(color = FALSE)
grob_layout(
grob_row(grob_col(gg1), grob_col(gg2)),
grob_row(grob_col(gg1))
) %>%
view_grob(height = 100, width = 100)
maintain_aspect_ratio = FALSE
must be inserted within the aes_list
list.grob_layout(
grob_row(
border = TRUE,
grob_col(
border = TRUE,
'kings_logo.png'
),
grob_col(
border = TRUE,
aes_list = ga_list(
maintain_aspect_ratio = FALSE
),
'https://raw.githubusercontent.com/calvinmfloyd/grobblR/master/vignettes/kings_logo.png'
)
),
height = 100,
width = 100
) %>%
view_grob()
grob_image()
and add_structure()
.grob_layout(
grob_row(
border = TRUE,
grob_col(
border = TRUE,
'kings_logo.png'
),
grob_col(
border = TRUE,
'https://raw.githubusercontent.com/calvinmfloyd/grobblR/master/vignettes/kings_logo.png' %>%
grob_image() %>%
add_structure("maintain_aspect_ratio", FALSE)
)
),
height = 100,
width = 100
) %>%
view_grob()
text = "The quick brown fox jumps over the lazy dog."
grob_layout(
grob_row(
border = TRUE,
grob_col(
border = TRUE,
text
)
),
height = 100,
width = 100
) %>%
view_grob()
grob_text()
and add_aesthetic()
.height
and width
parameters within grob_layout()
are 280
millimeters and 216
millimeters, as these are the values needed to properly fit the grob-layout onto a piece of standard computer paper, portrait orientation.grob_to_pdf()
, with a file title and a meta data title:first_page_grob_layout = grob_layout(
grob_row(
border = TRUE,
grob_col(df),
grob_col(
grob_row(grob_col(df)),
grob_row(grob_col(p = 1/3, NA))
),
grob_col(
grob_row(grob_col(p = 1/3, NA)),
grob_row(grob_col(df))
)
),
height = 100,
width = 100
)
second_page_grob_layout = grob_layout(
grob_row(
border = TRUE,
grob_col(
border = TRUE,
text
)
),
height = 100,
width = 100
)
# grob_to_pdf(
# first_page_grob_layout,
# second_page_grob_layout,
# file_name = file.path(tempdir(), "test.pdf"),
# meta_data_title = 'Test PDF'
# )
# OR
grob_to_pdf(
list(first_page_grob_layout, second_page_grob_layout),
file_name = file.path(tempdir(), "test.pdf"),
meta_data_title = "Test PDF"
)
The grobblR package provides R users a tool to quickly create dynamic and aesthetically pleasing PDF reports. In the future we hope to enhance and add even more features, but, even as it currently stands, we believe grobblR is a valuable utility in daily data visualization and data reporting tasks.