ggmatrix - A ggplot2 Matrix

Share:

Description

Make a generic matrix of ggplot2 plots.

Usage

1
2
3
4
5
6
ggmatrix(plots, nrow, ncol, xAxisLabels = NULL, yAxisLabels = NULL,
  title = NULL, xlab = NULL, ylab = NULL, byrow = TRUE,
  showStrips = NULL, showAxisPlotLabels = TRUE,
  showXAxisPlotLabels = TRUE, showYAxisPlotLabels = TRUE, labeller = NULL,
  xProportions = NULL, yProportions = NULL, data = NULL, gg = NULL,
  legend = NULL)

Arguments

plots

list of plots to be put into matrix

nrow, ncol

number of rows and columns

xAxisLabels, yAxisLabels

strip titles for the x and y axis respectively. Set to NULL to not be displayed

title, xlab, ylab

title, x label, and y label for the graph. Set to NULL to not be displayed

byrow

boolean that determines whether the plots should be ordered by row or by column

showStrips

boolean to determine if each plot's strips should be displayed. NULL will default to the top and right side plots only. TRUE or FALSE will turn all strips on or off respectively.

showAxisPlotLabels, showXAxisPlotLabels, showYAxisPlotLabels

booleans that determine if the plots axis labels are printed on the X (bottom) or Y (left) part of the plot matrix. If showAxisPlotLabels is set, both showXAxisPlotLabels and showYAxisPlotLabels will be set to the given value.

labeller

labeller for facets. See labellers. Common values are "label_value" (default) and "label_parsed".

xProportions, yProportions

Value to change how much area is given for each plot. Either NULL (default), numeric value matching respective length, or grid::unit object with matching respective length

data

data set using. This is the data to be used in place of 'ggally_data' if the plot is a string to be evaluated at print time

gg

ggplot2 theme objects to be applied to every plot

legend

May be the two objects described below or the default NULL value. The legend position can be moved by using ggplot2's theme element pm + theme(legend.position = "bottom")

a numeric vector of length 2

provides the location of the plot to use the legend for the plot matrix's legend. Such as legend = c(3,5) which will use the legend from the plot in the third row and fifth column

a single numeric value

provides the location of a plot according to the display order. Such as legend = 3 in a plot matrix with 2 rows and 5 columns displayed by column will return the plot in position c(1,2)

a object from grab_legend()

a predetermined plot legend that will be displayed directly

Memory usage

Now that the print.ggmatrix method uses a large gtable object, rather than print each plot independently, memory usage may be of concern. From small tests, memory usage flutters around object.size(data) * 0.3 * length(plots). So, for a 80Mb random noise dataset with 100 plots, about 2.4 Gb of memory needed to print. For the 3.46 Mb diamonds dataset with 100 plots, about 100 Mb of memory was needed to print. The benefits of using the ggplot2 format greatly outweigh the price of about 20

Author(s)

Barret Schloerke schloerke@gmail.com

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
# small function to display plots only if it's interactive
p_ <- GGally::print_if_interactive

plotList <- list()
for (i in 1:6) {
  plotList[[i]] <- ggally_text(paste("Plot #", i, sep = ""))
}
pm <- ggmatrix(
  plotList,
  2, 3,
  c("A", "B", "C"),
  c("D", "E"),
  byrow = TRUE
)
p_(pm)

pm <- ggmatrix(
  plotList,
  2, 3,
  xAxisLabels = c("A", "B", "C"),
  yAxisLabels = NULL,
  byrow = FALSE,
  showXAxisPlotLabels = FALSE
)
p_(pm)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.