Title: | Create Tibbles and Lists of 'ggplot' Figures for Reporting |
---|---|
Description: | Create tibbles and lists of 'ggplot' figures that can be modified as easily as regular 'ggplot' figures. Typical use cases are for creating reports or web pages where many figures are needed with different data and similar formatting. |
Authors: | Bill Denney [aut, cre] |
Maintainer: | Bill Denney <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.1.9000 |
Built: | 2024-12-08 20:26:17 UTC |
Source: | https://github.com/billdenney/ggtibble |
%+%
operator from ggplot2
for ggtibble
and gglist
objectsUse the %+%
operator from ggplot2
for ggtibble
and gglist
objects
e1 %+% e2
e1 %+% e2
e1 |
Either a |
e2 |
A plot component (see ?ggplot2:: |
glue()
Extract all expressions to be evaluated by glue()
extract_glue_expr(...)
extract_glue_expr(...)
... |
passed to |
A character vector of expressions to be evaluated
## Not run: extract_glue_expr("foo {character(0)} {bar}") ## End(Not run)
## Not run: extract_glue_expr("foo {character(0)} {bar}") ## End(Not run)
Generate a list of ggplots from a list of data.frames
gglist( data = NULL, mapping = ggplot2::aes(), ..., environment = parent.frame() )
gglist( data = NULL, mapping = ggplot2::aes(), ..., environment = parent.frame() )
data |
A list of data.frames (or similar objects) |
mapping |
Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot. |
... |
Other arguments passed on to methods. Not currently used. |
environment |
A list of ggplot2 objects
mydata <- list( data.frame(x = 1:3, y = 3:1), data.frame(x = 4:7, y = 7:4) ) gglist(mydata, ggplot2::aes(x = x, y = y)) + ggplot2::geom_point()
mydata <- list( data.frame(x = 1:3, y = 3:1), data.frame(x = 4:7, y = 7:4) ) gglist(mydata, ggplot2::aes(x = x, y = y)) + ggplot2::geom_point()
Save a plot or list of plots
ggsave( filename, plot = last_plot(), device = NULL, path = NULL, scale = 1, width = NA, height = NA, units = c("in", "cm", "mm", "px"), dpi = 300, limitsize = TRUE, bg = NULL, create.dir = FALSE, ... ) ## S3 method for class 'gglist' ggsave( filename, plot, device = NULL, path = NULL, scale = 1, width = NA, height = NA, units = c("in", "cm", "mm", "px"), dpi = 300, limitsize = TRUE, bg = NULL, create.dir = FALSE, ... ) ## S3 method for class 'ggtibble' ggsave( filename, plot, device = NULL, path = NULL, scale = 1, width = NA, height = NA, units = c("in", "cm", "mm", "px"), dpi = 300, limitsize = TRUE, bg = NULL, create.dir = FALSE, ... )
ggsave( filename, plot = last_plot(), device = NULL, path = NULL, scale = 1, width = NA, height = NA, units = c("in", "cm", "mm", "px"), dpi = 300, limitsize = TRUE, bg = NULL, create.dir = FALSE, ... ) ## S3 method for class 'gglist' ggsave( filename, plot, device = NULL, path = NULL, scale = 1, width = NA, height = NA, units = c("in", "cm", "mm", "px"), dpi = 300, limitsize = TRUE, bg = NULL, create.dir = FALSE, ... ) ## S3 method for class 'ggtibble' ggsave( filename, plot, device = NULL, path = NULL, scale = 1, width = NA, height = NA, units = c("in", "cm", "mm", "px"), dpi = 300, limitsize = TRUE, bg = NULL, create.dir = FALSE, ... )
filename |
A character string passed to |
plot |
Plot to save, defaults to last plot displayed. |
device |
Device to use. Can either be a device function
(e.g. png), or one of "eps", "ps", "tex" (pictex),
"pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf" (windows only). If
|
path |
Path of the directory to save plot to: |
scale |
Multiplicative scaling factor. |
width , height
|
Plot size in units expressed by the |
units |
One of the following units in which the |
dpi |
Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Applies only to raster output types. |
limitsize |
When |
bg |
Background colour. If |
create.dir |
Whether to create new directories if a non-existing
directory is specified in the |
... |
Other arguments passed on to the graphics device function,
as specified by |
ggsave(gglist)
: Save the figures in a gglist
object
ggsave(ggtibble)
: Save the figures in a ggtibble
object
Make a tibble where one column is the data to plot, one is the gglist, and one is the caption
ggtibble(data, ...) ## S3 method for class 'data.frame' ggtibble( data, mapping = ggplot2::aes(), ..., outercols = group_vars(data), labs = list(), caption = "" )
ggtibble(data, ...) ## S3 method for class 'data.frame' ggtibble( data, mapping = ggplot2::aes(), ..., outercols = group_vars(data), labs = list(), caption = "" )
data |
The data.frame to plot |
... |
Passed to subsequent methods (usually passed to |
mapping |
Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot. |
outercols |
The columns to have outside the nesting |
labs |
Labels to add via |
caption |
The glue specification for creating the caption |
A data.frame with a column named "data_plot" with the data to plot, "figure" with the gglist, and "caption" with the captions
A ggtibble
object which is a tibble with columns named "figure"
which is a gglist
object (a list of ggplots), "data_plot" which is the a
list of data.frames making up the source data used for each individual
plot, "caption" which is the text to use for the plot caption, and all of
the outercols
used for nesting.
ggtibble(data.frame)
: The default method for a data.frame or tibble
d_plot <- data.frame( A = rep(c("foo", "bar"), each = 4), B = 1:8, C = 11:18, Bunit = "mg", Cunit = "km" ) all_plots <- ggtibble( d_plot, ggplot2::aes(x = B, y = C), outercols = c("A", "Bunit", "Cunit"), caption = "All the {A}", labs = list(x = "B ({Bunit})", y = "C ({Cunit})") ) + ggplot2::geom_point() + ggplot2::geom_line() knit_print(all_plots)
d_plot <- data.frame( A = rep(c("foo", "bar"), each = 4), B = 1:8, C = 11:18, Bunit = "mg", Cunit = "km" ) all_plots <- ggtibble( d_plot, ggplot2::aes(x = B, y = C), outercols = c("A", "Bunit", "Cunit"), caption = "All the {A}", labs = list(x = "B ({Bunit})", y = "C ({Cunit})") ) + ggplot2::geom_point() + ggplot2::geom_line() knit_print(all_plots)
Print a ggplot (usually within knit_print.gglist)
## S3 method for class 'gg' knit_print( x, ..., fig_prefix, fig_suffix, filename = NULL, width = 6, height = 4, units = "in" )
## S3 method for class 'gg' knit_print( x, ..., fig_prefix, fig_suffix, filename = NULL, width = 6, height = 4, units = "in" )
x |
The gg object (i.e. a ggplot) |
... |
Ignored |
fig_prefix |
Text to |
fig_suffix |
Any text to add after the figure |
filename |
A filename saving the plot |
width , height
|
Plot size in units expressed by the |
units |
One of the following units in which the |
The gg object, invisibly
Other knitters:
knit_print.gglist()
The filename
argument may be given with an sprintf()
format including
"%d" to allow automatic numbering of the output filenames. Specifically, the
pattern of "%d" with an optional non-negative integer between the "%" and "d"
is searched for and if found, then the filename will be generated using that
sprintf()
format. Note that also means that other requirements for
sprintf()
must be met; for example, if you want a percent sign ("%") in the
filename, it must be doubled so that sprintf returns what is desired.
## S3 method for class 'gglist' knit_print(x, ..., filename = NULL, fig_suffix = "\n\n") ## S3 method for class 'ggtibble' knit_print(x, ...)
## S3 method for class 'gglist' knit_print(x, ..., filename = NULL, fig_suffix = "\n\n") ## S3 method for class 'ggtibble' knit_print(x, ...)
x |
The gglist object |
... |
extra arguments to |
filename |
A filename with an optional "%d" sprintf pattern for saving the plots |
fig_suffix |
Any text to add after the figure |
The list, invisibly
knit_print(ggtibble)
: Print the plots in a ggtibble
object
Other knitters:
knit_print.gg()
# Ensure that each figure is within its own float area mydata <- list( data.frame(x = 1:3, y = 3:1), data.frame(x = 4:7, y = 7:4) ) p <- gglist(mydata, ggplot2::aes(x = x, y = y)) + ggplot2::geom_point() knit_print(p, fig_suffix = "\n\n\\FloatBarrier\n\n")
# Ensure that each figure is within its own float area mydata <- list( data.frame(x = 1:3, y = 3:1), data.frame(x = 4:7, y = 7:4) ) p <- gglist(mydata, ggplot2::aes(x = x, y = y)) + ggplot2::geom_point() knit_print(p, fig_suffix = "\n\n\\FloatBarrier\n\n")
Generate ggplot2 labels based on data in a ggtibble
labs_glue(p, ...)
labs_glue(p, ...)
p |
The ggtibble object |
... |
Named arguments to be used as |
p
with the labels modified
gglist
objectCreate a new gglist
object
new_gglist(x = list())
new_gglist(x = list())
x |
A list of ggplot2 objects to convert into a gglist |
The list verified to be a gglist and with the gglist class
Other New ggtibble objects:
new_ggtibble()
new_gglist(list(NULL, ggplot2::ggplot(data = data.frame())))
new_gglist(list(NULL, ggplot2::ggplot(data = data.frame())))
ggtibble
objectCreate a new ggtibble
object
new_ggtibble(x)
new_ggtibble(x)
x |
A data.frame with a column named "figure" and "caption", and where the "figure" column is a ggtibble. |
The object with a ggtibble class
Other New ggtibble objects:
new_gglist()
new_ggtibble(tibble::tibble(figure = list(ggplot2::ggplot()), caption = ""))
new_ggtibble(tibble::tibble(figure = list(ggplot2::ggplot()), caption = ""))