Title: | Create customisable ggplot2 matrix |
---|---|
Description: | More about what it does (maybe more than one line) Use four spaces when indenting paragraphs within the Description. |
Authors: | Cynthia Huang [aut, cre] |
Maintainer: | Cynthia Huang <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.0.0.9000 |
Built: | 2024-11-10 03:59:46 UTC |
Source: | https://github.com/cynthiahqy/ggtilematrix |
Plot a matrix as a ggplot2 object
gg_tilematrix.matrix( .matrix, .geom = list(geom_tile(color = "pink", fill = "blue"), geom_text()), .scale_coord = list(scale_y_discrete(limits = base::rev), scale_x_discrete(position = "top"), coord_fixed()), .theme = list(theme_bw()), .layers = list(labs(x = NULL, y = NULL)) )
gg_tilematrix.matrix( .matrix, .geom = list(geom_tile(color = "pink", fill = "blue"), geom_text()), .scale_coord = list(scale_y_discrete(limits = base::rev), scale_x_discrete(position = "top"), coord_fixed()), .theme = list(theme_bw()), .layers = list(labs(x = NULL, y = NULL)) )
.matrix |
A matrix to plot |
.layers |
library(ggplot2) matrices$unnamed |> gg_tilematrix.matrix()
library(ggplot2) matrices$unnamed |> gg_tilematrix.matrix()
Converts a named (adjacency) matrix into (graph) triples, dropping any NA cells by default.
matrix_to_triples( matrix, x_names_to = "x_name", y_names_to = "y_name", values_to = "value", drop_na = TRUE ) triples_from_matrix( matrix, x_names_to = "x_name", y_names_to = "y_name", values_to = "value", drop_na = TRUE )
matrix_to_triples( matrix, x_names_to = "x_name", y_names_to = "y_name", values_to = "value", drop_na = TRUE ) triples_from_matrix( matrix, x_names_to = "x_name", y_names_to = "y_name", values_to = "value", drop_na = TRUE )
matrix |
A matrix to pivot |
x_names_to |
A string specifying the new column for
the names of the first/x-dimension of |
y_names_to |
A string specifying the new column for
the names of the second/y-dimension |
values_to |
A character vector specifying the new column to create
from the cell values of |
drop_na |
Boolean option to drop |
Uses pivot_longer and reverses triples_to_matrix()
.
Setting drop_na=FALSE
retain the complete set of graph edges.
If matrix
is unnamed, default names are generated by base::as.data.frame()
## named matrices blx_mtx <- triples$blx_tbl |> triples_to_matrix(from, to, weighted) return_triples <- blx_mtx |> triples_from_matrix("from", "to", "weighted") identical(triples$blx_tbl, return_triples) ## Setting `drop_na=FALSE` retains the `x`-`y` pairs with missing values, return_with_na <- blx_mtx |> triples_from_matrix("from", "to", "weighted", drop_na = FALSE) ## which is equivalent to using `tidyr::complete()` on the original triples complete_triples <- triples$blx_tbl |> tidyr::complete(from, to) identical(return_with_na, complete_triples) ## names are generated for unnamed matrices matrices$unnamed |> matrix_to_triples(drop_na = FALSE)
## named matrices blx_mtx <- triples$blx_tbl |> triples_to_matrix(from, to, weighted) return_triples <- blx_mtx |> triples_from_matrix("from", "to", "weighted") identical(triples$blx_tbl, return_triples) ## Setting `drop_na=FALSE` retains the `x`-`y` pairs with missing values, return_with_na <- blx_mtx |> triples_from_matrix("from", "to", "weighted", drop_na = FALSE) ## which is equivalent to using `tidyr::complete()` on the original triples complete_triples <- triples$blx_tbl |> tidyr::complete(from, to) identical(return_with_na, complete_triples) ## names are generated for unnamed matrices matrices$unnamed |> matrix_to_triples(drop_na = FALSE)
Converts a data frame of triples (x_names
, y_names
, values
) into
a matrix with x_names
and y_names
respectively
for row and column names and cell values from values
.
triples_to_matrix( triples, x_names_from = x_name, y_names_from = y_name, values_from = value, values_fill = NA ) matrix_from_tripes( triples, x_names_from = x_name, y_names_from = y_name, values_from = value, values_fill = NA )
triples_to_matrix( triples, x_names_from = x_name, y_names_from = y_name, values_from = value, values_fill = NA ) matrix_from_tripes( triples, x_names_from = x_name, y_names_from = y_name, values_from = value, values_fill = NA )
triples |
A data frame to pivot. Unused columns are dropped. |
x_names_from |
column to get matrix row row names from. |
y_names_from |
column to get matrix column names from. |
values_from |
column to get cell values from. |
values_fill |
Optionally, a (scalar) value that specifies what each
This can be a named list if you want to apply different fill values to different value columns. |
The triples define graph edges between x_names
and y_names
with
attribute value
. x_names
and y_names
are treated as disjoint nodes sets
of the bi-partite graph,
and the resultant matrix corresponds to the bi-adjacency matrix.
Uses pivot_wider and makes explicit
all possible pairs of x_names
and y_names
.
triples$blx_tbl triples$blx_tbl |> triples_to_matrix(from, to, weighted)
triples$blx_tbl triples$blx_tbl |> triples_to_matrix(from, to, weighted)