|
7 | 7 | #' columns have an equal relative width.
|
8 | 8 | #' @param heights relative height of each row on a 0-1 scale. By default all
|
9 | 9 | #' rows have an equal relative height.
|
10 |
| -#' @param shareX should the x-axis be shared amongst the subplots? |
11 |
| -#' @param shareY should the y-axis be shared amongst the subplots? |
12 | 10 | #' @param margin either a single value or four values (all between 0 and 1).
|
13 | 11 | #' If four values are provided, the first is used as the left margin, the second
|
14 | 12 | #' is used as the right margin, the third is used as the top margin, and the
|
15 | 13 | #' fourth is used as the bottom margin.
|
16 | 14 | #' If a single value is provided, it will be used as all four margins.
|
17 |
| -#' @param keep_titles should axis titles be retained? |
| 15 | +#' @param shareX should the x-axis be shared amongst the subplots? |
| 16 | +#' @param shareY should the y-axis be shared amongst the subplots? |
| 17 | +#' @param titleX should x-axis titles be retained? |
| 18 | +#' @param titleY should y-axis titles be retained? |
18 | 19 | #' @param which_layout adopt the layout of which plot? If the default value of
|
19 | 20 | #' "merge" is used, layout options found later in the sequence of plots will
|
20 | 21 | #' override options found earlier in the sequence. This argument also accepts a
|
|
28 | 29 | #' subplot(p1, p2, p1, p2, nrows = 2)
|
29 | 30 | #' }
|
30 | 31 |
|
31 |
| -subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, shareX = FALSE, |
32 |
| - shareY = FALSE, margin = 0.02, which_layout = "merge", |
33 |
| - keep_titles = FALSE) { |
| 32 | +subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02, |
| 33 | + shareX = FALSE, shareY = FALSE, titleX = shareX, |
| 34 | + titleY = shareY, which_layout = "merge") { |
34 | 35 | # build each plot
|
35 | 36 | plotz <- lapply(list(...), plotly_build)
|
36 | 37 | # ensure "axis-reference" trace attributes are properly formatted
|
@@ -98,9 +99,10 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, shareX = FALS
|
98 | 99 | yAxes <- lapply(layouts, function(lay) {
|
99 | 100 | lay[grepl("^yaxis|^geo", names(lay))] %||% list(yaxis = list(domain = c(0, 1)))
|
100 | 101 | })
|
101 |
| - # remove their titles |
102 |
| - if (!keep_titles) { |
| 102 | + if (!titleX) { |
103 | 103 | xAxes <- lapply(xAxes, function(ax) lapply(ax, function(y) { y$title <- NULL; y }))
|
| 104 | + } |
| 105 | + if (!titleY) { |
104 | 106 | yAxes <- lapply(yAxes, function(ax) lapply(ax, function(y) { y$title <- NULL; y }))
|
105 | 107 | }
|
106 | 108 | # number of x/y axes per plot
|
|
0 commit comments