|
4 | 4 | #' \url{https://plot.ly/ggplot2} |
5 | 5 | #' |
6 | 6 | #' @param p a ggplot object. |
7 | | -#' @param filename character string describing the name of the plot in your plotly account. |
8 | | -#' Use / to specify directories. If a directory path does not exist it will be created. |
9 | | -#' If this argument is not specified and the title of the plot exists, |
10 | | -#' that will be used for the filename. |
11 | | -#' @param fileopt character string describing whether to create a "new" plotly, "overwrite" an existing plotly, |
12 | | -#' "append" data to existing plotly, or "extend" it. |
13 | | -#' @param world_readable logical. If \code{TRUE}, the graph is viewable |
14 | | -#' by anyone who has the link and in the owner's plotly account. |
15 | | -#' If \code{FALSE}, graph is only viewable in the owner's plotly account. |
| 7 | +#' @param width Width of the plot in pixels (optional, defaults to automatic sizing). |
| 8 | +#' @param height Height of the plot in pixels (optional, defaults to automatic sizing). |
| 9 | +#' @param source Only relevant for \link{event_data}. |
16 | 10 | #' @seealso \link{signup}, \link{plot_ly} |
17 | 11 | #' @import httr jsonlite |
18 | 12 | #' @export |
|
32 | 26 | #' ggplotly(viz) |
33 | 27 | #' } |
34 | 28 | #' |
35 | | -ggplotly <- function(p = ggplot2::last_plot(), filename, fileopt, |
36 | | - world_readable = TRUE) { |
37 | | - l <- gg2list(p) |
38 | | - # tack on special keyword arguments |
39 | | - if (!missing(filename)) l$filename <- filename |
40 | | - if (!missing(fileopt)) l$fileopt <- fileopt |
41 | | - l$world_readable <- world_readable |
| 29 | +ggplotly <- function(p = ggplot2::last_plot(), width = NULL, height = NULL, |
| 30 | + source = "A") { |
| 31 | + l <- gg2list(p, width = width, height = height, source = source) |
42 | 32 | hash_plot(p$data, l) |
43 | 33 | } |
44 | 34 |
|
@@ -116,9 +106,12 @@ guide_names <- function(p, aes = c("shape", "fill", "alpha", "area", |
116 | 106 | #' Convert a ggplot to a list. |
117 | 107 | #' @import ggplot2 |
118 | 108 | #' @param p ggplot2 plot. |
| 109 | +#' @param width Width of the plot in pixels (optional, defaults to automatic sizing). |
| 110 | +#' @param height Height of the plot in pixels (optional, defaults to automatic sizing). |
| 111 | +#' @param source Only relevant for \link{event_data}. |
119 | 112 | #' @return figure object (list with names "data" and "layout"). |
120 | 113 | #' @export |
121 | | -gg2list <- function(p) { |
| 114 | +gg2list <- function(p, width = NULL, height = NULL, source = "A") { |
122 | 115 | # ggplot now applies geom_blank() (instead of erroring) when no layers exist |
123 | 116 | if (length(p$layers) == 0) p <- p + geom_blank() |
124 | 117 | layout <- list() |
@@ -960,6 +953,8 @@ gg2list <- function(p) { |
960 | 953 | } |
961 | 954 |
|
962 | 955 | l <- list(data = flipped.traces, layout = flipped.layout) |
963 | | - |
| 956 | + l$width <- width |
| 957 | + l$height <- width |
| 958 | + l$source <- source |
964 | 959 | structure(add_boxed(rm_asis(l)), class = "plotly") |
965 | 960 | } |
0 commit comments