Skip to content

Commit 370d9d4

Browse files
committed
add the filename, fileopt, and world_readable arguments to plot_ly() and ggplotly()
1 parent d6f549a commit 370d9d4

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

R/ggplotly.R

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
#' \url{https://plot.ly/ggplot2}
55
#'
66
#' @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.
716
#' @seealso \link{signup}, \link{plot_ly}
817
#' @import httr jsonlite
918
#' @export
@@ -23,8 +32,13 @@
2332
#' ggplotly(viz)
2433
#' }
2534
#'
26-
ggplotly <- function(p = ggplot2::last_plot()) {
35+
ggplotly <- function(p = ggplot2::last_plot(), filename, fileopt,
36+
world_readable = TRUE) {
2737
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
2842
hash_plot(p$data, l)
2943
}
3044

@@ -354,7 +368,7 @@ gg2list <- function(p) {
354368
# x axis scale instead of on the grid 0-1 scale). This allows
355369
# transformations to be used out of the box, with no additional d3
356370
# coding.
357-
theme.pars <- ggplot2:::plot_theme(p)
371+
theme.pars <- getFromNamespace("plot_theme", "ggplot2")(p)
358372

359373
# Flip labels if coords are flipped - transform does not take care
360374
# of this. Do this BEFORE checking if it is blank or not, so that

R/plotly.R

+18-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,21 @@
1414
#' @param color Either a variable name or a vector to use for color mapping.
1515
#' @param colors Either a colorbrewer2.org palette name (e.g. "YlOrRd" or "Blues"),
1616
#' or a vector of colors to interpolate in hexadecimal "#RRGGBB" format,
17-
#' or a color interpolation function like \link{grDevices::colorRamp}.
17+
#' or a color interpolation function like \code{colorRamp()}.
1818
#' @param symbol Either a variable name or a (discrete) vector to use for symbol encoding.
1919
#' @param symbols A character vector of symbol types. Possible values:
2020
#' 'dot', 'cross', 'diamond', 'square', 'triangle-down', 'triangle-left', 'triangle-right', 'triangle-up'
2121
#' @param size A variable name or numeric vector to encode the size of markers.
22-
#' @param inherit should future traces inherit properties from this initial trace?
22+
#' @param filename character string describing the name of the plot in your plotly account.
23+
#' Use / to specify directories. If a directory path does not exist it will be created.
24+
#' If this argument is not specified and the title of the plot exists,
25+
#' that will be used for the filename.
26+
#' @param fileopt character string describing whether to create a "new" plotly, "overwrite" an existing plotly,
27+
#' "append" data to existing plotly, or "extend" it.
28+
#' @param world_readable logical. If \code{TRUE}, the graph is viewable
29+
#' by anyone who has the link and in the owner's plotly account.
30+
#' If \code{FALSE}, graph is only viewable in the owner's plotly account.
31+
#' @param inherit logical. Should future traces inherit properties from this initial trace?
2332
#' @param evaluate logical. Evaluate arguments when this function is called?
2433
#' @seealso \code{\link{layout}()}, \code{\link{add_trace}()}, \code{\link{style}()}
2534
#' @references \url{https://plot.ly/r/reference/}
@@ -45,6 +54,7 @@
4554
#'
4655
plot_ly <- function(data = data.frame(), ..., type = "scatter",
4756
group, color, colors, symbol, symbols, size,
57+
filename, fileopt, world_readable = TRUE,
4858
inherit = TRUE, evaluate = FALSE) {
4959
# "native" plotly arguments
5060
argz <- substitute(list(...))
@@ -69,6 +79,11 @@ plot_ly <- function(data = data.frame(), ..., type = "scatter",
6979
layout = NULL,
7080
url = NULL
7181
)
82+
# tack on special keyword arguments
83+
if (!missing(filename)) p$filename <- filename
84+
if (!missing(fileopt)) p$fileopt <- fileopt
85+
p$world_readable <- world_readable
86+
7287
if (evaluate) p <- plotly_build(p)
7388
hash_plot(data, p)
7489
}
@@ -83,7 +98,7 @@ plot_ly <- function(data = data.frame(), ..., type = "scatter",
8398
#' @param color Either a variable name or a vector to use for color mapping.
8499
#' @param colors Either a colorbrewer2.org palette name (e.g. "YlOrRd" or "Blues"),
85100
#' or a vector of colors to interpolate in hexadecimal "#RRGGBB" format,
86-
#' or a color interpolation function like \link{grDevices::colorRamp}.
101+
#' or a color interpolation function like \code{colorRamp}.
87102
#' @param symbol Either a variable name or a (discrete) vector to use for symbol encoding.
88103
#' @param symbols A character vector of symbol types. Possible values:
89104
#' 'dot', 'cross', 'diamond', 'square', 'triangle-down', 'triangle-left', 'triangle-right', 'triangle-up'

0 commit comments

Comments
 (0)