forked from plotly/plotly.R
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyle.R
More file actions
32 lines (31 loc) · 920 Bytes
/
style.R
File metadata and controls
32 lines (31 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#' Modify trace(s)
#'
#' Modify trace(s) of an existing plotly visualization. Useful when used in
#' conjunction with \code{\link{get_figure}()}.
#'
#' @param p A plotly visualization.
#' @param ... Visual properties.
#' @param traces numeric vector. Which traces should be modified?
#' @seealso \code{\link{get_figure}()}
#' @author Carson Sievert
#' @export
#' @examples
#'
#' p <- qplot(data = mtcars, wt, mpg, geom = c("point", "smooth"))
#' # keep the hover info for points, but remove it for the line/ribbon
#' style(p, hoverinfo = "none", traces = c(2, 3))
#'
style <- function(p, ..., traces = 1) {
p <- plotly_build(p)
nTraces <- length(p$x$data)
idx <- traces > nTraces
traces <- traces[!idx]
if (any(idx)) warning("You've referenced non-existent traces", call. = FALSE)
argz <- list(...)
for (i in traces) {
for (j in names(argz)) {
p$x$data[[i]][[j]] <- argz[[j]]
}
}
p
}