Skip to content

Commit 40a2b3e

Browse files
committed
add new split argument to replace old group argument
1 parent fae3861 commit 40a2b3e

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

R/add.R

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,14 @@ add_data <- function(p, data = NULL) {
5959
#' add_markers(color = ~pop) %>%
6060
#' layout(showlegend = FALSE)
6161
#'
62-
add_trace <- function(p, ..., color, symbol, size, linetype,
62+
add_trace <- function(p, ...,
6363
data = NULL, inherit = TRUE) {
6464

6565
# "native" plotly arguments
6666
attrs <- list(...)
6767

68-
# tack on "special" arguments
69-
attrs$color <- if (!missing(color)) color
70-
attrs$symbol <- if (!missing(symbol)) symbol
71-
attrs$linetype <- if (!missing(linetype)) linetype
72-
attrs$size <- if (!missing(size)) size
73-
7468
if (!is.null(attrs[["group"]])) {
75-
warning("The group argument has been deprecated. Use group_by() instead.")
69+
warning("The group argument has been deprecated. Use group_by() or split instead.")
7670
}
7771

7872
p <- add_data(p, data)

R/plotly.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#' Either valid \link{par} (lty) or plotly dash codes may be supplied.
3232
#' @param size A variable name or numeric vector to encode the size of markers.
3333
#' @param sizes A numeric vector of length 2 used to scale sizes to pixels.
34+
#' @param split A formula containing a name or expression. Similar to
35+
#' \code{\link{group_by}()}, but ensures at least one trace for each unique
36+
#' value. This replaces the functionality of the (now deprecated)
37+
#' \code{group} argument.
3438
#' @param width Width in pixels (optional, defaults to automatic sizing).
3539
#' @param height Height in pixels (optional, defaults to automatic sizing).
3640
#' @param source Only relevant for \link{event_data}.
@@ -84,7 +88,7 @@
8488
plot_ly <- function(data = data.frame(), ..., type = NULL,
8589
color, colors = NULL, alpha = 1, symbol, symbols = NULL,
8690
size, sizes = c(10, 100), linetype, linetypes = NULL,
87-
width = NULL, height = NULL, source = "A") {
91+
split, width = NULL, height = NULL, source = "A") {
8892
if (!is.data.frame(data)) {
8993
stop("First argument, `data`, must be a data frame.", call. = FALSE)
9094
}
@@ -99,7 +103,7 @@ plot_ly <- function(data = data.frame(), ..., type = NULL,
99103
}
100104
if (!is.null(attrs[["group"]])) {
101105
warning(
102-
"The group argument has been deprecated. Use `group_by()` instead.\n",
106+
"The group argument has been deprecated. Use `group_by()` or split instead.\n",
103107
"See `help('plotly_data')` for examples"
104108
)
105109
attrs[["group"]] <- NULL
@@ -114,6 +118,7 @@ plot_ly <- function(data = data.frame(), ..., type = NULL,
114118
attrs$symbol <- if (!missing(symbol)) symbol
115119
attrs$linetype <- if (!missing(linetype)) linetype
116120
attrs$size <- if (!missing(size)) size
121+
attrs$split <- if (!missing(split)) split
117122

118123
attrs$colors <- colors
119124
attrs$alpha <- alpha

R/plotly_build.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ plotly_build.plotly <- function(p) {
163163
isAsIs <- vapply(builtData, function(x) inherits(x, "AsIs"), logical(1))
164164
isDiscrete <- vapply(builtData, is.discrete, logical(1))
165165
# note: can only have one linetype per trace
166-
isSplit <- names(builtData) %in% "linetype" |
166+
isSplit <- names(builtData) %in% "split"
167+
names(builtData) %in% "linetype" |
167168
!isAsIs & isDiscrete & names(builtData) %in% c("symbol", "color")
168169
if (any(isSplit)) {
169170
paste2 <- function(x, y) if (identical(x, y)) x else paste(x, y, sep = "<br />")

R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ getLevels <- function(x) {
4949

5050
# currently implemented non-positional scales in plot_ly()
5151
npscales <- function() {
52-
c("color", "symbol", "linetype", "size")
52+
c("color", "symbol", "linetype", "size", "split")
5353
}
5454

5555
# copied from https://github.com/plotly/plotly.js/blob/master/src/components/color/attributes.js

man/add_trace.Rd

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot_ly.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)