View source: R/fstruct_functions.R
Q_plot | R Documentation |
This function enables graphical visualization of a Q matrix, the default output of population structure inference software programs such as STRUCTURE and ADMIXTURE. In the output plot, each vertical bar represents a single individual's ancestry; the height of each color in the bar corresponds to the individual membership coefficients given by the Q matrix. Because this function produces a ggplot object, its output can be modified using standard ggplot2 syntax. For a more comprehensive population structure visualization program, see the program distruct.
Q_plot(Q, K = ncol(Q), arrange)
Q |
A dataframe, matrix, or array representing a Q matrix. Each row
represents an individual, and the last |
K |
The number of ancestral clusters in the Q matrix. Each individual
must have |
arrange |
Optional variable controlling horizontal ordering of individuals.
If |
A ggplot object describing a bar plot of membership coefficients from the Q matrix.
Q_plot(
# Make an example matrix of membership coefficients.
# Each row is an individual. Rows sum to 1.
Q = matrix(c(
.4, .2, .4,
.5, .3, .2,
.5, .4, .1,
.6, .1, .3,
.6, .3, .1
),
nrow = 5,
byrow = TRUE
),
K = 3, # How many ancestry coefficients per individual?
arrange = TRUE
) +
# Below are example, optional modifications to the default plot
ggplot2::ggtitle("Population A") +
ggplot2::scale_fill_brewer("Blues") +
ggplot2::scale_color_brewer("Blues") +
ggplot2::xlab("Individuals")
# Note that both scale_fill and scale_color are needed to change the color of the bars.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.