Skip to content

Commit 8cf609e

Browse files
committed
add k argument for plotLabel, selecting custom scales from multiscales
1 parent 5ff59e1 commit 8cf609e

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

R/plotLabel.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#'
44
#' @param x \code{SpatialData} object.
55
#' @param i character string or index; the label element to plot.
6+
#' @param k index of the scale of an image; by default (NULL), will auto-select
7+
#' scale in order to minimize memory-usage and blurring for a target size of
8+
#' 800 x 800px; use Inf to plot the lowest resolution available.
69
#' @param c the default, NULL, gives a binary image of whether or not
710
#' a given pixel is non-zero; alternatively, a character string specifying
811
#' a \code{colData} column or row name in a \code{table} annotating \code{i}.
@@ -47,11 +50,11 @@ NULL
4750
#' scale_fill_manual scale_fill_gradientn
4851
#' aes geom_raster theme unit guides guide_legend
4952
#' @export
50-
setMethod("plotLabel", "SpatialData", \(x, i=1, c=NULL,
53+
setMethod("plotLabel", "SpatialData", \(x, i=1, k=NULL, c=NULL,
5154
a=0.5, pal=c("red", "green"), nan=NA, assay=1) {
5255
if (is.numeric(i)) i <- labelNames(x)[i]
5356
i <- match.arg(i, labelNames(x))
54-
y <- as.matrix(.get_multiscale_data(label(x, i)))
57+
y <- as.matrix(.get_multiscale_data(label(x, i), k))
5558
df <- data.frame(x=c(col(y)), y=c(row(y)), z=c(y))
5659
aes <- aes(.data[["x"]], .data[["y"]])
5760
if (!is.null(c)) {

man/plotLabel.Rd

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/Rplots.pdf

-3.96 KB
Binary file not shown.

tests/testthat/test-plotArray.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,5 @@ test_that("plotLabel()", {
6666
expect_identical(q$layers[[1]]$aes_params$alpha, a)
6767
expect_error(show(plotSpatialData() + plotLabel(x, i, a=".....")))
6868
expect_error(show(plotSpatialData() + plotLabel(x, i, a=c(1, 2))))
69-
# TODO: use 'annotation_raster'
70-
# TODO: multiscale plotting
69+
# TODO: should we use 'annotation_raster' ?
7170
})

vignettes/SpatialData.plot.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ pal_d <- hcl.colors(10, "Spectral")
9393
pal_c <- hcl.colors(9, "Inferno")[-9]
9494
9595
a <- p + plotLabel(x, i) # simple binary image
96-
b <- p + plotLabel(x, i, "id", pal=pal_d) # 'colData'
97-
c <- p + plotLabel(x, i, "channel_1_sum", pal=pal_c) +
96+
b <- p + plotLabel(x, i, c = "id", pal=pal_d) # 'colData'
97+
c <- p + plotLabel(x, i, c = "channel_1_sum", pal=pal_c) +
9898
theme(legend.key.width=unit(1, "lines")) # 'assay'
9999
100100
(a | b | c) +
@@ -236,7 +236,7 @@ pa <- unzip_spd_demo(
236236
pal <- hcl.colors(8, "Spectral")
237237
wrap_plots(nrow=1, lapply(seq(3), \(.)
238238
plotSpatialData() + plotImage(x, .) +
239-
plotLabel(x, ., "Cluster", pal=pal))) +
239+
plotLabel(x, ., c = "Cluster", pal=pal))) +
240240
plot_layout(guides="collect")
241241
```
242242

@@ -337,7 +337,7 @@ x <- mask(x, "blobs_image", i, fun=mean)
337337
(t <- getTable(x, i))
338338
# visualize side-by-side
339339
ps <- lapply(paste(seq_len(3)), \(.)
340-
plotSpatialData() + plotLabel(x, i, .) +
340+
plotSpatialData() + plotLabel(x, i, c = .) +
341341
ggtitle(paste("channel", ., "sum")))
342342
wrap_plots(ps, nrow=1) & theme(
343343
legend.position="bottom",

0 commit comments

Comments
 (0)