Horizontal raincloud of Monte Carlo proportion estimates
Source:R/04_02_benchmark_visualisation.R
plot_mc_raincloud.RdHalf-eye densities, dots, and empirical 50% / 95% intervals
(Allen et al. 2019)
for the
Monte Carlo sampling distribution of \(\hat p_j\). Default
aesthetics: numeric axis is the estimation error
\(\hat p_j-p_j^{\star}\) (so a vertical line at 0 is bias);
the y-axis is the cell type; colour and dodge group the deconvolution
algorithm. Optional facet_rows / facet_cols split scenarios
(for example number of genes versus pairwise cosine).
Arguments
- benchmark
List from
run_simulation_benchmark(), or a table frompivot_mc_estimates().- quantity
"error"(default) or"estimate".- facet_rows, facet_cols
Optional column names for
ggplot2::facet_grid()rows and columns.- .width
Passed to
ggdist::stat_halfeye(); defaultc(0.5, 0.95).- include_dots
If
FALSE, omitggdist::stat_dots()(use this on large Monte Carlo tables: the Fortran QP innudge_binscannot take long vectors).- max_dots
Maximum rows passed to
stat_dotswheninclude_dots = TRUE. Extra rows are subsampled.- max_rows
Optional cap on the plotting table (half-eye and dots). When the Monte Carlo stack is huge, subsample before drawing.
- dodge_width
Width passed to
ggplot2::position_dodge().- slab_scale
Slab height for
ggdist::stat_halfeye().- slab_alpha
Transparency of the density slab (
1is opaque).- category_spacing
Vertical gap between discrete y categories (cell types). Values greater than 1 insert extra space so slabs from neighbouring types do not overlap; the axis still shows the original labels.
- slab
"halfeye"(default KDE raincloud) or"dotsinterval"(quantile dots plus interval; avoids empty bounded slabs).
Details
When quantity = "estimate" and slab = "halfeye", slabs use a
bounded kernel on \([0,1]\) (ggdist::density_bounded()) with a
coloured outline (slab_colour / slab_linewidth). Vertex pile-up
can leave that KDE empty; slab = "dotsinterval"
(ggdist::stat_dotsinterval()) draws quantile dots instead.
True proportions are labelled at the top of each panel (the most
abundant type to the right of its reference line; the others to the
left).
The inner interval is the central 50% of Monte Carlo replicates; the outer interval is the central 95%. These are not confidence intervals for \(p_j\).
References
Allen M, Poggiali D, Whitaker K, Marshall TR, van Langen J, Kievit RA (2019). “Raincloud Plots: A Multi-Platform Tool for Robust Data Visualization.” Wellcome Open Research, 4, 63. ISSN 2398-502X. doi:10.12688/wellcomeopenres.15191.2 . https://wellcomeopenresearch.org/articles/4-63.
Examples
set.seed(1)
genes <- paste0("g", 1:2)
cts <- paste0("ct", 1:2)
mu <- matrix(c(20, 22, 22, 20), nrow = 2, dimnames = list(genes, cts))
Sigma <- array(
c(1, 0, 0, 1, 1, 0, 0, 1),
dim = c(2, 2, 2),
dimnames = list(genes, genes, cts)
)
out <- run_simulation_benchmark(
tibble::tibble(
n_genes = 2L,
cosine = 0,
true_theta = list(list(p = c(0.5, 0.5), mu = mu, sigma = Sigma))
),
deconvolution_functions = list(
"nnls" = list(FUN = deconvolute_ratios_nnls)
),
n = 4,
cores = 1
)
if (requireNamespace("ggdist", quietly = TRUE)) {
plot_mc_raincloud(out, facet_cols = "cosine")
}