plot_popkin | R Documentation |
This function plots one or more kinship matrices, trees (class phylo
objects, see ape
package), and arbitrary functions, and a shared legend for the kinship color key.
Many options allow for fine control of individual or subpopulation labeling.
plot_popkin( kinship, titles = NULL, col = NULL, col_n = 100, mar = NULL, mar_pad = 0.2, oma = 1.5, diag_line = FALSE, panel_letters = toupper(letters), panel_letters_cex = 1.5, panel_letters_adj = -0.1, ylab = "Individuals", ylab_adj = NA, ylab_line = 0, ylab_side = 2, ylab_per_panel = FALSE, layout_add = TRUE, layout_rows = 1, leg_per_panel = FALSE, leg_title = "Kinship", leg_cex = 1, leg_n = 5, leg_mar = 3, leg_width = 0.3, leg_column = NA, names = FALSE, names_cex = 1, names_line = NA, names_las = 2, labs = NULL, labs_cex = 1, labs_las = 0, labs_line = 0, labs_sep = TRUE, labs_lwd = 1, labs_col = "black", labs_ticks = FALSE, labs_text = TRUE, labs_even = FALSE, null_panel_data = FALSE, weights = NULL, raster = is.null(weights), sym = FALSE, ... )
kinship |
A numeric kinship matrix, a |
titles |
Titles to add to each matrix panel (default is no titles). Applied to kinship and phylo panels only. |
col |
Colors for kinship heatmap (default is a red-white-blue palette symmetric about zero constructed using |
col_n |
The number of colors to use in the heatmap (applies if |
mar |
Margins shared by all panels (if a vector) or for each panel (if a list of such vectors).
If the vector has length 1, |
mar_pad |
Margin padding added to all panels ( |
oma |
Outer margin vector.
If length 1, the value of |
diag_line |
If |
panel_letters |
Vector of strings for labeling panels (default A-Z).
No labels are added if |
panel_letters_cex |
Scaling factor of panel letters (default 1.5). |
panel_letters_adj |
X-axis adjustment for panel letters (default -0.1). Negative values place the letter into the left margin area. Might need adjustment depending on the size of the left margin. |
ylab |
The y-axis label (default "Individuals").
If |
ylab_adj |
The value of |
ylab_line |
The value of |
ylab_side |
The value of |
ylab_per_panel |
Forces y-axis labels to appear for each panel, in the inner margins.
Most useful to cover the case where there is a single panel but no outer margins ( LAYOUT OPTIONS |
layout_add |
If |
layout_rows |
Number of rows in layout, used only if LEGEND (COLOR KEY) OPTIONS |
leg_per_panel |
If |
leg_title |
The name of the variable that the kinship heatmap colors measure (default "Kinship"), or a vector of such values if they vary per panel. |
leg_cex |
Scaling factor for |
leg_n |
The desired number of ticks in the kinship legend y-axis, and phylo x-axis (input to |
leg_mar |
Margin values for the kinship legend panel only, or a list of such values if they vary per panel.
A length-4 vector (in |
leg_width |
The width of the legend panel, relative to the width of a single main panel.
This value is passed to |
leg_column |
The column number in which to place the kinship legend (default INDIVIDUAL LABEL OPTIONS |
names |
If |
names_cex |
Scaling factor for the column and row names of a kinship matrix, or the tip labels of a |
names_line |
Line where kinship column and row names are placed, or a vector of such values if they vary per panel. Has no effect on non-kinship panels. |
names_las |
Orientation of labels relative to axis. Default (2) makes labels perpendicular to axis. Has no effect on non-kinship panels. SUBPOPULATION LABEL OPTIONS |
labs |
Subpopulation labels for individuals in kinship matrices. Use a matrix of labels (individuals along rows, levels along columns) to show groupings at more than one level (for a hierarchy or otherwise). If input is a vector or a matrix, the same subpopulation labels are shown for every kinship matrix; the input must be a list of such vectors or matrices if the labels vary per panel. Has no effect on non-kinship panels. |
labs_cex |
A vector of label scaling factors for each level of labs, or a list of such vectors if labels vary per panel. |
labs_las |
A vector of label orientations (in format that |
labs_line |
A vector of lines where labels are placed (in format that |
labs_sep |
A vector of logicals that specify whether lines separating the subpopulations are drawn for each level of labs, or a list of such vectors if labels vary per panel. |
labs_lwd |
A vector of line widths for the lines that divide subpopulations (if |
labs_col |
A vector of colors for the lines that divide subpopulations (if |
labs_ticks |
A vector of logicals that specify whether ticks separating the subpopulations are drawn for each level of labs, or a list of such vectors if labels vary per panel. |
labs_text |
A vector of logicals that specify whether the subpopulation labels are shown for each level of labs, or a list of such vectors if labels vary per panel. Useful for including separating lines or ticks without text. |
labs_even |
A vector of logicals that specify whether the subpopulations labels are drawn with equal spacing for each level of labs, or a list of such vectors if labels vary per panel.
When |
null_panel_data |
If |
weights |
A vector with weights for every individual, or a list of such vectors if they vary per panel. The width of every individual in the kinship matrix becomes proportional to their weight. Individuals with zero or negative weights are omitted. Has no effect on non-kinship panels. |
raster |
A logical equivalent to |
sym |
If AXIS LABEL OPTIONS |
... |
Additional options passed to |
plot_popkin
plots the input kinship matrices as-is.
For best results, a standard kinship matrix (such as the output of popkin()
) should have its diagonal rescaled to contain inbreeding coefficients using inbr_diag()
before plot_popkin
is used.
This function permits the labeling of individuals (from row and column names when names = TRUE
) and of subpopulations (passed through labs
).
The difference is that the labels passed through labs
are assumed to be shared by many individuals, and lines (or other optional visual aids) are added to demarcate these subgroups.
# Construct toy data X <- matrix(c(0,1,2,1,0,1,1,0,2), nrow = 3, byrow = TRUE) # genotype matrix subpops <- c(1,1,2) # subpopulation assignments for individuals # NOTE: for BED-formatted input, use BEDMatrix! # "file" is path to BED file (excluding .bed extension) ## library(BEDMatrix) ## X <- BEDMatrix(file) # load genotype matrix object # estimate the kinship matrix from the genotypes "X"! kinship <- popkin(X, subpops) # calculate kinship from X and optional subpop labels # simple plot of the kinship matrix, marking the subpopulations only # note inbr_diag replaces the diagonal of kinship with inbreeding coefficients # (see vignette for more elaborate examples) plot_popkin( inbr_diag(kinship), labs = subpops )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.