View source: R/diversity_plot.R
diversity_plot | R Documentation |
Creates an Alpha diversity plot. This function is built into the class omics with method alpha_diversity()
.
It computes the pairwise wilcox test, paired or non-paired, given a data frame and adds useful labelling.
diversity_plot(
data,
values,
col_name,
palette,
method,
paired = FALSE,
p.adjust.method = "fdr"
)
data |
A data.frame or data.table computed from diversity. |
values |
A column name of a continuous variable. |
col_name |
A column name of a categorical variable. |
palette |
An object with names and hexcode or color names, see colormap. |
method |
A character variable indicating what method is used to compute the diversity. |
paired |
A boolean value to perform paired analysis in wilcox.test. |
p.adjust.method |
A character variable to specify the p.adjust.method to be used (Default: fdr). |
A ggplot2 object to be further modified
library("ggplot2")
n_row <- 1000
n_col <- 100
density <- 0.2
num_entries <- n_row * n_col
num_nonzero <- round(num_entries * density)
set.seed(123)
positions <- sample(num_entries, num_nonzero, replace=FALSE)
row_idx <- ((positions - 1) %% n_row) + 1
col_idx <- ((positions - 1) %/% n_row) + 1
values <- runif(num_nonzero, min = 0, max = 1)
sparse_mat <- Matrix::sparseMatrix(
i = row_idx,
j = col_idx,
x = values,
dims = c(n_row, n_col)
)
div <- OmicFlow::diversity(
x = sparse_mat,
metric = "shannon"
)
dt <- data.table::data.table(
"values" = div,
"treatment" = c(rep("healthy", n_col / 2), rep("tumor", n_col / 2))
)
colors <- OmicFlow::colormap(dt, "treatment")
diversity_plot(
data = dt,
values = "values",
col_name = "treatment",
palette = colors,
method = "shannon",
paired = FALSE,
p.adjust.method = "fdr"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.