An R6
class defining the configuration for {patchwork}
plot grid used to
create a grid of plots from {tlf}
. It holds values for all relevant
plot properties.
Customizing
You can change the default values present in public fields.
For example, if you want to specify a new position for tags, you will have to do the following:
myPlotGridConfiguration <- PlotGridConfiguration$new()
myPlotGridConfiguration$tagPosition <- TagPositions$right
For more, see examples.
Specifying fonts
A font is a particular set of glyphs (character shapes), differentiated from other fonts in the same family by additional properties such as stroke weight, slant, relative width, etc.
A font face (aka typeface) is the design of lettering, characterized by
variations in size, weight (e.g. bold), slope (e.g. italic), width (e.g.
condensed), and so on. The available font faces can seen using
FontFaces
list.
A font family is a grouping of fonts defined by shared design styles.
The available font families will depend on which fonts have been installed on your computer. This information can be extracted by running the following code:
# install.packages("systemfonts")
library(systemfonts)
system_fonts()
Saving plot
By default, the plots will be shown in plot pane of your IDE, but the plots
can also be saved to a file using the ggplot2::ggsave()
function.
See also
Other PlotConfiguration classes:
AxisConfiguration
,
BackgroundConfiguration
,
BackgroundElement
,
BoxWhiskerPlotConfiguration
,
CumulativeTimeProfilePlotConfiguration
,
DDIRatioPlotConfiguration
,
ExportConfiguration
,
HistogramPlotConfiguration
,
LabelConfiguration
,
LegendConfiguration
,
LineElement
,
ObsVsPredPlotConfiguration
,
PKRatioPlotConfiguration
,
PieChartPlotConfiguration
,
PlotConfiguration
,
QQPlotConfiguration
,
ResVsPredPlotConfiguration
,
ResVsTimePlotConfiguration
,
TimeProfilePlotConfiguration
,
TornadoPlotConfiguration
,
XAxisConfiguration
,
YAxisConfiguration
Super class
ospsuite.utils::Printable
-> PlotGridConfiguration
Public fields
plotList
A list containing
ggplot
objects.title, subtitle, caption
Text strings to use for the various plot annotations, where plot refers to the grid of plots as a whole.
titleColor, titleSize, titleFontFace, titleFontFamily, titleHorizontalJustification, titleVerticalJustification, titleAngle, titleMargin
Aesthetic properties for the plot title.
subtitleColor, subtitleSize, subtitleFontFace, subtitleFontFamily, subtitleHorizontalJustification, subtitleVerticalJustification, subtitleAngle, subtitleMargin
Aesthetic properties for the plot subtitle.
captionColor, captionSize, captionFontFace, captionFontFamily, captionHorizontalJustification, captionVerticalJustification, captionAngle, captionMargin
Aesthetic properties for the plot caption.
tagLevels
A character vector defining the enumeration format to use at each level. Possible values are
'a'
for lowercase letters,'A'
for uppercase letters,'1'
for numbers,'i'
for lowercase Roman numerals, and'I'
for uppercase Roman numerals. It can also be a list containing character vectors defining arbitrary tag sequences. If any element in the list is a scalar and one of'a'
,'A'
,'1'
,'i
, or'I'
, this level will be expanded to the expected sequence.tagPrefix, tagSuffix
Strings that should appear before or after the tag.
tagSeparator
A separator between different tag levels.
tagPosition
Position of the tag for an individual plot with respect to that plot. Default is topleft. For all available options, see
TagPositions
.tagColor, tagSize, tagFontFamily, tagFontFace, tagHorizontalJustification, tagVerticalJustification, tagAngle, tagLineHeight, tagMargin
Aesthetic properties of individual plot tag text. For more detailed description of each aesthetic property, see docs for element_text().
nColumns, nRows
The dimensions of the grid to create - if both are
NULL
it will use the same logic as facet_wrap() to set the dimensionsbyRow
Analogous to
byrow
in matrix(). IfFALSE
the plots will be filled in in column-major order.widths, heights
The relative widths and heights of each column and row in the grid. Will get repeated to match the dimensions of the grid.
guides
A string specifying how guides should be treated in the layout.
'collect'
will collect guides below to the given nesting level, removing duplicates.'keep'
will stop collection at this level and let guides be placed alongside their plot.auto
will allow guides to be collected if a upper level tries, but place them alongside the plot if not. If you modify default guide "position" with theme(legend.position=...) while also collecting guides you must apply that change to the overall patchwork.design
Specification of the location of areas in the layout. Can either be specified as a text string or by concatenating calls to
area()
together. See the examples in wrap_plots() for further information on use.
Active bindings
title, subtitle, caption
Text strings to use for the various plot annotations, where plot refers to the grid of plots as a whole.
titleColor, titleSize, titleFontFace, titleFontFamily, titleHorizontalJustification, titleVerticalJustification, titleAngle, titleMargin
Aesthetic properties for the plot title.
subtitleColor, subtitleSize, subtitleFontFace, subtitleFontFamily, subtitleHorizontalJustification, subtitleVerticalJustification, subtitleAngle, subtitleMargin
Aesthetic properties for the plot subtitle.
captionColor, captionSize, captionFontFace, captionFontFamily, captionHorizontalJustification, captionVerticalJustification, captionAngle, captionMargin
Aesthetic properties for the plot caption.
tagPrefix, tagSuffix
Strings that should appear before or after the tag.
tagColor, tagSize, tagFontFamily, tagFontFace, tagHorizontalJustification, tagVerticalJustification, tagAngle, tagLineHeight, tagMargin
Aesthetic properties of individual plot tag text. For more detailed description of each aesthetic property, see docs for element_text().
nColumns, nRows
The dimensions of the grid to create - if both are
NULL
it will use the same logic as facet_wrap() to set the dimensionswidths, heights
The relative widths and heights of each column and row in the grid. Will get repeated to match the dimensions of the grid.
Methods
Method new()
Create an instance of PlotGridConfiguration
class.
Usage
PlotGridConfiguration$new(plotList = NULL)
Method addPlots()
Add a plot object.
Examples
library(ggplot2)
myPlotGrid <- PlotGridConfiguration$new()
# You can add a single ggplot object
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
myPlotGrid$addPlots(p)
# Or you can also pass a list
myPlotGrid$addPlots(list("p1" = ggplot(), "p2" = ggplot()))
# Since we added three plots, the `plotList` field should
# now be a list of length `3`
length(myPlotGrid$plotList)
Examples
library(tlf)
# create a list of plots
ls_plots <- list(
# first plot
plotBoxWhisker(mtcars,
dataMapping = BoxWhiskerDataMapping$new(x = "am", y = "wt"), outliers = FALSE
),
# second plot
plotBoxWhisker(ToothGrowth,
dataMapping = BoxWhiskerDataMapping$new(x = "supp", y = "len")
)
)
plotGridObj <- PlotGridConfiguration$new(ls_plots)
# specify further customizations for the plot grid
plotGridObj$title <- "my combined plot"
plotGridObj$subtitle <- "something clever"
plotGridObj$caption <- "my sources"
plotGridObj$nColumns <- 2L
plotGridObj$tagLevels <- "A"
plotGridObj$tagPrefix <- "Plot ("
plotGridObj$tagSuffix <- ")"
plotGridObj$tagColor <- "blue"
plotGridObj$tagSize <- 15
plotGridObj$tagAngle <- 45
plotGridObj$tagPosition <- TagPositions$top
plotGridObj$titleHorizontalJustification <- HorizontalJustification$middle
plotGridObj$subtitleHorizontalJustification <- HorizontalJustification$middle
# print the object to see its properties
plotGridObj
#> PlotGridConfiguration:
#> Plot grid annotations: NULL
#> Title: my combined plot
#> Subtitle: something clever
#> Caption: my sources
#> Plot grid arrangement: NULL
#> Number of plots included: 2
#> Number of columns in the grid: 2
#> Number of rows in the grid: NULL
#> Arranged in row-major order: NULL
#> Individual plot tags: NULL
#> Tag level format: A
#> Tag level prefix: Plot (
#> Tag level suffix: )
#> Tag level separator: NULL
## ------------------------------------------------
## Method `PlotGridConfiguration$addPlots`
## ------------------------------------------------
library(ggplot2)
myPlotGrid <- PlotGridConfiguration$new()
# You can add a single ggplot object
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
myPlotGrid$addPlots(p)
# Or you can also pass a list
myPlotGrid$addPlots(list("p1" = ggplot(), "p2" = ggplot()))
# Since we added three plots, the `plotList` field should
# now be a list of length `3`
length(myPlotGrid$plotList)
#> [1] 3