Skip to content

Commit cbdc93c

Browse files
committed
better subplot examples
1 parent 4f61d90 commit cbdc93c

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

R/subplots.R

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#' View multiple plots in a single view
22
#'
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+
#' }
59
#' @param nrows number of rows for laying out plots in a grid-like structure.
610
#' Only used if no domain is already specified.
711
#' @param widths relative width of each column on a 0-1 scale. By default all
@@ -24,11 +28,28 @@
2428
#' @return A plotly object
2529
#' @export
2630
#' @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+
#'
3253

3354
subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02,
3455
shareX = FALSE, shareY = FALSE, titleX = shareX,

man/subplot.Rd

Lines changed: 27 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)