View source: R/plot_composition_bar.R
plot_composition_bar | R Documentation |
Given a long formatted data.frame
, this function creates a barplot for
the average cell type composition among a set of samples (donors) using
ggplot2
.
plot_composition_bar(
prop_long,
sample_col = "RNum",
x_col = "ALL",
prop_col = "prop",
ct_col = "cell_type",
add_text = TRUE,
min_prop_text = 0
)
prop_long |
A |
sample_col |
A |
x_col |
A |
prop_col |
A |
ct_col |
A |
add_text |
A |
min_prop_text |
A |
A stacked barplot ggplot2
object representing the mean proportion
of cell types for each group.
# Load example data
data("rse_bulk_test")
data("est_prop")
# extract relevant colData from the example RangedSummarizedExperiment object
pd <- SummarizedExperiment::colData(rse_bulk_test) |>
as.data.frame()
# combine with the example estimated proportions in a long style table
est_prop_long <- est_prop |>
tibble::rownames_to_column("RNum") |>
tidyr::pivot_longer(!RNum, names_to = "cell_type", values_to = "prop") |>
dplyr::inner_join(pd |> dplyr::select(RNum, Dx))
est_prop_long
# Create composition bar plots
# Mean composition of all samples
plot_composition_bar(est_prop_long)
# Mean composition by Dx
plot_composition_bar(est_prop_long, x_col = "Dx")
# control minimum value of text to add
plot_composition_bar(est_prop_long, x_col = "Dx", min_prop_text = 0.1)
# plot all samples, then facet by Dx
plot_composition_bar(est_prop_long, x_col = "RNum", add_text = FALSE) +
ggplot2::facet_wrap(~Dx, scales = "free_x")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.