Title: | A 'ggplot2' Extension for Consistent Axis Alignment |
---|---|
Description: | A 'ggplot2' extension offers various tools for organizing and arranging plots. It is designed to consistently align a specific axis across multiple 'ggplot' objects, making it especially useful for plots requiring data order manipulation. A typical use case includes organizing combinations like a dendrogram and a heatmap. |
Authors: | Yun Peng [aut, cre] |
Maintainer: | Yun Peng <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.5.9000 |
Built: | 2024-11-22 10:24:13 UTC |
Source: | https://github.com/yunuuuu/ggalign |
These settings control the behavior of the plot when added to a layout, as well as the arrangement of individual plot areas within the layout.
active(order = waiver(), use = waiver(), name = waiver())
active(order = waiver(), use = waiver(), name = waiver())
order |
An integer specifying the order of the plot area within the layout. |
use |
A logical ( |
name |
A string specifying the plot's name, useful for switching active
contexts through the |
By default, the active context is set only for functions that add plot areas.
This allows other ggplot2
elements-such as geoms
, stats
, scales
, or
themes
- to be seamlessly added to the current plot area.
The default ordering of the plot areas is from top to bottom or from left to
right, depending on the layout orientation. However, users can customize this
order using the order
argument.
This function aligns observations within the layout according to a hierarchical clustering tree, enabling reordering or grouping of elements based on clustering results.
align_dendro( mapping = aes(), ..., distance = "euclidean", method = "complete", use_missing = "pairwise.complete.obs", reorder_dendrogram = FALSE, merge_dendrogram = FALSE, reorder_group = FALSE, k = NULL, h = NULL, cutree = NULL, plot_dendrogram = TRUE, plot_cut_height = NULL, root = NULL, center = FALSE, type = "rectangle", size = NULL, data = NULL, no_axes = NULL, active = NULL, free_guides = deprecated(), free_spaces = deprecated(), plot_data = deprecated(), theme = deprecated(), free_labs = deprecated(), set_context = deprecated(), order = deprecated(), name = deprecated() )
align_dendro( mapping = aes(), ..., distance = "euclidean", method = "complete", use_missing = "pairwise.complete.obs", reorder_dendrogram = FALSE, merge_dendrogram = FALSE, reorder_group = FALSE, k = NULL, h = NULL, cutree = NULL, plot_dendrogram = TRUE, plot_cut_height = NULL, root = NULL, center = FALSE, type = "rectangle", size = NULL, data = NULL, no_axes = NULL, active = NULL, free_guides = deprecated(), free_spaces = deprecated(), plot_data = deprecated(), theme = deprecated(), free_labs = deprecated(), set_context = deprecated(), order = deprecated(), name = deprecated() )
mapping |
Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot. |
... |
<dyn-dots> Additional arguments passed to
|
distance |
A string of distance measure to be used. This must be one of
|
method |
A string of the agglomeration method to be used. This should be
(an unambiguous abbreviation of) one of |
use_missing |
An optional character string giving a method for computing
covariances in the presence of missing values. This must be (an abbreviation
of) one of the strings |
reorder_dendrogram |
A single boolean value indicating whether to
reorder the dendrogram based on the means. Alternatively, you can provide a
custom function that accepts an |
merge_dendrogram |
A single boolean value, indicates whether we should
merge multiple dendrograms, only used when previous groups have been
established. Default: |
reorder_group |
A single boolean value, indicates whether we should do
Hierarchical Clustering between groups, only used when previous groups have
been established. Default: |
k |
An integer scalar indicates the desired number of groups. |
h |
A numeric scalar indicates heights where the tree should be cut. |
cutree |
A function used to cut the |
plot_dendrogram |
A boolean value indicates whether plot the dendrogram tree. |
plot_cut_height |
A boolean value indicates whether plot the cut height. |
root |
A length one string or numeric indicates the root branch. |
center |
A boolean value. if |
type |
A string indicates the plot type, |
size |
The relative size of the plot, can be specified as a
|
data |
A matrix-like object. By default, it inherits from the layout
|
no_axes |
Logical; if |
active |
A |
free_guides |
Please use
|
free_spaces |
Please use
|
plot_data |
Please use
|
theme |
Please use
|
free_labs |
Please use
|
set_context |
|
order |
|
name |
A "AlignDendro"
object.
align_dendro
initializes a ggplot data
and mapping
.
The internal will always use a default mapping of aes(x = .data$x, y = .data$y)
.
The default ggplot data is the node
coordinates with edge
data attached
in ggalign
attribute, in addition, a
geom_segment
layer with a data of the edge
coordinates will be added.
node
and tree segments edge
coordinates contains following columns:
index
: the original index in the tree for the current node
label
: node label text
x
and y
: x-axis and y-axis coordinates for current node or the start
node of the current edge.
xend
and yend
: the x-axis and y-axis coordinates of the terminal node
for current edge.
branch
: which branch current node or edge is. You can use this column
to color different groups.
panel
: which panel current node is, if we split the plot into panel
using facet_grid
, this column will show
which panel current node or edge is from. Note: some nodes may
fall outside panel (between two panel), so there are possible
NA
values in this column.
.panel
: Similar with panel
column, but always give the correct branch
for usage of the ggplot facet.
panel1
and panel2
: The panel1 and panel2 variables have the same
functionality as panel
, but they are specifically for the edge
data
and correspond to both nodes of each edge.
leaf
: A logical value indicates whether current node is a leaf.
It is important to note that we consider rows as observations, meaning
vec_size(data)
/NROW(data)
must match the number of observations along the
axis used for alignment (x-axis for a vertical stack layout, y-axis for a
horizontal stack layout).
quad_layout()
/ggheatmap()
: For column annotation, the layout
matrix
will be transposed before use (if data
is a function, it is
applied to the transposed matrix), as column annotation uses columns as
observations but alignment requires rows.
stack_layout()
: The layout matrix is used as is, aligning all plots
along a single axis.
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + align_dendro() ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + align_dendro(k = 3L)
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + align_dendro() ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + align_dendro(k = 3L)
align_gg()
is similar to ggplot
in that it initializes a ggplot
data
and mapping
. Same with other align_*
functions. align_gg()
allowing you
to provide data in various formats, including matrices, data frames, or
simple vectors. By default, it will inherit from the layout. If a function,
it will apply with the layout matrix. ggalign
is an alias of align_gg
.
align_gg( mapping = aes(), size = NULL, data = waiver(), limits = TRUE, facet = TRUE, no_axes = NULL, active = NULL, set_context = deprecated(), order = deprecated(), name = deprecated(), free_guides = deprecated(), free_spaces = deprecated(), plot_data = deprecated(), theme = deprecated(), free_labs = deprecated() )
align_gg( mapping = aes(), size = NULL, data = waiver(), limits = TRUE, facet = TRUE, no_axes = NULL, active = NULL, set_context = deprecated(), order = deprecated(), name = deprecated(), free_guides = deprecated(), free_spaces = deprecated(), plot_data = deprecated(), theme = deprecated(), free_labs = deprecated() )
mapping |
Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot. |
size |
The relative size of the plot, can be specified as a
|
data |
A flexible input that specifies the data to be used
|
limits |
Logical; if |
facet |
Logical; if |
no_axes |
Logical; if |
active |
A |
set_context |
|
order |
|
name |
|
free_guides |
Please use
|
free_spaces |
Please use
|
plot_data |
Please use
|
theme |
Please use
|
free_labs |
Please use
|
A "AlignGG"
object.
align_gg
initializes a ggplot data
and mapping
.
align_gg()
always applies a default mapping for the axis of the data index
in the layout. This mapping is aes(y = .data$.y)
for horizontal stack
layout (including left and right annotation) and aes(x = .data$.x)
for vertical stack layout (including top and bottom annotation).
matrix
input will be automatically melted into a long foramted data frame.
Atomic vector will be put in the value
column of the data frame.
In the case where the input data is already a data frame, 4 additional
columns (.x
/.y
, .names
, .index
, and .panel
) are added to the data
frame.
The data in the underlying ggplot
object will contain following columns:
.panel
: the panel for the aligned axis. It means x-axis
for vertical
stack layout (including top and bottom annotation), y-axis
for
horizontal stack layout (including left and right annotation).
.x
or .y
: the x
or y
coordinates
.names
(vec_names()
) and .index
(vec_size()
/NROW()
): A factor of the names
(only applicable when names exists) and an integer of index of the
original data.
.row_names
and .row_index
: the row names and an integer of
row index of the original matrix (only applicable if data
is a
matrix
).
.column_names
and .column_index
: the column names and column index of
the original matrix (only applicable if data
is a matrix
).
value
: the actual value (only applicable if data
is a matrix
or
atomic vector).
It is recommended to use .x
/.y
, or .names
as the x
/y
mapping.
If the data inherits from quad_layout()
/ggheatmap()
, an additional
column will be added.
.extra_panel
: the panel information for column (left or right
annotation) or row (top or bottom annotation).
It is important to note that we consider rows as observations, meaning
vec_size(data)
/NROW(data)
must match the number of observations along the
axis used for alignment (x-axis for a vertical stack layout, y-axis for a
horizontal stack layout).
quad_layout()
/ggheatmap()
: For column annotation, the layout
matrix
will be transposed before use (if data
is a function, it is
applied to the transposed matrix), as column annotation uses columns as
observations but alignment requires rows.
stack_layout()
: The layout matrix is used as is, aligning all plots
along a single axis.
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + ggalign() + geom_point(aes(y = value)) # if data is `NULL`, a three column data frame will be created # (`.panel`, `.index`, `.x`/`.y`) ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top(size = 0.5) + align_dendro(k = 3L) + ggalign(data = NULL, size = 0.2) + geom_tile(aes(y = 1L, fill = .panel))
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + ggalign() + geom_point(aes(y = value)) # if data is `NULL`, a three column data frame will be created # (`.panel`, `.index`, `.x`/`.y`) ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top(size = 0.5) + align_dendro(k = 3L) + ggalign(data = NULL, size = 0.2) + geom_tile(aes(y = 1L, fill = .panel))
Splits observations into groups, with slice ordering based on group levels.
align_group( group, active = NULL, set_context = deprecated(), name = deprecated() )
align_group( group, active = NULL, set_context = deprecated(), name = deprecated() )
group |
A character define the groups of the observations. |
active |
A |
set_context |
|
name |
A "AlignGroup"
object.
set.seed(1L) small_mat <- matrix(rnorm(81), nrow = 9) ggheatmap(small_mat) + anno_top() + align_group(sample(letters[1:4], ncol(small_mat), replace = TRUE))
set.seed(1L) small_mat <- matrix(rnorm(81), nrow = 9) ggheatmap(small_mat) + anno_top() + align_group(sample(letters[1:4], ncol(small_mat), replace = TRUE))
Aligns and groups observations based on k-means clustering, enabling observation splits by cluster groups.
align_kmeans( centers, ..., data = NULL, active = NULL, set_context = deprecated(), name = deprecated() )
align_kmeans( centers, ..., data = NULL, active = NULL, set_context = deprecated(), name = deprecated() )
centers |
either the number of clusters, say |
... |
Arguments passed on to
|
data |
A matrix-like object. By default, it inherits from the layout
|
active |
A |
set_context |
|
name |
A "AlignKmeans"
object.
It is important to note that we consider rows as observations, meaning
vec_size(data)
/NROW(data)
must match the number of observations along the
axis used for alignment (x-axis for a vertical stack layout, y-axis for a
horizontal stack layout).
quad_layout()
/ggheatmap()
: For column annotation, the layout
matrix
will be transposed before use (if data
is a function, it is
applied to the transposed matrix), as column annotation uses columns as
observations but alignment requires rows.
stack_layout()
: The layout matrix is used as is, aligning all plots
along a single axis.
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + align_kmeans(3L)
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + align_kmeans(3L)
Ordering observations based on summary weights or a specified ordering character or integer index.
align_order( weights = rowMeans, ..., reverse = FALSE, strict = TRUE, data = NULL, active = NULL, set_context = deprecated(), name = deprecated() )
align_order( weights = rowMeans, ..., reverse = FALSE, strict = TRUE, data = NULL, active = NULL, set_context = deprecated(), name = deprecated() )
weights |
A summary function which accepts a data and returns the
weights for each observations. Alternatively, you can provide an ordering
index as either an integer or a character. Since characters have been
designated as character indices, if you wish to specify a function name as a
string, you must enclose it with |
... |
<dyn-dots> Additional arguments passed to
function provided in |
reverse |
A boolean value. Should the sort order be in reverse? |
strict |
A boolean value indicates whether the order should be strict.
If previous groups has been established, and strict is |
data |
A |
active |
A |
set_context |
|
name |
A "AlignOrder"
object.
It is important to note that we consider rows as observations, meaning
vec_size(data)
/NROW(data)
must match the number of observations along the
axis used for alignment (x-axis for a vertical stack layout, y-axis for a
horizontal stack layout).
quad_layout()
/ggheatmap()
: For column annotation, the layout
matrix
will be transposed before use (if data
is a function, it is
applied to the transposed matrix), as column annotation uses columns as
observations but alignment requires rows.
stack_layout()
: The layout matrix is used as is, aligning all plots
along a single axis.
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_left() + align_order(I("rowMeans"))
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_left() + align_order(I("rowMeans"))
Arrange multiple plots into a grid
align_plots( ..., ncol = NULL, nrow = NULL, byrow = TRUE, widths = NA, heights = NA, design = NULL, guides = waiver(), theme = NULL )
align_plots( ..., ncol = NULL, nrow = NULL, byrow = TRUE, widths = NA, heights = NA, design = NULL, guides = waiver(), theme = NULL )
... |
<dyn-dots> A list of plots, ususally the
ggplot object. Use |
ncol , nrow
|
The dimensions of the grid to create - if both are |
byrow |
If |
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. The
special value of |
design |
Specification of the location of areas in the layout. Can
either be specified as a text string or by concatenating calls to
|
guides |
A string with one or more of |
theme |
A |
An alignpatches
object.
# directly copied from patchwork p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl) p4 <- ggplot(mtcars) + geom_bar(aes(carb)) p5 <- ggplot(mtcars) + geom_violin(aes(cyl, mpg, group = cyl)) # Either add the plots as single arguments align_plots(p1, p2, p3, p4, p5) # Or use bang-bang-bang to add a list align_plots(!!!list(p1, p2, p3), p4, p5) # Match plots to areas by name design <- "#BB AA#" align_plots(B = p1, A = p2, design = design) # Compare to not using named plot arguments align_plots(p1, p2, design = design)
# directly copied from patchwork p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl) p4 <- ggplot(mtcars) + geom_bar(aes(carb)) p5 <- ggplot(mtcars) + geom_violin(aes(cyl, mpg, group = cyl)) # Either add the plots as single arguments align_plots(p1, p2, p3, p4, p5) # Or use bang-bang-bang to add a list align_plots(!!!list(p1, p2, p3), p4, p5) # Match plots to areas by name design <- "#BB AA#" align_plots(B = p1, A = p2, design = design) # Compare to not using named plot arguments align_plots(p1, p2, design = design)
Reorders layout observations based on specific statistics.
align_reorder( stat, ..., reverse = FALSE, strict = TRUE, data = NULL, active = NULL, set_context = deprecated(), name = deprecated() )
align_reorder( stat, ..., reverse = FALSE, strict = TRUE, data = NULL, active = NULL, set_context = deprecated(), name = deprecated() )
stat |
A summary function which accepts a data and returns the
statistic, which we'll call |
... |
<dyn-dots> Additional arguments passed to
function provided in |
reverse |
A boolean value. Should the sort order be in reverse? |
strict |
A boolean value indicates whether the order should be strict.
If previous groups has been established, and strict is |
data |
A |
active |
A |
set_context |
|
name |
The align_reorder()
function differs from align_order()
in that the wts
argument in align_order()
must return atomic weights for each observation.
In contrast, the stat
argument in align_reorder()
can return more complex
structures, such as hclust or
dendrogram, among others.
Typically, you can achieve the functionality of align_reorder()
using
align_order()
by manually extracting the ordering information from
the statistic.
A "AlignReorder"
object.
It is important to note that we consider rows as observations, meaning
vec_size(data)
/NROW(data)
must match the number of observations along the
axis used for alignment (x-axis for a vertical stack layout, y-axis for a
horizontal stack layout).
quad_layout()
/ggheatmap()
: For column annotation, the layout
matrix
will be transposed before use (if data
is a function, it is
applied to the transposed matrix), as column annotation uses columns as
observations but alignment requires rows.
stack_layout()
: The layout matrix is used as is, aligning all plots
along a single axis.
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_left() + align_reorder(hclust2)
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_left() + align_reorder(hclust2)
align_plots
This is a small helper used to specify a single area in a rectangular grid
that should contain a plot. Objects constructed with area()
can be
concatenated together with c()
in order to specify multiple areas.
area(t, l, b = t, r = l)
area(t, l, b = t, r = l)
t , b
|
The top and bottom bounds of the area in the grid |
l , r
|
The left and right bounds of the area int the grid |
The grid that the areas are specified in reference to enumerate rows from top
to bottom, and coloumns from left to right. This means that t
and l
should always be less or equal to b
and r
respectively. Instead of
specifying area placement with a combination of area()
calls, it is
possible to instead pass in a single string
areas <- c(area(1, 1, 2, 1), area(2, 3, 3, 3))
is equivalent to
areas < -"A## A#B ##B"
A ggalign_area
object.
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl) layout <- c( area(1, 1), area(1, 3, 3), area(3, 1, 3, 2) ) # Show the layout to make sure it looks as it should plot(layout) # Apply it to a alignpatches align_plots(p1, p2, p3, design = layout)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl) layout <- c( area(1, 1), area(1, 3, 3), area(3, 1, 3, 2) ) # Show the layout to make sure it looks as it should plot(layout) # Apply it to a alignpatches align_plots(p1, p2, p3, design = layout)
Dengrogram x and y coordinates
dendrogram_data( tree, priority = "right", center = FALSE, type = "rectangle", leaf_pos = NULL, leaf_braches = NULL, reorder_branches = TRUE, branch_gap = NULL, root = NULL )
dendrogram_data( tree, priority = "right", center = FALSE, type = "rectangle", leaf_pos = NULL, leaf_braches = NULL, reorder_branches = TRUE, branch_gap = NULL, root = NULL )
tree |
A hclust or a dendrogram object. |
priority |
A string of "left" or "right". if we draw from right to left,
the left will override the right, so we take the |
center |
A boolean value. if |
type |
A string indicates the plot type, |
leaf_pos |
The x-coordinates of the leaf node. Must be the same length
of the number of observations in |
leaf_braches |
Branches of the leaf node. Must be the same length of the
number of observations in |
reorder_branches |
A single boolean value, indicates whether reorder the
provided |
branch_gap |
A single numeric value indicates the gap between different branches. |
root |
A length one string or numeric indicates the root branch. |
A list of 2 data.frame. One for node coordinates, another for edge
coordinates.
node
and tree segments edge
coordinates contains following columns:
index
: the original index in the tree for the current node
label
: node label text
x
and y
: x-axis and y-axis coordinates for current node or the start
node of the current edge.
xend
and yend
: the x-axis and y-axis coordinates of the terminal node
for current edge.
branch
: which branch current node or edge is. You can use this column
to color different groups.
panel
: which panel current node is, if we split the plot into panel
using facet_grid, this column will show
which panel current node or edge is from. Note: some nodes may
fall outside panel (between two panels), so there are possible
NA
values in this column.
.panel
: Similar with panel
column, but always give the correct
branch for usage of the ggplot facet.
panel1
and panel2
: The panel1 and panel2 variables have the same
functionality as panel
, but they are specifically for the edge
data
and correspond to both nodes of each edge.
leaf
: A logical value indicates whether current node is a leaf.
dendrogram_data(hclust(dist(USArrests), "ave"))
dendrogram_data(hclust(dist(USArrests), "ave"))
Each geom has an associated function that draws the key when the geom needs
to be displayed in a legend. These functions are called draw_key_*()
,
where *
stands for the name of the respective key glyph. The key glyphs can
be customized for individual geoms by providing a geom with the key_glyph
argument. The draw_key_draw
function provides this interface for custom key
glyphs used with geom_draw()
.
draw_key_draw(data, params, size)
draw_key_draw(data, params, size)
data |
A single row data frame containing the scaled aesthetics to display in this key |
params |
A list of additional parameters supplied to the geom. |
size |
Width and height of key in mm. |
A grid grob.
p <- ggplot(economics, aes(date, psavert, color = "savings rate")) # key glyphs can be specified by their name p + geom_line(key_glyph = "timeseries") # key glyphs can be specified via their drawing function p + geom_line(key_glyph = draw_key_rect)
p <- ggplot(economics, aes(date, psavert, color = "savings rate")) # key glyphs can be specified by their name p + geom_line(key_glyph = "timeseries") # key glyphs can be specified via their drawing function p + geom_line(key_glyph = draw_key_rect)
This function converts various objects to a data frame.
fortify_data_frame(data, ...)
fortify_data_frame(data, ...)
data |
An object to be converted to a data frame. |
... |
Arguments passed to methods. |
A data frame.
When data
is an atomic vector, it'll be converted to a data frame with
following columns:
.names
: the names for the vector (only applicable if names exist).
value
: the actual value of the vector.
## S3 method for class 'character' fortify_data_frame(data, ...)
## S3 method for class 'character' fortify_data_frame(data, ...)
data |
An object to be converted to a data frame. |
... |
Arguments passed to methods. |
A data frame.
Other fortify_data_frame methods:
fortify_data_frame.complex()
,
fortify_data_frame.default()
,
fortify_data_frame.logical()
,
fortify_data_frame.matrix()
,
fortify_data_frame.numeric()
When data
is an atomic vector, it'll be converted to a data frame with
following columns:
.names
: the names for the vector (only applicable if names exist).
value
: the actual value of the vector.
## S3 method for class 'complex' fortify_data_frame(data, ...)
## S3 method for class 'complex' fortify_data_frame(data, ...)
data |
An object to be converted to a data frame. |
... |
Arguments passed to methods. |
A data frame.
Other fortify_data_frame methods:
fortify_data_frame.character()
,
fortify_data_frame.default()
,
fortify_data_frame.logical()
,
fortify_data_frame.matrix()
,
fortify_data_frame.numeric()
By default, it calls fortify()
to build the
data frame.
## Default S3 method: fortify_data_frame(data, ...)
## Default S3 method: fortify_data_frame(data, ...)
data |
An object to be converted to a data frame. |
... |
Arguments passed to methods. |
A data frame.
Other fortify_data_frame methods:
fortify_data_frame.character()
,
fortify_data_frame.complex()
,
fortify_data_frame.logical()
,
fortify_data_frame.matrix()
,
fortify_data_frame.numeric()
When data
is an atomic vector, it'll be converted to a data frame with
following columns:
.names
: the names for the vector (only applicable if names exist).
value
: the actual value of the vector.
## S3 method for class 'logical' fortify_data_frame(data, ...)
## S3 method for class 'logical' fortify_data_frame(data, ...)
data |
An object to be converted to a data frame. |
... |
Arguments passed to methods. |
A data frame.
Other fortify_data_frame methods:
fortify_data_frame.character()
,
fortify_data_frame.complex()
,
fortify_data_frame.default()
,
fortify_data_frame.matrix()
,
fortify_data_frame.numeric()
When data
is a matrix, it will automatically be transformed into a
long-form data frame, where each row represents a unique combination of
matrix indices and their corresponding values.
## S3 method for class 'matrix' fortify_data_frame(data, ...)
## S3 method for class 'matrix' fortify_data_frame(data, ...)
data |
An object to be converted to a data frame. |
... |
Arguments passed to methods. |
A data frame.
Other fortify_data_frame methods:
fortify_data_frame.character()
,
fortify_data_frame.complex()
,
fortify_data_frame.default()
,
fortify_data_frame.logical()
,
fortify_data_frame.numeric()
When data
is an atomic vector, it'll be converted to a data frame with
following columns:
.names
: the names for the vector (only applicable if names exist).
value
: the actual value of the vector.
## S3 method for class 'numeric' fortify_data_frame(data, ...)
## S3 method for class 'numeric' fortify_data_frame(data, ...)
data |
An object to be converted to a data frame. |
... |
Arguments passed to methods. |
A data frame.
Other fortify_data_frame methods:
fortify_data_frame.character()
,
fortify_data_frame.complex()
,
fortify_data_frame.default()
,
fortify_data_frame.logical()
,
fortify_data_frame.matrix()
This function converts various objects into a matrix format.
fortify_matrix(data, ...)
fortify_matrix(data, ...)
data |
An object to be converted to a matrix. |
... |
Arguments passed to methods. |
A matrix.
By default, it calls as.matrix()
to build a matrix.
## Default S3 method: fortify_matrix(data, ...)
## Default S3 method: fortify_matrix(data, ...)
data |
An object to be converted to a matrix. |
... |
Arguments passed to methods. |
A matrix.
Other fortify_matrix methods:
fortify_matrix.GISTIC()
,
fortify_matrix.MAF()
This function converts various objects into a matrix format.
## S3 method for class 'GISTIC' fortify_matrix( data, ..., n_top = NULL, bands = NULL, ignored_bands = NULL, sample_anno = NULL, remove_empty_samples = TRUE )
## S3 method for class 'GISTIC' fortify_matrix( data, ..., n_top = NULL, bands = NULL, ignored_bands = NULL, sample_anno = NULL, remove_empty_samples = TRUE )
data |
An object to be converted to a matrix. |
... |
Not used currently. |
n_top |
A single number indicates how many top bands to be drawn. |
bands |
An atomic character defines the bands to draw. |
ignored_bands |
An atomic character defines the bands to be ignored. |
sample_anno |
A data frame of sample clinical features to be added. |
remove_empty_samples |
A single boolean value indicating whether to drop samples without any genomic alterations. |
A matrix.
sample_anno
: sample clinical informations provided in sample_anno
.
sample_summary
: sample copy number summary informations. See
[email protected]
for details.
cytoband_summary
: cytoband summary informations. See
[email protected]
for details.
gene_summary
: gene summary informations. See
[email protected]
for details.
summary
: A data frame of summary information. See data@summary
for
details.
Other fortify_matrix methods:
fortify_matrix.MAF()
,
fortify_matrix.default()
This function converts various objects into a matrix format.
## S3 method for class 'MAF' fortify_matrix( data, ..., genes = NULL, n_top = NULL, remove_empty_samples = TRUE, collapse_vars = TRUE, use_syn = TRUE )
## S3 method for class 'MAF' fortify_matrix( data, ..., genes = NULL, n_top = NULL, remove_empty_samples = TRUE, collapse_vars = TRUE, use_syn = TRUE )
data |
An object to be converted to a matrix. |
... |
Not used currently. |
genes |
An atomic character defines the genes to draw. |
n_top |
A single number indicates how many top genes to be drawn. |
remove_empty_samples |
A single boolean value indicating whether to drop samples without any genomic alterations. |
collapse_vars |
A single boolean value indicating whether to collapse
multiple alterations in the same sample and gene into a single value
|
use_syn |
A single boolean value indicates whether to include synonymous variants when Classifies SNPs into transitions and transversions. |
A matrix.
gene_summary
: gene summary informations. See
maftools::getGeneSummary()
for details.
sample_summary
: sample summary informations. See
maftools::getSampleSummary()
for details.
sample_anno
: sample clinical informations. See
maftools::getClinicalData()
for details.
n_genes
: Total of genes.
n_samples
: Total of samples.
titv
: A list of data.frames
with Transitions and Transversions
summary. See maftools::titv()
for details.
Other fortify_matrix methods:
fortify_matrix.GISTIC()
,
fortify_matrix.default()
align_plots will try to align plot panels, and every elements of the plot, following functions romove these restrictions:
free_align
: if we want to compose plots without alignment of some panel
axes (panel won't be aligned). we can wrap the plot with free_align
.
free_border
: If we want to compose plots without alignment of the panel
borders (but still align the panels themselves), we can wrap the plot with
free_border
.
free_lab
: If we want to compose plots without alignment of the axis
title, we can wrap the plot with free_lab
.
free_space
: Removing the ggplot element sizes when aligning.
free_vp
: Customize the viewport when aligning.
free_guide
: If we want to override the behaviour of the overall guides
behaviour, we can wrap the plot with free_guide
.
free_align(plot, axes = "tlbr") free_border(plot, borders = "tlbr") free_guide(plot, guides = "tlbr") free_lab(plot, labs = "tlbr") free_space(plot, spaces = "tlbr") free_vp(plot, x = 0.5, y = 0.5, width = NA, height = NA, ...)
free_align(plot, axes = "tlbr") free_border(plot, borders = "tlbr") free_guide(plot, guides = "tlbr") free_lab(plot, labs = "tlbr") free_space(plot, spaces = "tlbr") free_vp(plot, x = 0.5, y = 0.5, width = NA, height = NA, ...)
plot |
A ggplot or alignpatches object. |
axes |
Which axes shouldn't be aligned? A string containing
one or more of |
borders |
Which border shouldn't be aligned? A string containing one or
more of |
guides |
A string containing one or more of |
labs |
Which axis labs to be free? A string containing one or more of
|
spaces |
Which border spaces should be removed? A string containing one
or more of |
x |
A numeric vector or unit object specifying x-location. |
y |
A numeric vector or unit object specifying y-location. |
width |
A numeric vector or unit object specifying width. |
height |
A numeric vector or unit object specifying height. |
... |
Arguments passed on to
|
free_align
: A modified version of plot
with a free_align
class.
free_border
: A modified version of plot
with a free_border
class.
free_guide
: A modified version of plot
with a free_guide
class.
free_lab
: A modified version of plot
with a free_lab
class.
free_space
: A modified version of plot
with a free_space
class.
free_vp
: A modified version of plot
with a free_vp
class.
# directly copied from `patchwork` # Sometimes you have a plot that defies good composition alginment, e.g. due # to long axis labels p1 <- ggplot(mtcars) + geom_bar(aes(y = factor(gear), fill = factor(gear))) + scale_y_discrete( "", labels = c( "3 gears are often enough", "But, you know, 4 is a nice number", "I would def go with 5 gears in a modern car" ) ) # When combined with other plots it ends up looking bad p2 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) align_plots(p1, p2, ncol = 1L) # We can fix this be using `free_align` align_plots(free_align(p1), p2, ncol = 1L) # If we still want the panels to be aligned to the right, we can choose to # free only the left side align_plots(free_align(p1, axes = "l"), p2, ncol = 1L) # We could use `free_lab` to fix the layout in a different way align_plots(p1, free_lab(p2), ncol = 1L) # `free_border` is similar with `free_lab`, they have a distinction in terms # of placement on either the top or bottom side of the panel. Specifically, # the top side contains the `title` and `subtitle`, while the bottom side # contains the `caption`. free_lab() does not attach these elements in the # panel area. p3 <- ggplot(mtcars) + geom_point(aes(hp, wt, colour = mpg)) + ggtitle("Plot 3") p_axis_top <- ggplot(mtcars) + geom_point(aes(mpg, disp)) + ggtitle("Plot axis in top") + scale_x_continuous(position = "top") align_plots(p_axis_top, free_lab(p3)) align_plots(p_axis_top, free_border(p3)) # Another issue is that long labels can occupy much spaces align_plots(NULL, p1, p2, p2) # This can be fixed with `free_space` align_plots(NULL, free_space(p1, "l"), p2, p2)
# directly copied from `patchwork` # Sometimes you have a plot that defies good composition alginment, e.g. due # to long axis labels p1 <- ggplot(mtcars) + geom_bar(aes(y = factor(gear), fill = factor(gear))) + scale_y_discrete( "", labels = c( "3 gears are often enough", "But, you know, 4 is a nice number", "I would def go with 5 gears in a modern car" ) ) # When combined with other plots it ends up looking bad p2 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) align_plots(p1, p2, ncol = 1L) # We can fix this be using `free_align` align_plots(free_align(p1), p2, ncol = 1L) # If we still want the panels to be aligned to the right, we can choose to # free only the left side align_plots(free_align(p1, axes = "l"), p2, ncol = 1L) # We could use `free_lab` to fix the layout in a different way align_plots(p1, free_lab(p2), ncol = 1L) # `free_border` is similar with `free_lab`, they have a distinction in terms # of placement on either the top or bottom side of the panel. Specifically, # the top side contains the `title` and `subtitle`, while the bottom side # contains the `caption`. free_lab() does not attach these elements in the # panel area. p3 <- ggplot(mtcars) + geom_point(aes(hp, wt, colour = mpg)) + ggtitle("Plot 3") p_axis_top <- ggplot(mtcars) + geom_point(aes(mpg, disp)) + ggtitle("Plot axis in top") + scale_x_continuous(position = "top") align_plots(p_axis_top, free_lab(p3)) align_plots(p_axis_top, free_border(p3)) # Another issue is that long labels can occupy much spaces align_plots(NULL, p1, p2, p2) # This can be fixed with `free_space` align_plots(NULL, free_space(p1, "l"), p2, p2)
The free_gg()
function allows you to incorporate a ggplot object into your
layout. Unlike align_gg()
, which aligns every axis value precisely,
free_gg()
focuses on layout integration without enforcing strict axis
alignment. ggfree()
is an alias for free_gg
.
free_gg(..., data = waiver(), size = NULL, active = NULL) ## Default S3 method: free_gg(mapping = aes(), ..., data = waiver(), size = NULL, active = NULL) ## S3 method for class 'ggplot' free_gg(..., data = waiver(), size = NULL, active = NULL)
free_gg(..., data = waiver(), size = NULL, active = NULL) ## Default S3 method: free_gg(mapping = aes(), ..., data = waiver(), size = NULL, active = NULL) ## S3 method for class 'ggplot' free_gg(..., data = waiver(), size = NULL, active = NULL)
... |
Additional arguments passed to |
data |
A dataset used to initialize a |
size |
The relative size of the plot, can be specified as a
|
active |
A |
mapping |
Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot. |
A ggalign_free_gg
object.
ggheatmap(matrix(rnorm(56), nrow = 7)) + anno_top() + align_dendro() + ggfree(aes(wt, mpg), data = mtcars) + geom_point()
ggheatmap(matrix(rnorm(56), nrow = 7)) + anno_top() + align_dendro() + ggfree(aes(wt, mpg), data = mtcars) + geom_point()
Layer with customized draw function
geom_draw( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
geom_draw( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
lineend |
Line end style (round, butt, square). |
linejoin |
Line join style (round, mitre, bevel). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom_draw
depends on the new aesthetics draw
, which should always be
provided with scale_draw_manual()
, in which, we can provide a list of
functions that define how each cell's grob (graphical object) should be
drawn. This aesthetic allows you to replace the default rendering of cells
with custom behavior, making it possible to tailor the plot to specific
requirements.
geom_draw()
understands the following aesthetics (required aesthetics are in bold):
Learn more about setting these aesthetics in vignette("ggplot2-specs", package = "ggplot2")
.
library(grid) ggplot(data.frame(value = letters[seq_len(5)], y = seq_len(5))) + geom_draw(aes(x = 1, y = y, draw = value, fill = value)) + scale_draw_manual(values = list( a = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, b = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, c = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, d = function(x, y, width, height, shape) { gList( pointsGrob(x, y, pch = shape), # To ensure the rectangle color is shown in the legends, you # must explicitly provide a color argument and include it in # the `gpar()` of the graphical object rectGrob(x, y, width, height, gp = gpar(col = "black", fill = NA) ) ) }, e = function(xmin, xmax, ymin, ymax) { segmentsGrob( xmin, ymin, xmax, ymax, gp = gpar(lwd = 2) ) } )) + scale_fill_brewer(palette = "Dark2") + theme_void()
library(grid) ggplot(data.frame(value = letters[seq_len(5)], y = seq_len(5))) + geom_draw(aes(x = 1, y = y, draw = value, fill = value)) + scale_draw_manual(values = list( a = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, b = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, c = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, d = function(x, y, width, height, shape) { gList( pointsGrob(x, y, pch = shape), # To ensure the rectangle color is shown in the legends, you # must explicitly provide a color argument and include it in # the `gpar()` of the graphical object rectGrob(x, y, width, height, gp = gpar(col = "black", fill = NA) ) ) }, e = function(xmin, xmax, ymin, ymax) { segmentsGrob( xmin, ymin, xmax, ymax, gp = gpar(lwd = 2) ) } )) + scale_fill_brewer(palette = "Dark2") + theme_void()
Pie charts
geom_pie( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., clockwise = TRUE, steps = 100, lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
geom_pie( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., clockwise = TRUE, steps = 100, lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
clockwise |
A single boolean value indicates clockwise or not. |
steps |
An integer indicating the number of steps to generate the pie chart radian. Increasing this value results in a smoother pie circular. |
lineend |
Line end style (round, butt, square). |
linejoin |
Line join style (round, mitre, bevel). |
linemitre |
Line mitre limit (number greater than 1). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
angle
: the pie circle angle.
angle0
: the initial pie circle angle.
radius
: the circle radius.
geom_pie()
understands the following aesthetics (required aesthetics are in bold):
Learn more about setting these aesthetics in vignette("ggplot2-specs", package = "ggplot2")
.
ggplot(data.frame(x = 1:10, y = 1:10, value = 1:10 / sum(1:10))) + geom_pie(aes(x, y, angle = value * 360))
ggplot(data.frame(x = 1:10, y = 1:10, value = 1:10 / sum(1:10))) + geom_pie(aes(x, y, angle = value * 360))
These geoms subdivide rectangles with shared borders into a grid. Both geoms achieve the same result but differ in how the rectangles are parameterized:
geom_subrect()
: Defines rectangles using their four corners (xmin
,
xmax
, ymin
, ymax
).
geom_subtile()
: Defines rectangles using the center (x
, y
) and
dimensions (width
, height
).
geom_subrect( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., byrow = TRUE, direction = NULL, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_subtile( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., byrow = TRUE, direction = NULL, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
geom_subrect( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., byrow = TRUE, direction = NULL, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_subtile( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., byrow = TRUE, direction = NULL, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
byrow |
A single boolean value indicates whether we should arrange the divided rectangles in the row-major order. |
direction |
A string specifying the arrangement direction:
|
lineend |
Line end style (round, butt, square). |
linejoin |
Line join style (round, mitre, bevel). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom_subrect()
understands the following aesthetics (required aesthetics are in bold):
Learn more about setting these aesthetics in vignette("ggplot2-specs", package = "ggplot2")
.
geom_subtile()
understands the following aesthetics (required aesthetics are in bold):
Learn more about setting these aesthetics in vignette("ggplot2-specs", package = "ggplot2")
.
# arranges by row ggplot(data.frame(value = letters[seq_len(5)])) + geom_subtile(aes(x = 1, y = 1, fill = value)) # arranges by column ggplot(data.frame(value = letters[seq_len(9)])) + geom_subtile(aes(x = 1, y = 1, fill = value), byrow = FALSE) # one-row ggplot(data.frame(value = letters[seq_len(4)])) + geom_subtile(aes(x = 1, y = 1, fill = value), direction = "h") # one-column ggplot(data.frame(value = letters[seq_len(4)])) + geom_subtile(aes(x = 1, y = 1, fill = value), direction = "v")
# arranges by row ggplot(data.frame(value = letters[seq_len(5)])) + geom_subtile(aes(x = 1, y = 1, fill = value)) # arranges by column ggplot(data.frame(value = letters[seq_len(9)])) + geom_subtile(aes(x = 1, y = 1, fill = value), byrow = FALSE) # one-row ggplot(data.frame(value = letters[seq_len(4)])) + geom_subtile(aes(x = 1, y = 1, fill = value), direction = "h") # one-column ggplot(data.frame(value = letters[seq_len(4)])) + geom_subtile(aes(x = 1, y = 1, fill = value), direction = "v")
ggalign_attr
provides access to supplementary information stored as
attributes during the layout rendering process in quad_layout()
/ggheatmap()
or stack_layout()
object. These
attributes, commonly attached during data transformation by functions like
fortify_matrix()
or fortify_data_frame()
, can include essential
details such as filtered or supplementary data that inform downstream
operations.
ggalign_attr(x, field = NULL)
ggalign_attr(x, field = NULL)
x |
Data used, typically inherited from the layout |
field |
A string specifying the particular data to retrieve from the
attached attribute. If |
Attributes attached to the data are particularly useful when input data is
transformed in ways that restrict access to the complete dataset. For
instance, fortify_matrix.MAF()
might filter mutation data while adding
attributes that retain essential context, such as the total number of
observations, for detailed or aggregated analyses.
The specified data from the attached attribute or NULL
if it is
unavailable.
ggalign_attr_set
: Attaches supplementary data to the input, facilitating
downstream use.
ggalign_attr_get
: Extracts previously attached supplementary data during
the transformation process.
ggalign_attr_set(x, values) ggalign_attr_get(x)
ggalign_attr_set(x, values) ggalign_attr_get(x)
x |
Input data for the layout. |
values |
A list to be attached. |
Attributes attached to the data are particularly useful when input data is
transformed in ways that restrict access to the complete dataset. For
instance, fortify_matrix.MAF()
might filter mutation data while adding
attributes that retain essential context, such as the total number of
observations, for detailed or aggregated analyses.
Get the statistics from the layout
ggalign_stat(x, ...) ## S3 method for class 'QuadLayout' ggalign_stat(x, position, ...) ## S3 method for class 'StackLayout' ggalign_stat(x, what, ...)
ggalign_stat(x, ...) ## S3 method for class 'QuadLayout' ggalign_stat(x, position, ...) ## S3 method for class 'StackLayout' ggalign_stat(x, what, ...)
x |
A |
... |
Arguments passed to methods. |
position |
A string of |
what |
A single number or string of the plot elements in the stack layout. |
The statistics
Generate a plot grob.
ggalignGrob(x)
ggalignGrob(x)
x |
An object to be converted into a grob. |
A grob()
object.
ggalignGrob(ggplot())
ggalignGrob(ggplot())
OncoPrint
Visualizations from Genetic Alteration DataThe ggoncoplot()
function generates oncoPrint
visualizations that display
genetic alterations in a matrix format. This function is especially useful
for visualizing complex genomic data, such as mutations, copy number
variations, and other genomic alterations in cancer research.
ggoncoplot( data = NULL, mapping = aes(), ..., map_width = NULL, map_height = NULL, reorder_row = reorder_column, reorder_column = TRUE, width = NA, height = NA, filling = waiver(), theme = NULL, active = NULL ) ## Default S3 method: ggoncoplot( data = NULL, mapping = aes(), ..., map_width = NULL, map_height = NULL, reorder_row = reorder_column, reorder_column = TRUE, width = NA, height = NA, filling = waiver(), theme = NULL, active = NULL )
ggoncoplot( data = NULL, mapping = aes(), ..., map_width = NULL, map_height = NULL, reorder_row = reorder_column, reorder_column = TRUE, width = NA, height = NA, filling = waiver(), theme = NULL, active = NULL ) ## Default S3 method: ggoncoplot( data = NULL, mapping = aes(), ..., map_width = NULL, map_height = NULL, reorder_row = reorder_column, reorder_column = TRUE, width = NA, height = NA, filling = waiver(), theme = NULL, active = NULL )
data |
A character matrix which encodes the alterations, you can use
|
mapping |
Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot. |
... |
Additional arguments passed to |
map_width , map_height
|
A named numeric value defines the width/height of each alterations. |
reorder_row , reorder_column
|
A boolean value indicating whether to reorder the rows/columns based on the frequency or characteristics of the alterations. |
width , height
|
The relative width/height of the main plot, can be a
|
filling |
Same as |
theme |
A |
active |
A |
ggoncoplot()
is a wrapper around the ggheatmap()
function, designed to
simplify the creation of OncoPrint
-style visualizations. The function
automatically processes the input character matrix by splitting the encoded
alterations (delimited by ";"
, ":"
, ","
, or "|"
) into
individual genomic events and unnesting the columns for visualization.
Additionally, a predefined reordering function, adapted from https://gist.github.com/armish/564a65ab874a770e2c26, is included to enhance the organization of the alterations.
A HeatmapLayout
object.
# A simple example from `ComplexHeatmap` mat <- read.table(textConnection( "s1,s2,s3 g1,snv;indel,snv,indel g2,,snv;indel,snv g3,snv,,indel;snv" ), row.names = 1, header = TRUE, sep = ",", stringsAsFactors = FALSE) ggoncoplot(mat, map_width = c(snv = 0.5), map_height = c(indel = 0.9)) + # Note that guide legends from `geom_tile` and `geom_bar` are different. # Although they appear similar, the internal mechanisms won't collapse # the guide legends. Therefore, we remove the guide legends from # `geom_tile`. guides(fill = "none") + anno_top(size = 0.5) + ggalign() + geom_bar(aes(fill = value), data = function(x) { subset(x, !is.na(value)) }) + anno_right(size = 0.5) + ggalign() + geom_bar(aes(fill = value), orientation = "y", data = function(x) { subset(x, !is.na(value)) }) & scale_fill_brewer(palette = "Dark2", na.translate = FALSE)
# A simple example from `ComplexHeatmap` mat <- read.table(textConnection( "s1,s2,s3 g1,snv;indel,snv,indel g2,,snv;indel,snv g3,snv,,indel;snv" ), row.names = 1, header = TRUE, sep = ",", stringsAsFactors = FALSE) ggoncoplot(mat, map_width = c(snv = 0.5), map_height = c(indel = 0.9)) + # Note that guide legends from `geom_tile` and `geom_bar` are different. # Although they appear similar, the internal mechanisms won't collapse # the guide legends. Therefore, we remove the guide legends from # `geom_tile`. guides(fill = "none") + anno_top(size = 0.5) + ggalign() + geom_bar(aes(fill = value), data = function(x) { subset(x, !is.na(value)) }) + anno_right(size = 0.5) + ggalign() + geom_bar(aes(fill = value), orientation = "y", data = function(x) { subset(x, !is.na(value)) }) & scale_fill_brewer(palette = "Dark2", na.translate = FALSE)
The ggwrap()
function allows non-ggplot2 elements to be converted into a
compliant representation for use with align_plots()
. This is useful for
adding any graphics that can be converted into a grob
with
the patch()
method.
ggwrap(plot, ..., align = "panel", on_top = TRUE, clip = TRUE, vp = NULL)
ggwrap(plot, ..., align = "panel", on_top = TRUE, clip = TRUE, vp = NULL)
plot |
Any graphic that can be converted into a |
... |
Additional arguments passed to the |
align |
A string specifying the area to place the plot: |
on_top |
A single boolean value indicates whether the graphic plot should be put frontmost. Note: the graphic plot will always put above the background. |
clip |
A single boolean value indicating whether the grob should be clipped if they expand outside their designated area. |
vp |
A |
A wrapped_plot
object that can be directly placed into
align_plots()
.
library(grid) ggwrap(rectGrob(gp = gpar(fill = "goldenrod")), align = "full") + inset(rectGrob(gp = gpar(fill = "steelblue")), align = "panel") + inset(textGrob("Here are some text", gp = gpar(color = "black")), align = "panel" ) p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) + ggtitle("Plot 1") align_plots(p1, ggwrap( ~ plot(mtcars$mpg, mtcars$disp), mar = c(0, 2, 0, 0), bg = NA ))
library(grid) ggwrap(rectGrob(gp = gpar(fill = "goldenrod")), align = "full") + inset(rectGrob(gp = gpar(fill = "steelblue")), align = "panel") + inset(textGrob("Here are some text", gp = gpar(color = "black")), align = "panel" ) p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) + ggtitle("Plot 1") align_plots(p1, ggwrap( ~ plot(mtcars$mpg, mtcars$disp), mar = c(0, 2, 0, 0), bg = NA ))
Generate Tree Structures with Hierarchical Clustering
hclust2( matrix, distance = "euclidean", method = "complete", use_missing = "pairwise.complete.obs" )
hclust2( matrix, distance = "euclidean", method = "complete", use_missing = "pairwise.complete.obs" )
matrix |
A numeric matrix, or data frame. |
distance |
A string of distance measure to be used. This must be one of
|
method |
A string of the agglomeration method to be used. This should be
(an unambiguous abbreviation of) one of |
use_missing |
An optional character string giving a method for computing
covariances in the presence of missing values. This must be (an abbreviation
of) one of the strings |
A hclust object.
hclust2(dist(USArrests), method = "ward.D")
hclust2(dist(USArrests), method = "ward.D")
heatmap_layout
is a specialized version of quad_alignb()
, which
simplifies the creation of heatmap plots by integrating essential elements
for a standard heatmap layout, ensuring that the appropriate data mapping and
visualization layers are automatically applied. ggheatmap
is an alias for
heatmap_layout
.
heatmap_layout( data = NULL, mapping = aes(), ..., width = NA, height = NA, filling = waiver(), theme = NULL, active = NULL, set_context = deprecated(), order = deprecated(), name = deprecated(), guides = deprecated() )
heatmap_layout( data = NULL, mapping = aes(), ..., width = NA, height = NA, filling = waiver(), theme = NULL, active = NULL, set_context = deprecated(), order = deprecated(), name = deprecated(), guides = deprecated() )
data |
Default dataset to use for the layout. If not specified, it must be supplied in each plot added to the layout. By default, it will try to inherit from parent layout. If not already a matrix, will be converted
to one by |
mapping |
Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot. |
... |
Additional arguments passed to |
width , height
|
The relative width/height of the main plot, can be a
|
filling |
A single string of For backward compatibility, a single boolean value is acceptable: By default, the classic heatmap color scheme
You can use the options
|
theme |
A |
active |
A |
set_context |
|
order |
|
name |
|
guides |
Please use
|
A HeatmapLayout
object.
The data input in ggheatmap
will be converted into the long formated data
frame when drawing. The default mapping will use aes(.data$.x, .data$.y)
,
you can use mapping
argument to control it. The data in the underlying
ggplot
object contains following columns:
.xpanel
and .ypanel
: the column and row panel
.x
and .y
: the x
and y
coordinates
.row_names
and .column_names
: A factor of the row and column names of
the original matrix (only applicable when names exist).
.row_index
and .column_index
: the row and column index of the original
matrix.
value
: the actual matrix value.
ggheatmap(1:10) ggheatmap(letters) ggheatmap(matrix(rnorm(81), nrow = 9L))
ggheatmap(1:10) ggheatmap(letters) ggheatmap(matrix(rnorm(81), nrow = 9L))
Create a ggplot inset
inset(plot, ..., align = "panel", on_top = TRUE, clip = TRUE, vp = NULL)
inset(plot, ..., align = "panel", on_top = TRUE, clip = TRUE, vp = NULL)
plot |
Any graphic that can be converted into a |
... |
Additional arguments passed to the |
align |
A string specifying the area to place the plot: |
on_top |
A single boolean value indicates whether the graphic plot should be put frontmost. Note: the graphic plot will always put above the background. |
clip |
A single boolean value indicating whether the grob should be clipped if they expand outside their designated area. |
vp |
A |
A patch_inset
object, which can be added in ggplot.
library(grid) p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p1 + inset(p2, vp = viewport(0.6, 0.6, just = c(0, 0), width = 0.4, height = 0.4 ))
library(grid) p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p1 + inset(p2, vp = viewport(0.6, 0.6, just = c(0, 0), width = 0.4, height = 0.4 ))
x
is layout objectReports whether x
is layout object
is_layout(x) is_quad_layout(x) is_stack_layout(x) is_heatmap_layout(x) is_ggheatmap(x)
is_layout(x) is_quad_layout(x) is_stack_layout(x) is_heatmap_layout(x) is_ggheatmap(x)
x |
An object to test. |
A single boolean value.
is_layout(ggheatmap(1:10)) # for quad_layout() is_quad_layout(quad_alignb(1:10)) is_quad_layout(quad_alignh(1:10)) is_quad_layout(quad_alignv(1:10)) is_quad_layout(quad_free(mtcars)) # for stack_layout() is_stack_layout(stack_align(1:10)) is_stack_layout(stack_free(1:10)) # for heatmap_layout() is_heatmap_layout(ggheatmap(1:10)) is_ggheatmap(ggheatmap(1:10))
is_layout(ggheatmap(1:10)) # for quad_layout() is_quad_layout(quad_alignb(1:10)) is_quad_layout(quad_alignh(1:10)) is_quad_layout(quad_alignv(1:10)) is_quad_layout(quad_free(mtcars)) # for stack_layout() is_stack_layout(stack_align(1:10)) is_stack_layout(stack_free(1:10)) # for heatmap_layout() is_heatmap_layout(ggheatmap(1:10)) is_ggheatmap(ggheatmap(1:10))
This function allows you to change the order in which layers are added to a ggplot.
layer_order(layer, order = 0)
layer_order(layer, order = 0)
layer |
A |
order |
An integer indicating the position at which the layer should be
added. If |
A layer_order
object.
ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density)) + geom_point(color = "red", size = 1) ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density)) + layer_order(geom_point(color = "red", size = 1))
ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density)) + geom_point(color = "red", size = 1) ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density)) + layer_order(geom_point(color = "red", size = 1))
modify the theme of the layout
layout_annotation(theme = waiver(), ...)
layout_annotation(theme = waiver(), ...)
theme |
A |
... |
These dots are for future extensions and must be empty. |
guides
, patch.title
, panel.border
, and background
will always be
added even for the nested alignpatches
object.
title
, subtitle
, caption
, and margins
will be added for the
top-level alignpatches
object only.
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl) align_plots( p1 + theme(plot.background = element_blank()), p2 + theme(plot.background = element_blank()), p3 + theme(plot.background = element_blank()) ) + layout_annotation( theme = theme(plot.background = element_rect(fill = "red")) )
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl) align_plots( p1 + theme(plot.background = element_blank()), p2 + theme(plot.background = element_blank()), p3 + theme(plot.background = element_blank()) ) + layout_annotation( theme = theme(plot.background = element_rect(fill = "red")) )
To control how different plots are laid out, you need to add a layout design specification. If you are nesting grids, the layout is scoped to the current nesting level.
layout_design( ncol = waiver(), nrow = waiver(), byrow = waiver(), widths = waiver(), heights = waiver(), design = waiver(), guides = NA )
layout_design( ncol = waiver(), nrow = waiver(), byrow = waiver(), widths = waiver(), heights = waiver(), design = waiver(), guides = NA )
ncol , nrow
|
The dimensions of the grid to create - if both are |
byrow |
If |
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. The
special value of |
design |
Specification of the location of areas in the layout. Can
either be specified as a text string or by concatenating calls to
|
guides |
A string with one or more of |
A layout_design
object.
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl) align_plots(p1, p2, p3) + layout_design(nrow = 1L) align_plots(p1, p2, p3) + layout_design(ncol = 1L)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl) align_plots(p1, p2, p3) + layout_design(nrow = 1L) align_plots(p1, p2, p3) + layout_design(ncol = 1L)
Annotate the whole layout
layout_title(title = waiver(), subtitle = waiver(), caption = waiver())
layout_title(title = waiver(), subtitle = waiver(), caption = waiver())
title |
The text for the title. |
subtitle |
The text for the subtitle for the plot which will be displayed below the title. |
caption |
The text for the caption which will be displayed in the bottom-right of the plot by default. |
A layout_title
object.
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl) align_plots(p1, p2, p3) + layout_title(title = "I'm title")
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p3 <- ggplot(mtcars) + geom_bar(aes(gear)) + facet_wrap(~cyl) align_plots(p1, p2, p3) + layout_title(title = "I'm title")
+
: Adds elements to the active plot in the active layout.
&
: Applies elements to all plots in the layout.
-
: Adds elements to multiple plots in the layout.
## S4 method for signature 'QuadLayout,ANY' Ops(e1, e2) ## S4 method for signature 'StackLayout,ANY' Ops(e1, e2)
## S4 method for signature 'QuadLayout,ANY' Ops(e1, e2) ## S4 method for signature 'StackLayout,ANY' Ops(e1, e2)
e1 |
A |
e2 |
An object to be added to the plot. |
The +
operator is straightforward and should be used as needed.
In order to reduce code repetition ggalign
provides two operators for
adding ggplot elements (geoms, themes, facets, etc.) to multiple/all plots in
quad_layout()
/ggheatmap()
or stack_layout()
object: -
and &
. See vignette("operator")
for details.
A modified Layout
object.
set.seed(123) small_mat <- matrix(rnorm(56), nrow = 7) ggheatmap(small_mat) + anno_top() + ggalign() + geom_point(aes(y = value)) # `&` operator apply it to all plots ggheatmap(small_mat) + anno_top() + align_dendro() & theme(panel.border = element_rect( colour = "red", fill = NA, linewidth = unit(2, "mm") )) # If the active layout is the annotation stack, the `-` operator will only # add the elements to all plots in the active annotation stack: ggheatmap(small_mat) + anno_left(size = 0.2) + align_dendro(aes(color = branch), k = 3L) + align_dendro(aes(color = branch), k = 3L) - # Modify the the color scales of all plots in the left annotation scale_color_brewer(palette = "Dark2") # If the active layout is the `ggstack()`/`stack_layout()` itself, `-` # applies the elements to all plots in the layout except the nested # `ggheatmap()`/`quad_layout()`. stack_alignv(small_mat) + align_dendro() + ggtitle("I'm from the parent stack") + ggheatmap() + # remove any active context stack_active() + align_dendro() + ggtitle("I'm from the parent stack") - # Modify the the color scales of all plots in the stack layout except the # heatmap layout scale_color_brewer(palette = "Dark2") - # set the background of all plots in the stack layout except the heatmap # layout theme(plot.background = element_rect(fill = "red"))
set.seed(123) small_mat <- matrix(rnorm(56), nrow = 7) ggheatmap(small_mat) + anno_top() + ggalign() + geom_point(aes(y = value)) # `&` operator apply it to all plots ggheatmap(small_mat) + anno_top() + align_dendro() & theme(panel.border = element_rect( colour = "red", fill = NA, linewidth = unit(2, "mm") )) # If the active layout is the annotation stack, the `-` operator will only # add the elements to all plots in the active annotation stack: ggheatmap(small_mat) + anno_left(size = 0.2) + align_dendro(aes(color = branch), k = 3L) + align_dendro(aes(color = branch), k = 3L) - # Modify the the color scales of all plots in the left annotation scale_color_brewer(palette = "Dark2") # If the active layout is the `ggstack()`/`stack_layout()` itself, `-` # applies the elements to all plots in the layout except the nested # `ggheatmap()`/`quad_layout()`. stack_alignv(small_mat) + align_dendro() + ggtitle("I'm from the parent stack") + ggheatmap() + # remove any active context stack_active() + align_dendro() + ggtitle("I'm from the parent stack") - # Modify the the color scales of all plots in the stack layout except the # heatmap layout scale_color_brewer(palette = "Dark2") - # set the background of all plots in the stack layout except the heatmap # layout theme(plot.background = element_rect(fill = "red"))
order2
returns a permutation which rearranges its first argument into
ascending order.
order2(x) ## S3 method for class 'hclust' order2(x) ## S3 method for class 'dendrogram' order2(x) ## S3 method for class 'ser_permutation_vector' order2(x) ## S3 method for class 'ser_permutation' order2(x)
order2(x) ## S3 method for class 'hclust' order2(x) ## S3 method for class 'dendrogram' order2(x) ## S3 method for class 'ser_permutation_vector' order2(x) ## S3 method for class 'ser_permutation' order2(x)
x |
Any objects can be extracting ordering. |
An integer vector unless any of the inputs has 2^31
or more
elements, when it is a double vector.
order2(hclust2(matrix(rnorm(100L), nrow = 10L)))
order2(hclust2(matrix(rnorm(100L), nrow = 10L)))
This function extends ggplot2's title functionality, allowing you to add titles to each border of the plot: top, left, bottom, and right.
patch_titles( top = waiver(), left = waiver(), bottom = waiver(), right = waiver() )
patch_titles( top = waiver(), left = waiver(), bottom = waiver(), right = waiver() )
top , left , bottom , right
|
A string specifying the title to be added to the top, left, bottom, and right border of the plot. |
You can also use labs() to specify the titles (use arguments
"top"
, "left"
, "bottom"
, and "right"
) for the top, left, bottom, and right borders of the
plot.
The appearance and alignment of these patch titles can be customized using theme():
plot.patch_title
/plot.patch_title.*
: Controls the text appearance of
patch titles. By default, plot.patch_title
inherit from plot.title
, and
settings for each border will inherit from plot.patch_title
, with the
exception of the angle
property, which is not inherited.
plot.patch_title.position
/plot.patch_title.position.*
: Determines the
alignment of the patch titles. By default, plot.patch_title.position
inherit from plot.title.position
, and settings for each border will
inherit from plot.patch_title
. The value "panel"
aligns the patch
titles with the plot panels. Setting this to "plot"
aligns the patch
title with the entire plot (excluding margins and plot tags).
A labels object to be added to ggplot.
ggplot(mtcars) + geom_point(aes(mpg, disp)) + patch_titles( top = "I'm top patch title", left = "I'm left patch title", bottom = "I'm bottom patch title", right = "I'm right patch title" )
ggplot(mtcars) + geom_point(aes(mpg, disp)) + patch_titles( top = "I'm top patch title", left = "I'm left patch title", bottom = "I'm bottom patch title", right = "I'm right patch title" )
The patch()
function is used by ggwrap()
and inset()
to convert
objects into a grob
.
## S3 method for class 'alignpatches' patch(x, ...)
## S3 method for class 'alignpatches' patch(x, ...)
x |
An object to be converted into a |
... |
Not used currently. |
A grob
object.
Other patch methods:
patch.Heatmap()
,
patch.formula()
,
patch.ggplot()
,
patch.grob()
,
patch.patch()
,
patch.patch_ggplot()
,
patch.patchwork()
,
patch.pheatmap()
,
patch.recordedplot()
,
patch.trellis()
The patch()
function is used by ggwrap()
and inset()
to convert
objects into a grob
.
## S3 method for class 'formula' patch(x, ..., device = NULL, name = NULL) ## S3 method for class ''function'' patch(x, ..., device = NULL, name = NULL)
## S3 method for class 'formula' patch(x, ..., device = NULL, name = NULL) ## S3 method for class ''function'' patch(x, ..., device = NULL, name = NULL)
x |
An object to be converted into a |
... |
Graphical Parameters passed on to par(). |
device |
A function that opens a graphics device for |
name |
A character identifier. |
A grob
object.
Other patch methods:
patch.Heatmap()
,
patch.alignpatches()
,
patch.ggplot()
,
patch.grob()
,
patch.patch()
,
patch.patch_ggplot()
,
patch.patchwork()
,
patch.pheatmap()
,
patch.recordedplot()
,
patch.trellis()
The patch()
function is used by ggwrap()
and inset()
to convert
objects into a grob
.
## S3 method for class 'ggplot' patch(x, ...)
## S3 method for class 'ggplot' patch(x, ...)
x |
An object to be converted into a |
... |
Not used currently. |
A grob
object.
Other patch methods:
patch.Heatmap()
,
patch.alignpatches()
,
patch.formula()
,
patch.grob()
,
patch.patch()
,
patch.patch_ggplot()
,
patch.patchwork()
,
patch.pheatmap()
,
patch.recordedplot()
,
patch.trellis()
The patch()
function is used by ggwrap()
and inset()
to convert
objects into a grob
.
## S3 method for class 'grob' patch(x, ...) ## S3 method for class 'gList' patch(x, ...)
## S3 method for class 'grob' patch(x, ...) ## S3 method for class 'gList' patch(x, ...)
x |
An object to be converted into a |
... |
Not used currently. |
A grob
object.
Other patch methods:
patch.Heatmap()
,
patch.alignpatches()
,
patch.formula()
,
patch.ggplot()
,
patch.patch()
,
patch.patch_ggplot()
,
patch.patchwork()
,
patch.pheatmap()
,
patch.recordedplot()
,
patch.trellis()
The patch()
function is used by ggwrap()
and inset()
to convert
objects into a grob
.
## S3 method for class 'Heatmap' patch(x, ..., device = NULL) ## S3 method for class 'HeatmapList' patch(x, ..., device = NULL) ## S3 method for class 'HeatmapAnnotation' patch(x, ..., device = NULL)
## S3 method for class 'Heatmap' patch(x, ..., device = NULL) ## S3 method for class 'HeatmapList' patch(x, ..., device = NULL) ## S3 method for class 'HeatmapAnnotation' patch(x, ..., device = NULL)
x |
An object to be converted into a |
... |
Additional arguments passed to draw(). |
device |
A function that opens a graphics device for temporary
rendering. By default this is an off-screen, in-memory device
based on the |
A grob
object.
Other patch methods:
patch.alignpatches()
,
patch.formula()
,
patch.ggplot()
,
patch.grob()
,
patch.patch()
,
patch.patch_ggplot()
,
patch.patchwork()
,
patch.pheatmap()
,
patch.recordedplot()
,
patch.trellis()
The patch()
function is used by ggwrap()
and inset()
to convert
objects into a grob
.
## S3 method for class 'patch' patch(x, ...)
## S3 method for class 'patch' patch(x, ...)
x |
An object to be converted into a |
... |
Not used currently. |
A grob
object.
Other patch methods:
patch.Heatmap()
,
patch.alignpatches()
,
patch.formula()
,
patch.ggplot()
,
patch.grob()
,
patch.patch_ggplot()
,
patch.patchwork()
,
patch.pheatmap()
,
patch.recordedplot()
,
patch.trellis()
The patch()
function is used by ggwrap()
and inset()
to convert
objects into a grob
.
## S3 method for class 'patch_ggplot' patch(x, ...)
## S3 method for class 'patch_ggplot' patch(x, ...)
x |
An object to be converted into a |
... |
Not used currently. |
A grob
object.
Other patch methods:
patch.Heatmap()
,
patch.alignpatches()
,
patch.formula()
,
patch.ggplot()
,
patch.grob()
,
patch.patch()
,
patch.patchwork()
,
patch.pheatmap()
,
patch.recordedplot()
,
patch.trellis()
The patch()
function is used by ggwrap()
and inset()
to convert
objects into a grob
.
## S3 method for class 'patchwork' patch(x, ...)
## S3 method for class 'patchwork' patch(x, ...)
x |
An object to be converted into a |
... |
Not used currently. |
A grob
object.
Other patch methods:
patch.Heatmap()
,
patch.alignpatches()
,
patch.formula()
,
patch.ggplot()
,
patch.grob()
,
patch.patch()
,
patch.patch_ggplot()
,
patch.pheatmap()
,
patch.recordedplot()
,
patch.trellis()
The patch()
function is used by ggwrap()
and inset()
to convert
objects into a grob
.
## S3 method for class 'pheatmap' patch(x, ...)
## S3 method for class 'pheatmap' patch(x, ...)
x |
An object to be converted into a |
... |
Not used currently. |
A grob
object.
Other patch methods:
patch.Heatmap()
,
patch.alignpatches()
,
patch.formula()
,
patch.ggplot()
,
patch.grob()
,
patch.patch()
,
patch.patch_ggplot()
,
patch.patchwork()
,
patch.recordedplot()
,
patch.trellis()
The patch()
function is used by ggwrap()
and inset()
to convert
objects into a grob
.
## S3 method for class 'recordedplot' patch(x, ..., device = NULL)
## S3 method for class 'recordedplot' patch(x, ..., device = NULL)
x |
An object to be converted into a |
... |
Not used currently. |
device |
A function that opens a graphics device for |
A grob
object.
Other patch methods:
patch.Heatmap()
,
patch.alignpatches()
,
patch.formula()
,
patch.ggplot()
,
patch.grob()
,
patch.patch()
,
patch.patch_ggplot()
,
patch.patchwork()
,
patch.pheatmap()
,
patch.trellis()
The patch()
function is used by ggwrap()
and inset()
to convert
objects into a grob
.
## S3 method for class 'trellis' patch(x, ..., device = NULL)
## S3 method for class 'trellis' patch(x, ..., device = NULL)
x |
An object to be converted into a |
... |
Arguments passed on to
|
device |
A function that opens a graphics device for temporary
rendering. By default this is an off-screen, in-memory device
based on the |
A grob
object.
Other patch methods:
patch.Heatmap()
,
patch.alignpatches()
,
patch.formula()
,
patch.ggplot()
,
patch.grob()
,
patch.patch()
,
patch.patch_ggplot()
,
patch.patchwork()
,
patch.pheatmap()
,
patch.recordedplot()
The plot_align()
function defines the align Specifications for plots.
plot_align(guides = NA, free_spaces = NA, free_labs = NA)
plot_align(guides = NA, free_spaces = NA, free_labs = NA)
guides |
A string with one or more of |
free_spaces |
A string with one or more of Usually you want to apply this with the whole layout, instead of individual plots. |
free_labs |
A string with one or more of |
A plot_align
object.
set.seed(123) mat <- matrix(rnorm(72), nrow = 8) # used in the layout, define the default action for all plots in the layout ggheatmap(mat) - plot_align(guides = NULL) + anno_right() + align_dendro(aes(color = branch), k = 3) # You can also add it for a single plot ggheatmap(mat) - # for all plots in the layout, we default won't collect any guide legends plot_align(guides = NULL) + # for the heatmap body, we collect guide legends in the right # note, the guide legends will be collected to the right side of the # layout which will overlap the legends in the right annotation plot_align(guides = "r") + anno_right() + align_dendro(aes(color = branch), k = 3) # to avoid overlapping, we can also collect the guide legends in the # right annotation ggheatmap(mat) - plot_align(guides = NULL) + plot_align(guides = "r") + anno_right() + align_dendro(aes(color = branch), k = 3) + plot_align(guides = "r")
set.seed(123) mat <- matrix(rnorm(72), nrow = 8) # used in the layout, define the default action for all plots in the layout ggheatmap(mat) - plot_align(guides = NULL) + anno_right() + align_dendro(aes(color = branch), k = 3) # You can also add it for a single plot ggheatmap(mat) - # for all plots in the layout, we default won't collect any guide legends plot_align(guides = NULL) + # for the heatmap body, we collect guide legends in the right # note, the guide legends will be collected to the right side of the # layout which will overlap the legends in the right annotation plot_align(guides = "r") + anno_right() + align_dendro(aes(color = branch), k = 3) # to avoid overlapping, we can also collect the guide legends in the # right annotation ggheatmap(mat) - plot_align(guides = NULL) + plot_align(guides = "r") + anno_right() + align_dendro(aes(color = branch), k = 3) + plot_align(guides = "r")
Transforms the plot data. Many functions in this package require a specific
data format to align observations, plot_data()
helps reformat data frames
as needed.
plot_data(data, inherit = FALSE)
plot_data(data, inherit = FALSE)
data |
A function to transform the plot data before rendering, referred
to as
Use this hook to modify the data for all |
inherit |
A single boolean value indicates whether to apply the parent
|
Defaults will attempt to inherit from the parent layout if the actual data is
inherited from the parent layout, with one exception: align_dendro()
, which
will not inherit the plot_data
by default.
plot_theme()
serves as the default theme and will always be overridden by
any theme()
settings applied directly to the plot. The default theme
(plot_theme()
) is applied first, followed by any specific theme()
settings, even if theme()
is added before plot_theme()
.
plot_theme( ..., line, rect, text, title, aspect.ratio, axis.title, axis.title.x, axis.title.x.top, axis.title.x.bottom, axis.title.y, axis.title.y.left, axis.title.y.right, axis.text, axis.text.x, axis.text.x.top, axis.text.x.bottom, axis.text.y, axis.text.y.left, axis.text.y.right, axis.text.theta, axis.text.r, axis.ticks, axis.ticks.x, axis.ticks.x.top, axis.ticks.x.bottom, axis.ticks.y, axis.ticks.y.left, axis.ticks.y.right, axis.ticks.theta, axis.ticks.r, axis.minor.ticks.x.top, axis.minor.ticks.x.bottom, axis.minor.ticks.y.left, axis.minor.ticks.y.right, axis.minor.ticks.theta, axis.minor.ticks.r, axis.ticks.length, axis.ticks.length.x, axis.ticks.length.x.top, axis.ticks.length.x.bottom, axis.ticks.length.y, axis.ticks.length.y.left, axis.ticks.length.y.right, axis.ticks.length.theta, axis.ticks.length.r, axis.minor.ticks.length, axis.minor.ticks.length.x, axis.minor.ticks.length.x.top, axis.minor.ticks.length.x.bottom, axis.minor.ticks.length.y, axis.minor.ticks.length.y.left, axis.minor.ticks.length.y.right, axis.minor.ticks.length.theta, axis.minor.ticks.length.r, axis.line, axis.line.x, axis.line.x.top, axis.line.x.bottom, axis.line.y, axis.line.y.left, axis.line.y.right, axis.line.theta, axis.line.r, legend.background, legend.margin, legend.spacing, legend.spacing.x, legend.spacing.y, legend.key, legend.key.size, legend.key.height, legend.key.width, legend.key.spacing, legend.key.spacing.x, legend.key.spacing.y, legend.frame, legend.ticks, legend.ticks.length, legend.axis.line, legend.text, legend.text.position, legend.title, legend.title.position, legend.position, legend.position.inside, legend.direction, legend.byrow, legend.justification, legend.justification.top, legend.justification.bottom, legend.justification.left, legend.justification.right, legend.justification.inside, legend.location, legend.box, legend.box.just, legend.box.margin, legend.box.background, legend.box.spacing, panel.background, panel.border, panel.spacing, panel.spacing.x, panel.spacing.y, panel.grid, panel.grid.major, panel.grid.minor, panel.grid.major.x, panel.grid.major.y, panel.grid.minor.x, panel.grid.minor.y, panel.ontop, plot.background, plot.title, plot.title.position, plot.subtitle, plot.caption, plot.caption.position, plot.tag, plot.tag.position, plot.tag.location, plot.margin, strip.background, strip.background.x, strip.background.y, strip.clip, strip.placement, strip.text, strip.text.x, strip.text.x.bottom, strip.text.x.top, strip.text.y, strip.text.y.left, strip.text.y.right, strip.switch.pad.grid, strip.switch.pad.wrap, complete = FALSE, validate = TRUE )
plot_theme( ..., line, rect, text, title, aspect.ratio, axis.title, axis.title.x, axis.title.x.top, axis.title.x.bottom, axis.title.y, axis.title.y.left, axis.title.y.right, axis.text, axis.text.x, axis.text.x.top, axis.text.x.bottom, axis.text.y, axis.text.y.left, axis.text.y.right, axis.text.theta, axis.text.r, axis.ticks, axis.ticks.x, axis.ticks.x.top, axis.ticks.x.bottom, axis.ticks.y, axis.ticks.y.left, axis.ticks.y.right, axis.ticks.theta, axis.ticks.r, axis.minor.ticks.x.top, axis.minor.ticks.x.bottom, axis.minor.ticks.y.left, axis.minor.ticks.y.right, axis.minor.ticks.theta, axis.minor.ticks.r, axis.ticks.length, axis.ticks.length.x, axis.ticks.length.x.top, axis.ticks.length.x.bottom, axis.ticks.length.y, axis.ticks.length.y.left, axis.ticks.length.y.right, axis.ticks.length.theta, axis.ticks.length.r, axis.minor.ticks.length, axis.minor.ticks.length.x, axis.minor.ticks.length.x.top, axis.minor.ticks.length.x.bottom, axis.minor.ticks.length.y, axis.minor.ticks.length.y.left, axis.minor.ticks.length.y.right, axis.minor.ticks.length.theta, axis.minor.ticks.length.r, axis.line, axis.line.x, axis.line.x.top, axis.line.x.bottom, axis.line.y, axis.line.y.left, axis.line.y.right, axis.line.theta, axis.line.r, legend.background, legend.margin, legend.spacing, legend.spacing.x, legend.spacing.y, legend.key, legend.key.size, legend.key.height, legend.key.width, legend.key.spacing, legend.key.spacing.x, legend.key.spacing.y, legend.frame, legend.ticks, legend.ticks.length, legend.axis.line, legend.text, legend.text.position, legend.title, legend.title.position, legend.position, legend.position.inside, legend.direction, legend.byrow, legend.justification, legend.justification.top, legend.justification.bottom, legend.justification.left, legend.justification.right, legend.justification.inside, legend.location, legend.box, legend.box.just, legend.box.margin, legend.box.background, legend.box.spacing, panel.background, panel.border, panel.spacing, panel.spacing.x, panel.spacing.y, panel.grid, panel.grid.major, panel.grid.minor, panel.grid.major.x, panel.grid.major.y, panel.grid.minor.x, panel.grid.minor.y, panel.ontop, plot.background, plot.title, plot.title.position, plot.subtitle, plot.caption, plot.caption.position, plot.tag, plot.tag.position, plot.tag.location, plot.margin, strip.background, strip.background.x, strip.background.y, strip.clip, strip.placement, strip.text, strip.text.x, strip.text.x.bottom, strip.text.x.top, strip.text.y, strip.text.y.left, strip.text.y.right, strip.switch.pad.grid, strip.switch.pad.wrap, complete = FALSE, validate = TRUE )
... |
A |
line |
all line elements ( |
rect |
all rectangular elements ( |
text |
all text elements ( |
title |
all title elements: plot, axes, legends ( |
aspect.ratio |
aspect ratio of the panel |
axis.title , axis.title.x , axis.title.y , axis.title.x.top , axis.title.x.bottom , axis.title.y.left , axis.title.y.right
|
labels of axes ( |
axis.text , axis.text.x , axis.text.y , axis.text.x.top , axis.text.x.bottom , axis.text.y.left , axis.text.y.right , axis.text.theta , axis.text.r
|
tick labels along axes ( |
axis.ticks , axis.ticks.x , axis.ticks.x.top , axis.ticks.x.bottom , axis.ticks.y , axis.ticks.y.left , axis.ticks.y.right , axis.ticks.theta , axis.ticks.r
|
tick marks along axes ( |
axis.minor.ticks.x.top , axis.minor.ticks.x.bottom , axis.minor.ticks.y.left , axis.minor.ticks.y.right , axis.minor.ticks.theta , axis.minor.ticks.r
|
minor tick marks along axes ( |
axis.ticks.length , axis.ticks.length.x , axis.ticks.length.x.top , axis.ticks.length.x.bottom , axis.ticks.length.y , axis.ticks.length.y.left , axis.ticks.length.y.right , axis.ticks.length.theta , axis.ticks.length.r
|
length of tick marks ( |
axis.minor.ticks.length , axis.minor.ticks.length.x , axis.minor.ticks.length.x.top , axis.minor.ticks.length.x.bottom , axis.minor.ticks.length.y , axis.minor.ticks.length.y.left , axis.minor.ticks.length.y.right , axis.minor.ticks.length.theta , axis.minor.ticks.length.r
|
length of minor tick marks ( |
axis.line , axis.line.x , axis.line.x.top , axis.line.x.bottom , axis.line.y , axis.line.y.left , axis.line.y.right , axis.line.theta , axis.line.r
|
lines along axes ( |
legend.background |
background of legend ( |
legend.margin |
the margin around each legend ( |
legend.spacing , legend.spacing.x , legend.spacing.y
|
the spacing between legends ( |
legend.key |
background underneath legend keys ( |
legend.key.size , legend.key.height , legend.key.width
|
size of legend keys ( |
legend.key.spacing , legend.key.spacing.x , legend.key.spacing.y
|
spacing
between legend keys given as a |
legend.frame |
frame drawn around the bar ( |
legend.ticks |
tick marks shown along bars or axes ( |
legend.ticks.length |
length of tick marks in legend ( |
legend.axis.line |
lines along axes in legends ( |
legend.text |
legend item labels ( |
legend.text.position |
placement of legend text relative to legend keys or bars ("top", "right", "bottom" or "left"). The legend text placement might be incompatible with the legend's direction for some guides. |
legend.title |
title of legend ( |
legend.title.position |
placement of legend title relative to the main legend ("top", "right", "bottom" or "left"). |
legend.position |
the default position of legends ("none", "left", "right", "bottom", "top", "inside") |
legend.position.inside |
A numeric vector of length two setting the
placement of legends that have the |
legend.direction |
layout of items in legends ("horizontal" or "vertical") |
legend.byrow |
whether the legend-matrix is filled by columns
( |
legend.justification |
anchor point for positioning legend inside plot ("center" or two-element numeric vector) or the justification according to the plot area when positioned outside the plot |
legend.justification.top , legend.justification.bottom , legend.justification.left , legend.justification.right , legend.justification.inside
|
Same as |
legend.location |
Relative placement of legends outside the plot as a
string. Can be |
legend.box |
arrangement of multiple legends ("horizontal" or "vertical") |
legend.box.just |
justification of each legend within the overall bounding box, when there are multiple legends ("top", "bottom", "left", or "right") |
legend.box.margin |
margins around the full legend area, as specified
using |
legend.box.background |
background of legend area ( |
legend.box.spacing |
The spacing between the plotting area and the
legend box ( |
panel.background |
background of plotting area, drawn underneath plot
( |
panel.border |
border around plotting area, drawn on top of plot so that
it covers tick marks and grid lines. This should be used with
|
panel.spacing , panel.spacing.x , panel.spacing.y
|
spacing between facet
panels ( |
panel.grid , panel.grid.major , panel.grid.minor , panel.grid.major.x , panel.grid.major.y , panel.grid.minor.x , panel.grid.minor.y
|
grid lines ( |
panel.ontop |
option to place the panel (background, gridlines) over
the data layers ( |
plot.background |
background of the entire plot ( |
plot.title |
plot title (text appearance) ( |
plot.title.position , plot.caption.position
|
Alignment of the plot title/subtitle
and caption. The setting for |
plot.subtitle |
plot subtitle (text appearance) ( |
plot.caption |
caption below the plot (text appearance)
( |
plot.tag |
upper-left label to identify a plot (text appearance)
( |
plot.tag.position |
The position of the tag as a string ("topleft",
"top", "topright", "left", "right", "bottomleft", "bottom", "bottomright")
or a coordinate. If a coordinate, can be a numeric vector of length 2 to
set the x,y-coordinate relative to the whole plot. The coordinate option
is unavailable for |
plot.tag.location |
The placement of the tag as a string, one of
|
plot.margin |
margin around entire plot ( |
strip.background , strip.background.x , strip.background.y
|
background of facet labels ( |
strip.clip |
should strip background edges and strip labels be clipped
to the extend of the strip background? Options are |
strip.placement |
placement of strip with respect to axes, either "inside" or "outside". Only important when axes and strips are on the same side of the plot. |
strip.text , strip.text.x , strip.text.y , strip.text.x.top , strip.text.x.bottom , strip.text.y.left , strip.text.y.right
|
facet labels ( |
strip.switch.pad.grid |
space between strips and axes when strips are
switched ( |
strip.switch.pad.wrap |
space between strips and axes when strips are
switched ( |
complete |
set this to |
validate |
|
Theme elements inherit properties from other theme elements hierarchically.
For example, axis.title.x.bottom
inherits from axis.title.x
which inherits
from axis.title
, which in turn inherits from text
. All text elements inherit
directly or indirectly from text
; all lines inherit from
line
, and all rectangular objects inherit from rect
.
This means that you can modify the appearance of multiple elements by
setting a single high-level component.
Learn more about setting these aesthetics in vignette("ggplot2-specs")
.
+.gg()
and %+replace%,
element_blank()
, element_line()
,
element_rect()
, and element_text()
for
details of the specific theme elements.
The modifying theme components and theme elements sections of the online ggplot2 book.
set.seed(123) small_mat <- matrix(rnorm(56), nrow = 8) ggheatmap(small_mat) + plot_theme(plot.background = element_rect(fill = "red")) # `plot_theme()` serves as the default theme and will always be # overridden by any `theme()` settings applied directly to the plot ggheatmap(small_mat) + theme(plot.background = element_rect(fill = "blue")) + plot_theme(plot.background = element_rect(fill = "red"))
set.seed(123) small_mat <- matrix(rnorm(56), nrow = 8) ggheatmap(small_mat) + plot_theme(plot.background = element_rect(fill = "red")) # `plot_theme()` serves as the default theme and will always be # overridden by any `theme()` settings applied directly to the plot ggheatmap(small_mat) + theme(plot.background = element_rect(fill = "blue")) + plot_theme(plot.background = element_rect(fill = "red"))
quad_active
: Sets the active context to the quad_layout()
/ggheatmap()
itself.
quad_anno
: Sets the active context to the specified annotation stack
based on the position
argument.
anno_top
: A special case of quad_anno
with position = "top"
.
anno_left
: A special case of quad_anno
with position = "left"
.
anno_bottom
: A special case of quad_anno
with position = "bottom"
.
anno_right
: A special case of quad_anno
with position = "right"
.
quad_active(width = NULL, height = NULL) quad_anno(position, size = NULL, free_guides = waiver(), what = waiver()) anno_top(size = NULL, free_guides = waiver(), what = waiver()) anno_left(size = NULL, free_guides = waiver(), what = waiver()) anno_bottom(size = NULL, free_guides = waiver(), what = waiver()) anno_right(size = NULL, free_guides = waiver(), what = waiver())
quad_active(width = NULL, height = NULL) quad_anno(position, size = NULL, free_guides = waiver(), what = waiver()) anno_top(size = NULL, free_guides = waiver(), what = waiver()) anno_left(size = NULL, free_guides = waiver(), what = waiver()) anno_bottom(size = NULL, free_guides = waiver(), what = waiver()) anno_right(size = NULL, free_guides = waiver(), what = waiver())
width , height
|
The relative width/height of the main plot, can be a
|
position |
A string of |
size |
A numeric value or an
|
free_guides |
Override the |
what |
What should get activated in the annotation stack?
A single number or string of the plot elements in the stack layout. If |
By default, quad_anno()
will try to initialize the annotation stack layout
using data from quad_layout()
/ggheatmap()
. However, there are situations where the
annotation stack cannot be initialized due to incompatible data formats
between quad_layout()
and the required format for the annotation stack.
This often occurs in quad_alignh()
and quad_alignv()
, where the
layout data is a matrix, but top and bottom annotations (in
quad_alignh()
) or left and right annotations (in quad_alignv()
)
require a data frame. In such cases, you must use quad_init()
to manually
initialize the annotation stack.
An object that can be added to quad_layout()
/ggheatmap()
.
These functions arrange plots around a main plot, allowing for flexible
alignment of observations in different directions. ggside
is an alias for
quad_free
.
quad_free
/ggside
: Never align observations.
quad_alignh
: Align observations in the horizontal direction.
quad_alignv
: Align observations in the vertical direction.
quad_alignb
: Align observations in both horizontal and vertical
directions.
quad_free( data = NULL, mapping = aes(), ..., theme = NULL, active = NULL, width = NA, height = NA ) quad_alignh( data = NULL, mapping = aes(), ..., theme = NULL, active = NULL, width = NA, height = NA ) quad_alignv( data = NULL, mapping = aes(), ..., theme = NULL, active = NULL, width = NA, height = NA ) quad_alignb( data = NULL, mapping = aes(), ..., theme = NULL, active = NULL, width = NA, height = NA )
quad_free( data = NULL, mapping = aes(), ..., theme = NULL, active = NULL, width = NA, height = NA ) quad_alignh( data = NULL, mapping = aes(), ..., theme = NULL, active = NULL, width = NA, height = NA ) quad_alignv( data = NULL, mapping = aes(), ..., theme = NULL, active = NULL, width = NA, height = NA ) quad_alignb( data = NULL, mapping = aes(), ..., theme = NULL, active = NULL, width = NA, height = NA )
data |
Default dataset to use for the layout. If not specified, it must be supplied in each plot added to the layout. By default, it will try to inherit from parent layout.
|
mapping |
Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot. |
... |
Additional arguments passed to |
theme |
A |
active |
A |
width , height
|
The relative width/height of the main plot, can be a
|
For quad_alignb
, quad_alignh
, and quad_alignv
, the data input will be
converted into the long formated data frame when drawing. The data in the
underlying ggplot
object contains following columns:
.xpanel
and .ypanel
: the column and row panel
.x
and .y
: the x
and y
coordinates
.row_names
and .column_names
: A factor of the row and column names of
the original matrix (only applicable when names exist).
.row_index
and .column_index
: the row and column index of the original
matrix.
value
: the actual matrix value.
Initializes an annotation stack with a user-specified data.
quad_init(position, data = waiver(), ...)
quad_init(position, data = waiver(), ...)
position |
A string of |
data |
Default dataset to use for the annotation stack. If not specified, a dataset must be provided for each plot added to the layout. Possible values:
Data conversion depends on whether the annotation stack will align the observations:
|
... |
Additional arguments passed to |
This function integrates the functionalities of quad_free()
,
quad_alignh()
, quad_alignv()
, and quad_alignb()
into a single
interface.
quad_layout( data = NULL, align = NULL, mapping = aes(), ..., theme = NULL, active = NULL, width = NA, height = NA )
quad_layout( data = NULL, align = NULL, mapping = aes(), ..., theme = NULL, active = NULL, width = NA, height = NA )
data |
Default dataset to use for the layout. If not specified, it must be supplied in each plot added to the layout. By default, it will try to inherit from parent layout. The conversion of data depends on the
|
align |
A string indicating the alignment direction:
By default, the function does not align observations. |
mapping |
Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot. |
... |
Additional arguments passed to |
theme |
A |
active |
A |
width , height
|
The relative width/height of the main plot, can be a
|
quad_switch()
integrates quad_active()
and quad_anno()
into one
function for ease of use. This function allows you to quickly change the
active context of the quad_layout()
and its annotations.
hmanno
is an alias for quad_switch
, with additional arguments for
backward compatibility
quad_switch( position = NULL, size = NULL, width = NULL, height = NULL, free_guides = waiver(), what = waiver() ) hmanno( position = NULL, size = NULL, width = NULL, height = NULL, free_guides = waiver(), what = waiver(), ..., guides = deprecated(), free_spaces = deprecated(), plot_data = deprecated(), theme = deprecated(), free_labs = deprecated() )
quad_switch( position = NULL, size = NULL, width = NULL, height = NULL, free_guides = waiver(), what = waiver() ) hmanno( position = NULL, size = NULL, width = NULL, height = NULL, free_guides = waiver(), what = waiver(), ..., guides = deprecated(), free_spaces = deprecated(), plot_data = deprecated(), theme = deprecated(), free_labs = deprecated() )
position |
A string of |
size |
A numeric value or an
|
width , height
|
The relative width/height of the main plot, can be a
|
free_guides |
Override the |
what |
What should get activated in the annotation stack?
A single number or string of the plot elements in the stack layout. If |
... |
These dots are for future extensions and must be empty. |
guides |
Please use
|
free_spaces |
Please use
|
plot_data |
Please use
|
theme |
Please use
|
free_labs |
Please use
|
An object that can be added to quad_layout()
/ggheatmap()
.
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + align_dendro()
ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + align_dendro()
The function rasterizes input graphical objects (e.g., grob, layer, ggplot) and optionally processes the resulting raster using magick, a powerful image manipulation library. This allows for advanced graphical transformations directly within the plotting pipeline.
raster_magick(x, magick = NULL, ..., res = NULL, interpolate = FALSE)
raster_magick(x, magick = NULL, ..., res = NULL, interpolate = FALSE)
x |
An object to rasterize, can be a |
magick |
A function (purrr-style formula is accepted) that takes an
|
... |
Not used currently. |
res |
An integer sets the desired resolution in pixels. |
interpolate |
A logical value indicating whether to linearly interpolate the image (the alternative is to use nearest-neighbour interpolation, which gives a more blocky result). |
An object with the same class of the input.
# data generated code was copied from `ComplexHeatmap` set.seed(123) small_mat <- matrix(rnorm(56), nrow = 7) rownames(small_mat) <- paste0("row", seq_len(nrow(small_mat))) colnames(small_mat) <- paste0("column", seq_len(ncol(small_mat))) ggheatmap(small_mat, filling = NULL) + raster_magick(geom_tile(aes(fill = value)), dpi = 20) ggheatmap(small_mat, filling = NULL) + # Use `magick::filter_types()` to check available `filter` arguments raster_magick(geom_tile(aes(fill = value)), magick = function(image) { magick::image_resize(image, geometry = "50%x", filter = "Lanczos" ) } )
# data generated code was copied from `ComplexHeatmap` set.seed(123) small_mat <- matrix(rnorm(56), nrow = 7) rownames(small_mat) <- paste0("row", seq_len(nrow(small_mat))) colnames(small_mat) <- paste0("column", seq_len(ncol(small_mat))) ggheatmap(small_mat, filling = NULL) + raster_magick(geom_tile(aes(fill = value)), dpi = 20) ggheatmap(small_mat, filling = NULL) + # Use `magick::filter_types()` to check available `filter` arguments raster_magick(geom_tile(aes(fill = value)), magick = function(image) { magick::image_resize(image, geometry = "50%x", filter = "Lanczos" ) } )
This function reads example data from the file. If no file is specified, it returns a list of available example files.
read_example(file = NULL)
read_example(file = NULL)
file |
A string representing the name of the example file to be read. If
|
If file
is NULL
, returns a character vector of available example
file names. Otherwise, returns the contents of the specified example file,
read as an R object.
read_example()
read_example()
draw
aestheticScale for draw
aesthetic
scale_draw_manual( ..., values, aesthetics = "draw", breaks = waiver(), na.value = NA )
scale_draw_manual( ..., values, aesthetics = "draw", breaks = waiver(), na.value = NA )
... |
Arguments passed on to
|
values |
A list of functions (including purrr-like lambda syntax) that define how each cell's grob (graphical object) should be drawn. |
aesthetics |
Character string or vector of character strings listing the
name(s) of the aesthetic(s) that this scale works with. This can be useful, for
example, to apply colour settings to the |
breaks |
One of:
|
na.value |
The aesthetic value to use for missing ( |
geom_draw
depends on the new aesthetics draw
, which should always be
provided with scale_draw_manual()
, in which, we can provide a list of
functions that define how each cell's grob (graphical object) should be
drawn. This aesthetic allows you to replace the default rendering of cells
with custom behavior, making it possible to tailor the plot to specific
requirements.
geom_draw()
understands the following aesthetics (required aesthetics are in bold):
Learn more about setting these aesthetics in vignette("ggplot2-specs", package = "ggplot2")
.
library(grid) ggplot(data.frame(value = letters[seq_len(5)], y = seq_len(5))) + geom_draw(aes(x = 1, y = y, draw = value, fill = value)) + scale_draw_manual(values = list( a = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, b = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, c = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, d = function(x, y, width, height, shape) { gList( pointsGrob(x, y, pch = shape), # To ensure the rectangle color is shown in the legends, you # must explicitly provide a color argument and include it in # the `gpar()` of the graphical object rectGrob(x, y, width, height, gp = gpar(col = "black", fill = NA) ) ) }, e = function(xmin, xmax, ymin, ymax) { segmentsGrob( xmin, ymin, xmax, ymax, gp = gpar(lwd = 2) ) } )) + scale_fill_brewer(palette = "Dark2") + theme_void()
library(grid) ggplot(data.frame(value = letters[seq_len(5)], y = seq_len(5))) + geom_draw(aes(x = 1, y = y, draw = value, fill = value)) + scale_draw_manual(values = list( a = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, b = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, c = function(x, y, width, height, fill) { rectGrob(x, y, width = width, height = height, gp = gpar(fill = fill), default.units = "native" ) }, d = function(x, y, width, height, shape) { gList( pointsGrob(x, y, pch = shape), # To ensure the rectangle color is shown in the legends, you # must explicitly provide a color argument and include it in # the `gpar()` of the graphical object rectGrob(x, y, width, height, gp = gpar(col = "black", fill = NA) ) ) }, e = function(xmin, xmax, ymin, ymax) { segmentsGrob( xmin, ymin, xmax, ymax, gp = gpar(lwd = 2) ) } )) + scale_fill_brewer(palette = "Dark2") + theme_void()
The stack_align
function aligns observations, while stack_free
does not.
Several aliases are provided for convenience:
stack_alignv
: A special case of stack_align
that sets direction = "vertical"
.
stack_alignh
: A special case of stack_align
that sets direction = "horizontal"
.
stack_freev
: A special case of stack_free
that sets direction = "vertical"
.
stack_freeh
: A special case of stack_free
that sets direction = "horizontal"
.
stack_align(data = NULL, direction = NULL, ..., theme = NULL, sizes = NA) stack_alignv(data = NULL, ...) stack_alignh(data = NULL, ...) stack_free(data = NULL, direction = NULL, ..., theme = NULL, sizes = NA) stack_freev(data = NULL, ...) stack_freeh(data = NULL, ...)
stack_align(data = NULL, direction = NULL, ..., theme = NULL, sizes = NA) stack_alignv(data = NULL, ...) stack_alignh(data = NULL, ...) stack_free(data = NULL, direction = NULL, ..., theme = NULL, sizes = NA) stack_freev(data = NULL, ...) stack_freeh(data = NULL, ...)
data |
Default dataset to use for the layout. If not specified, it must be supplied in each plot added to the layout. By default, it will try to inherit from parent layout:
|
direction |
A string indicating the direction of the stack layout,
either |
... |
Additional arguments passed to |
theme |
A |
sizes |
A numeric or a |
set.seed(123) stack_align(matrix(rnorm(56), nrow = 7L), "h") + align_dendro()
set.seed(123) stack_align(matrix(rnorm(56), nrow = 7L), "h") + align_dendro()
This function integrates the functionalities of stack_free()
and
stack_align()
into a single interface. ggstack
is an alias for
stack_layout
.
stack_layout(data = NULL, direction = NULL, type = NULL, ...)
stack_layout(data = NULL, direction = NULL, type = NULL, ...)
data |
Default dataset to use for the layout. If not specified, it must be supplied in each plot added to the layout. By default, it will try to inherit from parent layout:
|
direction |
A string indicating the direction of the stack layout,
either |
type |
A string indicating the stack layout type: |
... |
Additional arguments passed to |
A StackLayout
object.
set.seed(123) small_mat <- matrix(rnorm(56), nrow = 7L) stack_layout(small_mat, "h", "align") + align_dendro() # ggstack is an alias for `stack_layout` ggstack(small_mat, "h", "align") + align_dendro() # this is the same with: stack_align(small_mat, "h") + align_dendro()
set.seed(123) small_mat <- matrix(rnorm(56), nrow = 7L) stack_layout(small_mat, "h", "align") + align_dendro() # ggstack is an alias for `stack_layout` ggstack(small_mat, "h", "align") + align_dendro() # this is the same with: stack_align(small_mat, "h") + align_dendro()
stack_active
is an alias for stack_switch()
, which sets what = NULL
by
default, with additional arguments for backward compatibility.
stack_switch(sizes = NULL, what = waiver()) stack_active( sizes = NULL, what = NULL, ..., guides = deprecated(), free_spaces = deprecated(), plot_data = deprecated(), theme = deprecated(), free_labs = deprecated() )
stack_switch(sizes = NULL, what = waiver()) stack_active( sizes = NULL, what = NULL, ..., guides = deprecated(), free_spaces = deprecated(), plot_data = deprecated(), theme = deprecated(), free_labs = deprecated() )
sizes |
A numeric or a |
what |
What should get activated for the stack layout?
A single number or string of the plot elements in the stack layout. If |
... |
These dots are for future extensions and must be empty. |
guides |
Please use
|
free_spaces |
Please use
|
plot_data |
Please use
|
theme |
Please use
|
free_labs |
Please use
|
A stack_switch
object which can be added to stack_layout()
.
stack_align(matrix(1:9, nrow = 3L), "h") + ggheatmap() + # ggheamtap will set the active context, directing following addition # into the heatmap plot area. To remove the heatmap active context, # we can use `stack_active()` which will direct subsequent addition into # the stack stack_active() + # here we add a dendrogram to the stack. align_dendro()
stack_align(matrix(1:9, nrow = 3L), "h") + ggheatmap() + # ggheamtap will set the active context, directing following addition # into the heatmap plot area. To remove the heatmap active context, # we can use `stack_active()` which will direct subsequent addition into # the stack stack_active() + # here we add a dendrogram to the stack. align_dendro()
Default theme for quad_layout()
/ggheatmap()
or stack_layout()
object.
theme_ggalign(...)
theme_ggalign(...)
... |
Arguments passed on to
|
You can change the default theme using the option
"ggalign.default_theme"
. This option should be
set to a function that returns a theme()
object.
A theme()
object.
# Setting a new default theme old <- options(ggalign.default_theme = function() theme_bw()) # Creating a heatmap with the new theme ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + align_dendro(k = 3L) # Restoring the old default theme options(old)
# Setting a new default theme old <- options(ggalign.default_theme = function() theme_bw()) # Creating a heatmap with the new theme ggheatmap(matrix(rnorm(81), nrow = 9)) + anno_top() + align_dendro(k = 3L) # Restoring the old default theme options(old)
Remove axis elements
theme_no_axes( axes = "xy", text = TRUE, ticks = TRUE, title = TRUE, line = FALSE )
theme_no_axes( axes = "xy", text = TRUE, ticks = TRUE, title = TRUE, line = FALSE )
axes |
Which axes elements should be removed? A string containing
one or more of |
text |
If |
ticks |
If |
title |
If |
line |
If |
A theme()
object.
p <- ggplot() + geom_point(aes(x = wt, y = qsec), data = mtcars) p + theme_no_axes() p + theme_no_axes("b") p + theme_no_axes("l")
p <- ggplot() + geom_point(aes(x = wt, y = qsec), data = mtcars) p + theme_no_axes() p + theme_no_axes("b") p + theme_no_axes("l")
quad_layout()
The with_quad()
function modifies the application context of elements in
ggheatmap()
/quad_layout()
. It controls how objects like themes, scales,
or other plot modifications apply to specific annotation stacks or the main
plot without altering the currently active layout or plot.
with_quad(x, position = waiver(), main = NULL)
with_quad(x, position = waiver(), main = NULL)
x |
An object which can be added to the ggplot, including
plot options (see |
position |
A string specifying one or more positions-
|
main |
A single boolean value indicating whether |
Default Behavior by wrapping object with with_quad()
:
For quad_layout()
object:
When ggheatmap()
/quad_layout()
has no active annotation stack, objects
added via +
or -
operate normally without with_quad()
.
When the active annotation stack is set, with_quad()
ensures the applied
object also modifies:
The main plot (by default).
Opposite annotation stacks when using -
.
For stack_layout()
object:
When the active layout is the stack_layout()
itself:
-
operator will apply changes to all plots along the
stack_layout()
, which means if the stack layout is in horizontal
,
-
operator will also add the element to the left
and right
annotation, if the stack layout is in vertical
, -
operator will
also add element to the top
and bottom
annotation.
+
operator won't do anything special.
When the active layout is the nested ggheatmap()
/quad_layout()
, the
+
/-
operator applies the elements to this nested layout, following the
same principles as for ggheatmap()
/quad_layout()
.
The original object with an added attribute that sets the specified context.
set.seed(123) small_mat <- matrix(rnorm(56), nrow = 7) # By wrapping object with `with_quad()`, the `+` operator will apply the # object not only to the active plot in the annotation stack, but also to # the main plot unless specified by `main` argument otherwise. ggheatmap(small_mat) + # initialize the left annotation anno_left(size = 0.2) + align_dendro() + # apply the object not only to the active plot in the annotation stack, # but also to the main plot with_quad(theme(plot.background = element_rect(fill = "red"))) # the `-` operator will apply changes not only to the active annotation # stack but also to the opposite one (i.e., bottom if top is active, and # vice versa). The same principle applies to the left and right annotation. ggheatmap(small_mat) + anno_left(size = 0.2) + align_dendro(aes(color = branch), k = 3L) + # Change the active layout to the left annotation anno_top(size = 0.2) + align_dendro(aes(color = branch), k = 3L) + anno_bottom(size = 0.2) + align_dendro(aes(color = branch), k = 3L) - # Modify the color scale of all plots in the bottom and the opposite # annotation, in this way, the `main` argument by default would be `TRUE` with_quad(scale_color_brewer(palette = "Dark2", name = "Top and bottom")) # When the `position` argument is manually set, the # default value of the `main` argument will be `FALSE`. ggheatmap(small_mat) + anno_left(size = 0.2) + align_dendro(aes(color = branch), k = 3L) + anno_top(size = 0.2) + align_dendro(aes(color = branch), k = 3L) + anno_bottom(size = 0.2) + align_dendro(aes(color = branch), k = 3L) - # Modify the background of all plots in the left and top annotation with_quad(theme(plot.background = element_rect(fill = "red")), "tl")
set.seed(123) small_mat <- matrix(rnorm(56), nrow = 7) # By wrapping object with `with_quad()`, the `+` operator will apply the # object not only to the active plot in the annotation stack, but also to # the main plot unless specified by `main` argument otherwise. ggheatmap(small_mat) + # initialize the left annotation anno_left(size = 0.2) + align_dendro() + # apply the object not only to the active plot in the annotation stack, # but also to the main plot with_quad(theme(plot.background = element_rect(fill = "red"))) # the `-` operator will apply changes not only to the active annotation # stack but also to the opposite one (i.e., bottom if top is active, and # vice versa). The same principle applies to the left and right annotation. ggheatmap(small_mat) + anno_left(size = 0.2) + align_dendro(aes(color = branch), k = 3L) + # Change the active layout to the left annotation anno_top(size = 0.2) + align_dendro(aes(color = branch), k = 3L) + anno_bottom(size = 0.2) + align_dendro(aes(color = branch), k = 3L) - # Modify the color scale of all plots in the bottom and the opposite # annotation, in this way, the `main` argument by default would be `TRUE` with_quad(scale_color_brewer(palette = "Dark2", name = "Top and bottom")) # When the `position` argument is manually set, the # default value of the `main` argument will be `FALSE`. ggheatmap(small_mat) + anno_left(size = 0.2) + align_dendro(aes(color = branch), k = 3L) + anno_top(size = 0.2) + align_dendro(aes(color = branch), k = 3L) + anno_bottom(size = 0.2) + align_dendro(aes(color = branch), k = 3L) - # Modify the background of all plots in the left and top annotation with_quad(theme(plot.background = element_rect(fill = "red")), "tl")