Extended grid facetsSource:
This function behaves like ggplot2::facet_grid with default arguments, but has a few extra options. It can draw partial or full axis guides at inner panels, and position scales can be independent.
facet_grid2( rows = NULL, cols = NULL, scales = "fixed", space = "fixed", axes = "margins", remove_labels = "none", independent = "none", shrink = TRUE, labeller = "label_value", as.table = TRUE, switch = NULL, drop = TRUE, margins = FALSE, render_empty = TRUE, strip = strip_vanilla() )
- rows, cols
A set of variables or expressions quoted by
vars()and defining faceting groups on the rows or columns dimension. The variables can be named (the names are passed to
For compatibility with the classic interface,
rowscan also be a formula with the rows (of the tabular display) on the LHS and the columns (of the tabular display) on the RHS; the dot in the formula is used to indicate there should be no faceting on this dimension (either row or column).
logical(1)whether scales are shared across facets or allowed to vary. Interacts with the
independentargument. One of the following:
Scales are shared across all facets (default).
x-scales are allowed to vary across rows.
y-scales are allowed to vary across columns.
Scales can vary across rows and columns.
logical(1)determining whether the size of panels are proportional to the length of the scales. When the
independentargument allows for free scales in a dimension, the panel sizes cannot be proportional. Note that the
scalesargument must be free in the same dimension as the
spaceargument to have an effect.One of the following:
All panels have the same size (default).
Panel widths are proportional to the x-scales.
Panel heights are proportional to the y-scales.
Both the widths and heights vary according to scales.
logical(1)where axes should be drawn. One of the following:
Only draw axes at the outer margins (default).
Draw axes at the outer margins and all inner x-axes too.
Draw axes at the outer margins and all inner y-axes too.
Draw the axes for every panel.
logical(1)determining whether axis text is displayed at inner panels. One of the following:
Display axis text at all axes (default).
Display axis text at outer margins and all inner y-axes.
Display axis text at outer margins and all inner x-axes.
Only display axis text at the outer margins.
logical(1)determining whether scales can vary within a row or column of panels, like they can be in ggplot2::facet_wrap. The
scalesargument must be free for the same dimension before they can be set to independent. One of the following:
All y-scales should be fixed in a row and all x-scales are fixed in a column (default).
x-scales are allowed to vary within a column.
y-scales are allowed to vary within a row.
Both x- and y-scales are allowed to vary within a column or row respectively.
TRUE, will shrink scales to fit output of statistics, not raw data. If
FALSE, will be range of raw data before statistical summary.
A function that takes one data frame of labels and returns a list or data frame of character vectors. Each input column corresponds to one factor. Thus there will be more than one with
vars(cyl, am). Each output column gets displayed as one separate line in the strip label. This function should inherit from the "labeller" S3 class for compatibility with
labeller(). You can use different labeling functions for different kind of labels, for example use
label_parsed()for formatting facet labels.
label_value()is used by default, check it for more details and pointers to other options.
TRUE, the default, the facets are laid out like a table with highest values at the bottom-right. If
FALSE, the facets are laid out like a plot with the highest value at the top-right.
By default, the labels are displayed on the top and right of the plot. If
"x", the top labels will be displayed to the bottom. If
"y", the right-hand side labels will be displayed to the left. Can also be set to
TRUE, the default, all factor levels not used in the data will automatically be dropped. If
FALSE, all factor levels will be shown, regardless of whether or not they appear in the data.
Either a logical value or a character vector. Margins are additional facets which contain all the data for each of the possible values of the faceting variables. If
FALSE, no additional facets are included (the default). If
TRUE, margins are included for all faceting variables. If specified as a character vector, it is the names of variables for which margins are to be created.
logical(1): whether to draw panels without any data (
TRUE, default) or display these as blanks (
An object created by a call to a strip function, such as
space arguments only have an effect
scales argument in a dimension is free. However, the
space arguments can not be used to simultaneously set
an independent scale and have the panel size be proportional to that scale.
p <- ggplot(mpg, aes(displ, hwy)) + geom_point() # Repeat all axes for every facet p + facet_grid2(cyl ~ drv, axes = "all") # Repeat only y-axes p + facet_grid2(cyl ~ drv, axes = "y") # Repeat axes without x-labels p + facet_grid2(cyl ~ drv, axes = "all", remove_labels = "x") # Grid facets with independent axes for every panel p + facet_grid2(cyl ~ drv, scales = "free", independent = "all")