Skip to content

Commit 2657719

Browse files
committed
Add density plot highlight keys
1 parent 99a5d7d commit 2657719

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# prolfqua 1.6.3
22

3+
- Abundance-density plots now carry per-sample Plotly highlight keys, allowing interactive reports to fade non-hovered
4+
sample curves while preserving the existing ggplot output.
35
- **Breaking — contrast schema.** The `modelName` column of `get_contrasts()` output is now the selected facade key (`lm`, `rlm`, `rfit`, `lm_impute`, `lm_missing`, `limma`, `limma_impute`, `limma_voom`, `limma_voom_impute`, `limpa`, `deqms`, `deqms_voom`, `firth`, `lmer_nested`, `ropeca_nested`, `firth_nested`, `limpa_nested`) instead of the testing-schema label (`WaldTest_moderated`, `*_DEqMS`, `*_imputed`, …). Rescue/imputation state moved to a new `estimate_type` column with values `observed`, `lod_imputed`, or `missing_fallback`. The redundant `facade` column was removed (its role is now played by `modelName`). The moderated-Wald-test wording belongs in methods text, not per-row labels. Downstream code that filtered on `modelName == "WaldTest_moderated"` (or the `_imputed`/`_DEqMS` variants) or read the `facade` column must migrate to the facade key and `estimate_type`.
46
- `build_contrast_analysis()` and the exported `FACADE_REGISTRY` now derive method dispatch and the available-method list from a single seeded registry (`list_facades()`), removing three hand-maintained copies that could drift. New exported base class `ContrastsFacadeBase` holds the shared facade plumbing; the 18 built-in facades are now thin subclasses.
57
- `ContrastsPlotter` colours volcano/MA/score plots by `estimate_type` when present (and the colour column was left at its default), keeping LOD-imputed / fallback rows visually distinct now that `modelName` is uniform per run.

R/tidyMS_plotting.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,19 @@ plot_intensity_distribution_density <- function(
226226
legend = NA,
227227
max_legend_samples = 16
228228
) {
229-
p <- ggplot(pdata, aes(x = .data[[response]], colour = .data[[sample_name]])) +
229+
density_data <- plotly::highlight_key(
230+
pdata,
231+
key = as.character(pdata[[sample_name]]),
232+
group = paste("prolfqua_density", sample_name, sep = "_")
233+
)
234+
p <- ggplot(
235+
density_data,
236+
aes(
237+
x = .data[[response]],
238+
colour = .data[[sample_name]],
239+
group = .data[[sample_name]]
240+
)
241+
) +
230242
geom_line(stat = "density")
231243
if (!is_transformed) {
232244
p <- p + scale_x_continuous(trans = "log10")

tests/testthat/test-plotting_functions.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ test_that("density legend is suppressed automatically for many samples", {
4747
expect_equal(length(p$guides$guides), 1)
4848
})
4949

50+
test_that("density plot carries sample keys for plotly hover highlighting", {
51+
testthat::skip_if_not_installed("plotly")
52+
53+
pdata <- expand.grid(
54+
sample = c("S1", "S2"),
55+
feature = seq_len(30),
56+
KEEP.OUT.ATTRS = FALSE
57+
)
58+
pdata$abundance <- c(stats::rnorm(30, mean = 10), stats::rnorm(30, mean = 12))
59+
60+
p <- plot_intensity_distribution_density(
61+
pdata,
62+
sample_name = "sample",
63+
response = "abundance",
64+
is_transformed = TRUE
65+
)
66+
built <- plotly::plotly_build(plotly::ggplotly(p))
67+
trace_keys <- vapply(built$x$data, function(trace) trace$key[[1]], character(1))
68+
69+
expect_setequal(trace_keys, c("S1", "S2"))
70+
})
71+
5072
test_that("PCA sample labels repel and are not clipped", {
5173
matrix <- matrix(stats::rnorm(60), nrow = 10)
5274
colnames(matrix) <- paste0("sample_", seq_len(6))

0 commit comments

Comments
 (0)