14
14
# ' is used as the right margin, the third is used as the top margin, and the
15
15
# ' fourth is used as the bottom margin.
16
16
# ' If a single value is provided, it will be used as all four margins.
17
+ # ' @param keep_titles should axis titles be retained?
17
18
# ' @param which_layout adopt the layout of which plot? If the default value of
18
- # ' "merge" is used, all plot level layout options will be included in the final
19
- # ' layout. This argument also accepts a numeric vector specifying
19
+ # ' "merge" is used, layout options found later in the sequence of plots will
20
+ # ' override options found earlier in the sequence. This argument also accepts a
21
+ # ' numeric vector specifying which plots to consider when merging.
20
22
# ' @return A plotly object
21
23
# ' @export
22
24
# ' @author Carson Sievert
27
29
# ' }
28
30
29
31
subplot <- function (... , nrows = 1 , widths = NULL , heights = NULL , shareX = FALSE ,
30
- shareY = FALSE , margin = 0.02 , which_layout = " merge" ) {
32
+ shareY = FALSE , margin = 0.02 , which_layout = " merge" ,
33
+ keep_titles = FALSE ) {
31
34
# build each plot and collect relevant info
32
35
plots <- lapply(list (... ), plotly_build )
33
36
traces <- lapply(plots , " [[" , " data" )
@@ -46,8 +49,10 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, shareX = FALS
46
49
x [grepl(" ^yaxis" , names(x ))] %|| % list (yaxis = list (domain = c(0 , 1 ), anchor = " x" ))
47
50
})
48
51
# remove their titles
49
- xAxes <- lapply(xAxes , function (x ) lapply(x , function (y ) { y $ title <- NULL ; y }))
50
- yAxes <- lapply(yAxes , function (x ) lapply(x , function (y ) { y $ title <- NULL ; y }))
52
+ if (! keep_titles ) {
53
+ xAxes <- lapply(xAxes , function (x ) lapply(x , function (y ) { y $ title <- NULL ; y }))
54
+ yAxes <- lapply(yAxes , function (x ) lapply(x , function (y ) { y $ title <- NULL ; y }))
55
+ }
51
56
# number of x/y axes per plot
52
57
xAxisN <- vapply(xAxes , length , numeric (1 ))
53
58
yAxisN <- vapply(yAxes , length , numeric (1 ))
@@ -75,7 +80,6 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, shareX = FALS
75
80
xAxisMap <- split(xAxisMap , rep(seq_along(plots ), xAxisN ))
76
81
yAxisMap <- split(yAxisMap , rep(seq_along(plots ), yAxisN ))
77
82
# domains of each subplot
78
- # TODO: allow control of column width and row height!
79
83
domainInfo <- get_domains(
80
84
length(plots ), nrows , margin , widths = widths , heights = heights
81
85
)
@@ -137,7 +141,6 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, shareX = FALS
137
141
layouts <- layouts [which_layout ]
138
142
}
139
143
p $ layout <- c(p $ layout , Reduce(modifyList , layouts ))
140
-
141
144
hash_plot(data.frame (), p )
142
145
}
143
146
0 commit comments