|
1 | 1 | #' View multiple plots in a single view
|
2 | 2 | #'
|
3 |
| -#' @param ... any number of plotly objects. A list of plotly objects or a tibble |
4 |
| -#' with one list-column of plotly objects is also accepted. |
| 3 | +#' @param ... One of the following |
| 4 | +#' \itemize{ |
| 5 | +#' \item any number of plotly/ggplot2 objects. |
| 6 | +#' \item a list of plotly/ggplot2 objects. |
| 7 | +#' \item a tibble with one list-column of plotly/ggplot2 objects. |
| 8 | +#' } |
5 | 9 | #' @param nrows number of rows for laying out plots in a grid-like structure.
|
6 | 10 | #' Only used if no domain is already specified.
|
7 | 11 | #' @param widths relative width of each column on a 0-1 scale. By default all
|
|
24 | 28 | #' @return A plotly object
|
25 | 29 | #' @export
|
26 | 30 | #' @author Carson Sievert
|
27 |
| -#' @examples \dontrun{ |
28 |
| -#' p1 <- plot_ly(economics, x = date, y = uempmed, showlegend = F) |
29 |
| -#' p2 <- plot_ly(economics, x = date, y = unemploy, showlegend = F) |
30 |
| -#' subplot(p1, p2, p1, p2, nrows = 2) |
31 |
| -#' } |
| 31 | +#' @examples |
| 32 | +#' |
| 33 | +#' # pass any number of plotly objects to subplot() |
| 34 | +#' p1 <- plot_ly(economics, x = ~date, y = ~uempmed) |
| 35 | +#' p2 <- plot_ly(economics, x = ~date, y = ~unemploy) |
| 36 | +#' subplot(p1, p2, p1, p2, nrows = 2, margin = 0.05) |
| 37 | +#' |
| 38 | +#' # or pass a list |
| 39 | +#' library(purrr) |
| 40 | +#' economics_long %>% |
| 41 | +#' split(.$variable) %>% |
| 42 | +#' map(~ plot_ly(., x = ~date, y = ~value)) %>% |
| 43 | +#' subplot(nrows = NROW(.), shareX = T) |
| 44 | +#' |
| 45 | +#' # or pass a tibble with a list-column of plotly objects |
| 46 | +#' economics_long %>% |
| 47 | +#' group_by(variable) %>% |
| 48 | +#' do(p = plot_ly(., x = ~date, y = ~value)) %>% |
| 49 | +#' subplot(nrows = NROW(.), shareX = T) |
| 50 | +#' |
| 51 | +#' # learn more at https://cpsievert.github.io/plotly_book/subplot.html |
| 52 | +#' |
32 | 53 |
|
33 | 54 | subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02,
|
34 | 55 | shareX = FALSE, shareY = FALSE, titleX = shareX,
|
|
0 commit comments