Skip to content

Commit edf5ce0

Browse files
committed
omit legend for RGB images
1 parent ccc2786 commit edf5ce0

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

R/plotImage.R

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ plotSpatialData <- \() ggplot() + scale_y_reverse() + .theme
132132
.is_rgb <- \(x) {
133133
if (is(x, "ImageArray") &&
134134
!is.null(md <- meta(x)))
135-
x <- md$omero$channels$label
135+
x <- channels(x)
136136
if (!is.vector(x)) stop("invalid 'x'")
137137
is_len <- length(x) == 3
138138
is_012 <- setequal(x, seq(0, 2))
@@ -202,12 +202,15 @@ plotSpatialData <- \() ggplot() + scale_y_reverse() + .theme
202202
#' scale_x_continuous
203203
#' scale_x_continuous
204204
#' annotation_raster
205-
.gg_i <- \(x, w, h, nms, c) list(
206-
scale_color_identity(NULL, guide="legend", labels=nms),
207-
geom_point(aes(col=c), data.frame(c), x=0, y=0, alpha=0),
208-
guides(col=guide_legend(override.aes=list(alpha=1, size=2))),
209-
scale_x_continuous(limits=w), scale_y_reverse(limits=rev(h)),
210-
annotation_raster(x, w[2],w[1], -h[1],-h[2], interpolate=FALSE))
205+
.gg_i <- \(x, w, h, pal=NULL) {
206+
lgd <- if (!is.null(pal)) list(
207+
guides(col=guide_legend(override.aes=list(alpha=1, size=2))),
208+
scale_color_identity(NULL, guide="legend", labels=names(pal)),
209+
geom_point(aes(col=foo), data.frame(foo=pal), x=0, y=0, alpha=0))
210+
list(lgd,
211+
scale_x_continuous(limits=w), scale_y_reverse(limits=rev(h)),
212+
annotation_raster(x, w[2],w[1], -h[1],-h[2], interpolate=FALSE))
213+
}
211214

212215
#' @rdname plotImage
213216
#' @export
@@ -219,7 +222,10 @@ setMethod("plotImage", "SpatialData", \(x, i=1, j=1, k=NULL, ch=NULL, c=NULL, cl
219222
j <- CTname(y)[j]
220223
df <- .df_i(y, k, ch, c, cl)
221224
wh <- .get_wh(x, i, j)
222-
nms <- channels(y)[idx <- .ch_idx(y, ch)]
223-
pal <- if (is.null(c)) .DEFAULT_COLORS else c
224-
.gg_i(df, wh$w, wh$h, nms, pal[seq_along(idx)])
225+
pal <- if (!.is_rgb(y)) {
226+
pal <- if (is.null(c)) .DEFAULT_COLORS else c
227+
nms <- channels(y)[idx <- .ch_idx(y, ch)]
228+
setNames(pal[seq_along(idx)], nms)
229+
}
230+
.gg_i(df, wh$w, wh$h, pal)
225231
})

0 commit comments

Comments
 (0)