PlotGridConfiguration | R Documentation |
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.
A PlotGridConfiguration
object.
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.
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()
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.
myPlot <- plotGrid(...) ggplot2::ggsave(filename = "plot_1.png", plot = myPlot)
ospsuite.utils::Printable
-> PlotGridConfiguration
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 dimensions
byRow
Analogous to byrow
in matrix(). If FALSE
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.
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 dimensions
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.
new()
Create an instance of PlotGridConfiguration
class.
PlotGridConfiguration$new(plotList = NULL)
plotList
A list containing ggplot
objects.
A PlotGridConfiguration
object.
addPlots()
Add a plot object.
PlotGridConfiguration$addPlots(plots = NULL)
plots
A single or a list containing ggplot
object(s).
PlotGridConfiguration
object with $plotList
field updated to
store entered plots.
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)
print()
Print the object to the console.
PlotGridConfiguration$print()
clone()
The objects of this class are cloneable with this method.
PlotGridConfiguration$clone(deep = FALSE)
deep
Whether to make a deep clone.
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
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
## ------------------------------------------------
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.