@@ -120,6 +120,7 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02
120
120
traces <- lapply(plots , " [[" , " data" )
121
121
layouts <- lapply(plots , " [[" , " layout" )
122
122
shapes <- lapply(layouts , " [[" , " shapes" )
123
+ images <- lapply(layouts , " [[" , " images" )
123
124
annotations <- lapply(layouts , function (x ) {
124
125
# keep non axis title annotations (for rescaling)
125
126
axes <- vapply(x $ annotations , function (a ) identical(a $ annotationType , " axis" ), logical (1 ))
@@ -263,11 +264,13 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02
263
264
# reposition shapes and annotations
264
265
annotations <- Map(reposition , annotations , split(domainInfo , seq_along(plots )))
265
266
shapes <- Map(reposition , shapes , split(domainInfo , seq_along(plots )))
267
+ images <- Map(reposition , images , split(domainInfo , seq_along(plots )))
266
268
p $ layout $ annotations <- Reduce(c , annotations )
267
269
p $ layout $ shapes <- Reduce(c , shapes )
270
+ p $ layout $ images <- Reduce(c , images )
268
271
# merge non-axis layout stuff
269
272
layouts <- lapply(layouts , function (x ) {
270
- x [! grepl(" ^[x-y]axis|^geo|^mapbox|annotations|shapes" , names(x ))] %|| % list ()
273
+ x [! grepl(" ^[x-y]axis|^geo|^mapbox|annotations|shapes|images " , names(x ))] %|| % list ()
271
274
})
272
275
if (which_layout != " merge" ) {
273
276
if (! is.numeric(which_layout )) warning(" which_layout must be numeric" )
@@ -396,24 +399,27 @@ list2df <- function(x, nms) {
396
399
# (useful mostly for repositioning annotations/shapes in subplots)
397
400
reposition <- function (obj , domains ) {
398
401
# we need x and y in order to rescale them!
402
+ xdom <- as.numeric(domains [c(" xstart" , " xend" )])
403
+ ydom <- as.numeric(domains [c(" yend" , " ystart" )])
404
+
399
405
for (i in seq_along(obj )) {
400
406
o <- obj [[i ]]
401
- # TODO: this implementation currently assumes xref/yref == "paper"
402
- # should we support references to axis objects as well?
403
- xs <- if (identical(o $ xref , " paper" )) c(" x" , " x0" , " x1" )
407
+ xs <- if (identical(o $ xref , " paper" )) {
408
+ if (is.numeric(o $ sizex )) obj [[i ]]$ sizex <- o $ sizex * abs(diff(xdom ))
409
+ c(" x" , " x0" , " x1" )
410
+ }
404
411
for (j in xs ) {
405
412
if (is.numeric(o [[j ]])) {
406
- obj [[i ]][[j ]] <- scales :: rescale(
407
- o [[j ]], as.numeric(domains [c(" xstart" , " xend" )]), from = c(0 , 1 )
408
- )
413
+ obj [[i ]][[j ]] <- scales :: rescale(o [[j ]], xdom , from = c(0 , 1 ))
409
414
}
410
415
}
411
- ys <- if (identical(o $ xref , " paper" )) c(" y" , " y0" , " y1" )
416
+ ys <- if (identical(o $ yref , " paper" )) {
417
+ if (is.numeric(o $ sizey )) obj [[i ]]$ sizey <- o $ sizey * abs(diff(ydom ))
418
+ c(" y" , " y0" , " y1" )
419
+ }
412
420
for (j in ys ) {
413
421
if (is.numeric(o [[j ]])) {
414
- obj [[i ]][[j ]] <- scales :: rescale(
415
- o [[j ]], as.numeric(domains [c(" yend" , " ystart" )]), from = c(0 , 1 )
416
- )
422
+ obj [[i ]][[j ]] <- scales :: rescale(o [[j ]], ydom , from = c(0 , 1 ))
417
423
}
418
424
}
419
425
}
0 commit comments