|
63 | 63 | subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02,
|
64 | 64 | shareX = FALSE, shareY = FALSE, titleX = shareX,
|
65 | 65 | titleY = shareY, which_layout = "merge") {
|
66 |
| - |
| 66 | + |
67 | 67 |
|
68 | 68 | plots <- dots2plots(...)
|
69 | 69 |
|
@@ -215,16 +215,25 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02
|
215 | 215 | axisMap <- setNames(sub("axis", "", axisMap), sub("axis", "", names(axisMap)))
|
216 | 216 | newAnchors <- names(axisMap)[match(oldAnchors, axisMap)]
|
217 | 217 | traces[[i]] <- Map(function(tr, a) { tr[[key]] <- a; tr }, traces[[i]], newAnchors)
|
218 |
| - # also map annotation[i].xref/annotation[i].yref |
| 218 | + # also map annotation and image xaxis/yaxis references |
| 219 | + # TODO: do this for shapes as well? |
219 | 220 | ref <- list(xaxis = "xref", yaxis = "yref")[[key]]
|
220 | 221 | if (is.null(ref)) next
|
221 |
| - if (is.null(annotations[[i]])) next |
222 |
| - annotations[[i]] <- Map(function(ann, a) { |
223 |
| - if (!identical(ann[[ref]], "paper")) ann[[ref]] <- a |
224 |
| - ann |
225 |
| - }, annotations[[i]], newAnchors) |
| 222 | + if (length(annotations[[i]])) { |
| 223 | + annotations[[i]] <- Map(function(x, y) { |
| 224 | + if (!identical(x[[ref]], "paper")) x[[ref]] <- y |
| 225 | + x |
| 226 | + }, annotations[[i]], newAnchors) |
| 227 | + } |
| 228 | + if (length(images[[i]])) { |
| 229 | + images[[i]] <- Map(function(x, y) { |
| 230 | + if (!identical(x[[ref]], "paper")) x[[ref]] <- y |
| 231 | + x |
| 232 | + }, images[[i]], newAnchors) |
| 233 | + } |
226 | 234 | }
|
227 | 235 |
|
| 236 | + |
228 | 237 | # rescale domains according to the tabular layout
|
229 | 238 | xDom <- as.numeric(domainInfo[i, c("xstart", "xend")])
|
230 | 239 | yDom <- as.numeric(domainInfo[i, c("yend", "ystart")])
|
|
0 commit comments