diff --git a/NAMESPACE b/NAMESPACE index dd80145f23..5d3c95aca7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -97,6 +97,7 @@ export(add_histogram2dcontour) export(add_lines) export(add_markers) export(add_mesh) +export(add_parcoords) export(add_paths) export(add_pie) export(add_polygons) diff --git a/R/add.R b/R/add.R index 31de4c02e1..59c35241cf 100644 --- a/R/add.R +++ b/R/add.R @@ -373,6 +373,28 @@ add_table <- function(p, ..., rownames = TRUE, data = NULL, inherit = TRUE) { } +#' @inheritParams add_trace +#' @param rownames whether or not to display the rownames of `data`. +#' @rdname add_trace +#' @export +add_parcoords <- function(p, ..., data = NULL, inherit = TRUE) { + attrs <- list(...) + dat <- plotly_data(add_data(p, data)) + # if a dataset is provided, and dimensions are not pre-specified + dimensions <- attrs$dimensions %||% if (inherit) p$x$attrs[[1]]$dimensions + if (is.data.frame(dat) && is.null(dimensions)) { + d <- dat[sapply(dat, is.numeric)] + dimensions <- Map(function(x, y) { + list(values = x, range = range(x, na.rm = TRUE), label = y) + }, d, names(d), USE.NAMES = FALSE) + } + add_trace_classed( + p = p, class = "plotly_parcoords", type = "parcoords", + dimensions = dimensions, ... + ) +} + + #' @inheritParams add_trace #' @rdname add_trace #' @export diff --git a/man/add_trace.Rd b/man/add_trace.Rd index 2746c1544a..f2f8df3f63 100644 --- a/man/add_trace.Rd +++ b/man/add_trace.Rd @@ -10,6 +10,7 @@ \alias{add_polygons} \alias{add_sf} \alias{add_table} +\alias{add_parcoords} \alias{add_ribbons} \alias{add_area} \alias{add_pie} @@ -50,6 +51,8 @@ add_sf(p, ..., x = ~x, y = ~y, data = NULL, inherit = TRUE) add_table(p, ..., rownames = TRUE, data = NULL, inherit = TRUE) +add_parcoords(p, ..., data = NULL, inherit = TRUE) + add_ribbons(p, x = NULL, ymin = NULL, ymax = NULL, ..., data = NULL, inherit = TRUE) @@ -124,6 +127,8 @@ provided at this level may override other arguments \item{values}{the value to associated with each slice of the pie.} \item{labels}{the labels (categories) corresponding to \code{values}.} + +\item{rownames}{whether or not to display the rownames of \code{data}.} } \description{ Add trace(s) to a plotly visualization