Skip to content

Commit 66c3d56

Browse files
committed
merge conflicts
2 parents e9e6979 + 4f61d90 commit 66c3d56

23 files changed

+588
-156
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: plotly
22
Title: Create Interactive Web Graphics via 'plotly.js'
3-
Version: 4.4.5
3+
Version: 4.5.2
44
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
55
email = "[email protected]"),
66
person("Chris", "Parmer", role = c("aut", "cph"),

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export(add_histogram2d)
7676
export(add_histogram2dcontour)
7777
export(add_lines)
7878
export(add_markers)
79+
export(add_mesh)
7980
export(add_paths)
81+
export(add_pie)
8082
export(add_polygons)
8183
export(add_ribbons)
8284
export(add_scattergeo)
@@ -119,7 +121,9 @@ export(layout)
119121
export(mutate)
120122
export(mutate_)
121123
export(offline)
124+
export(plot_geo)
122125
export(plot_ly)
126+
export(plot_mapbox)
123127
export(plotly)
124128
export(plotlyOutput)
125129
export(plotly_IMAGE)

NEWS.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
# 4.5.2 -- 23 September 2016
2+
3+
## NEW FEATURES
4+
5+
* The new argument, `split`, replaces the old functionality of the now deprecated `group` argument by creating one trace per value.
6+
7+
## BUG FIXES
8+
9+
* Passing plots to `subplot()` without a specified color (once again) match the coloring defaults supplied by plotly.js (see #724).
10+
11+
# 4.5.1 -- 23 September 2016
12+
13+
## NEW FEATURES
14+
15+
* A tibble with a list-column of plotly objects can now be input directly into `subplot()`
16+
17+
## BUG FIXES
18+
19+
* The `colorbar()` function now works on colorbars generated via `z` mapping.
20+
21+
# 4.5.0 -- 22 September 2016
22+
23+
## NEW FEATURES
24+
25+
* Added the `plot_mapbox()` and `plot_geo()` functions, which make it easier to work with the "scattermapbox", "scattergeo", and "choropleth" trace types. See the maps chapter of the plotly book for some examples -- <https://cpsievert.github.io/plotly_book/maps.html>
26+
* `subplot()` now accepts, and correctly scales mapbox objects.
27+
* Added the `add_mesh3d()` and `add_pie()` functions as wrappers around the "mesh3d", and "pie" trace types.
28+
29+
## CHANGES
30+
31+
* The `add_scattergeo()` and `add_choropleth()` functions have been deprecated in favor of `plot_geo()`.
32+
* The `add_area(...)` function changed it's meaning from `add_lines(..., fill = 'tozeroy')` to a wrapper around the area trace <https://plot.ly/r/reference/#area>. This is more consistent with the naming conventions already in place for other `add_()` functions.
33+
* `add_ribbons()` now shows points (instead of fill) on hover.
34+
135
# 4.4.5 -- 19 September 2016
236

337
## NEW FEATURES

R/add.R

Lines changed: 70 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,8 @@ add_data <- function(p, data = NULL) {
2121

2222
#' Add trace(s) to a plotly visualization
2323
#'
24-
#' @param p a plotly or ggplot object.
25-
#' @param ... These arguments are documented in the references section below.
26-
#' Note that acceptable arguments depend on the trace type.
27-
#' @param color Either a variable name or a vector to use for color mapping.
28-
#' @param symbol Either a variable name or a (discrete) vector to use for symbol encoding.
29-
#' @param size A variable name or numeric vector to encode the size of markers.
30-
#' @param linetype Either a variable name or a (discrete) vector to use for linetype encoding.
31-
#' @param data A data frame to associate with this trace (optional). If not
32-
#' provided, arguments are evaluated using the data frame in \code{\link{plot_ly}()}.
24+
#' @inheritParams plot_ly
25+
#' @param p a plotly object
3326
#' @param inherit inherit attributes from \code{\link{plot_ly}()}?
3427
#' @param z a numeric matrix
3528
#' @param x the x variable.
@@ -59,20 +52,14 @@ add_data <- function(p, data = NULL) {
5952
#' add_markers(color = ~pop) %>%
6053
#' layout(showlegend = FALSE)
6154
#'
62-
add_trace <- function(p, ..., color, symbol, size, linetype,
55+
add_trace <- function(p, ...,
6356
data = NULL, inherit = TRUE) {
6457

6558
# "native" plotly arguments
6659
attrs <- list(...)
6760

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-
7461
if (!is.null(attrs[["group"]])) {
75-
warning("The group argument has been deprecated. Use group_by() instead.")
62+
warning("The group argument has been deprecated. Use group_by() or split instead.")
7663
}
7764

7865
p <- add_data(p, data)
@@ -251,36 +238,61 @@ add_ribbons <- function(p, x = NULL, ymin = NULL, ymax = NULL, ...,
251238
add_trace_classed(
252239
p, class = c("plotly_ribbon", "plotly_polygon"),
253240
x = x, ymin = ymin, ymax = ymax, type = "scatter", mode = "lines",
254-
fill = "toself", ..., data = data, inherit = inherit
241+
hoveron = "points", fill = "toself", ..., data = data, inherit = inherit
255242
)
256243
}
257244

258-
259245
#' @inheritParams add_trace
260246
#' @rdname add_trace
247+
#' @param r For polar chart only. Sets the radial coordinates.
248+
#' @param t For polar chart only. Sets the radial coordinates.
261249
#' @export
262250
#' @examples
263-
#' huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
264-
#' plot_ly(huron, x = ~year, ymax = ~level) %>% add_area()
265-
add_area <- function(p, x = NULL, ymax = NULL, ...,
251+
#' p <- plot_ly(plotly::wind, r = ~r, t = ~t) %>% add_area(color = ~nms)
252+
#' layout(p, radialaxis = list(ticksuffix = "%"), orientation = 270)
253+
add_area <- function(p, r = NULL, t = NULL, ...,
266254
data = NULL, inherit = TRUE) {
267-
268255
if (inherit) {
269-
x <- x %||% p$x$attrs[[1]][["x"]]
270-
ymax <- ymax %||% p$x$attrs[[1]][["ymax"]]
256+
r <- t %||% p$x$attrs[[1]][["r"]]
257+
t <- t %||% p$x$attrs[[1]][["t"]]
271258
}
272-
if (is.null(x) || is.null(ymax)) {
273-
stop("Must supply `x`/`ymax` attributes", call. = FALSE)
259+
if (is.null(r) || is.null(t)) {
260+
stop("Must supply `r`/`t` attributes", call. = FALSE)
274261
}
275262
add_trace_classed(
276-
p, class = c("plotly_area", "plotly_ribbon", "plotly_polygon"),
277-
x = x, ymax = ymax,
278-
type = "scatter", fill = "toself", mode = "lines",
263+
p, class = "plotly_area", r = r, t = t, type = "area",
279264
..., data = data, inherit = inherit
280265
)
281266
}
282267

283-
268+
#' @inheritParams add_trace
269+
#' @rdname add_trace
270+
#' @param values the value to associated with each slice of the pie.
271+
#' @param labels the labels (categories) corresponding to \code{values}.
272+
#' @export
273+
#' @examples
274+
#' ds <- data.frame(
275+
#' labels = c("A", "B", "C"),
276+
#' values = c(10, 40, 60)
277+
#' )
278+
#'
279+
#' plot_ly(ds, labels = ~labels, values = ~values) %>%
280+
#' add_pie() %>%
281+
#' layout(title = "Basic Pie Chart using Plotly")
282+
add_pie <- function(p, values = NULL, labels = NULL, ...,
283+
data = NULL, inherit = TRUE) {
284+
if (inherit) {
285+
values <- values %||% p$x$attrs[[1]][["values"]]
286+
labels <- labels %||% p$x$attrs[[1]][["labels"]]
287+
}
288+
if (is.null(values)) {
289+
stop("Must supply `values`", call. = FALSE)
290+
}
291+
add_trace_classed(
292+
p, class = "plotly_pie", values = values, labels = labels, type = "pie",
293+
..., data = data, inherit = inherit
294+
)
295+
}
284296

285297
#' @inheritParams add_trace
286298
#' @rdname add_trace
@@ -464,19 +476,23 @@ add_surface <- function(p, z = NULL, ..., data = NULL, inherit = TRUE) {
464476
)
465477
}
466478

467-
468479
#' @inheritParams add_trace
469480
#' @rdname add_trace
470-
#' @param geo anchor this trace on which geo object?
471481
#' @export
472482
#' @examples
473-
#' plot_ly() %>% add_scattergeo()
474-
add_scattergeo <- function(p, geo = NULL, ..., data = NULL, inherit = TRUE) {
483+
#' plot_ly(x = c(0, 0, 1), y = c(0, 1, 0), z = c(0, 0, 0)) %>% add_mesh()
484+
add_mesh <- function(p, x = NULL, y = NULL, z = NULL, ...,
485+
data = NULL, inherit = TRUE) {
475486
if (inherit) {
476-
geo <- geo %||% p$x$attrs[[1]][["geo"]] %||% "geo"
487+
x <- x %||% p$x$attrs[[1]][["x"]]
488+
y <- y %||% p$x$attrs[[1]][["y"]]
489+
z <- z %||% p$x$attrs[[1]][["z"]]
490+
}
491+
if (is.null(x) || is.null(y) || is.null(z)) {
492+
stop("Must supply `x`/`y`/`z` attributes", call. = FALSE)
477493
}
478494
add_trace_classed(
479-
p, class = "plotly_scattergeo", type = "scattergeo", geo = geo,
495+
p, class = "plotly_mesh", x = x, y = y, z = z, type = "mesh3d",
480496
..., data = data, inherit = inherit
481497
)
482498
}
@@ -485,24 +501,18 @@ add_scattergeo <- function(p, geo = NULL, ..., data = NULL, inherit = TRUE) {
485501
#' @inheritParams add_trace
486502
#' @rdname add_trace
487503
#' @export
488-
#' @examples
489-
#' density <- state.x77[, "Population"] / state.x77[, "Area"]
490-
#' plot_ly(z = ~density) %>%
491-
#' add_choropleth(locations = state.abb, locationmode = 'USA-states') %>%
492-
#' layout(geo = list(scope = "usa"))
493-
add_choropleth <- function(p, z = NULL, geo = NULL, ...,
504+
add_scattergeo <- function(p, ...) {
505+
.Deprecated("geo")
506+
p
507+
}
508+
509+
#' @inheritParams add_trace
510+
#' @rdname add_trace
511+
#' @export
512+
add_choropleth <- function(p, z = NULL, ...,
494513
data = NULL, inherit = TRUE) {
495-
if (inherit) {
496-
z <- z %||% p$x$attrs[[1]][["z"]]
497-
geo <- geo %||% p$x$attrs[[1]][["geo"]] %||% "geo"
498-
}
499-
if (is.null(z)) {
500-
stop("Must supply `z` attribute", call. = FALSE)
501-
}
502-
add_trace_classed(
503-
p, class = "plotly_choropleth", z = z, type = "choropleth", geo = geo,
504-
..., data = data, inherit = inherit
505-
)
514+
.Deprecated("geo")
515+
p
506516
}
507517

508518
# attach a class to a trace which informs data processing in plotly_build
@@ -515,12 +525,16 @@ add_trace_classed <- function(p, class = "plotly_polygon", ...) {
515525

516526
# retrieve the non-plotly.js attributes for a given trace
517527
special_attrs <- function(trace) {
518-
switch(
528+
attrs <- switch(
519529
class(trace)[[1]],
520-
plotly_area = c("ymax"),
521530
plotly_segment = c("xend", "yend"),
522531
plotly_ribbon = c("ymin", "ymax")
523532
)
533+
# for data training, we temporarily rename lat/lon as x/y
534+
if (isTRUE(trace[["type"]] %in% c("scattermapbox", "scattergeo"))) {
535+
attrs <- c(attrs, c("x", "y"))
536+
}
537+
attrs
524538
}
525539

526540

R/coord.R

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#' *** This won't be possible until plotly.js implements aspect ratios... ***
2+
#'
3+
#' #' Force the aspect ratio according to x and y scales
4+
#' #'
5+
#' #' When x and y are numeric variables measured on the same scale,
6+
#' #' or are related in some meaningful way, forcing the aspect ratio of the
7+
#' #' plot to be proportional to the ratio of a unit change in x versus y improves
8+
#' #' our ability to correctly perceive the data.
9+
#' #'
10+
#' #' @param p a plotly object
11+
#' #' @param ratio aspect ratio, expressed as y / x
12+
#' #' @export
13+
#' #' @examples
14+
#' #'
15+
#' #' canada <- map_data("world", "canada")
16+
#' #'
17+
#' #' canada %>%
18+
#' #' group_by(group) %>%
19+
#' #' plot_ly(x = ~long, y = ~lat, alpha = 0.2) %>%
20+
#' #' add_polygons(hoverinfo = "none", color = I("black")) %>%
21+
#' #' coord_fix()
22+
#' #'
23+
#' #' # works on (non-faceted) ggplot2 plots, too
24+
#' #' gg <- ggplot(canada, aes(long, lat, group = group)) +
25+
#' #' geom_polygon() + coord_fixed()
26+
#' #'
27+
#' #' gg %>%
28+
#' #' ggplotly() %>%
29+
#' #' coord_fix()
30+
#' #'
31+
#'
32+
#' coord_fix <- function(p, ratio = 1) {
33+
#' p <- plotly_build(p)
34+
#' # this won't work for subplots, or categorical data
35+
#' x <- grepl("^xaxis", names(p$x$layout))
36+
#' y <- grepl("^yaxis", names(p$x$layout))
37+
#' if (sum(x) > 1 || sum(y) > 1) {
38+
#' stop("Can not impose aspect ratio a plot with more than one x/y axis", call. = FALSE)
39+
#' }
40+
#' xDat <- unlist(lapply(p$x$data, "[[", "x"))
41+
#' yDat <- unlist(lapply(p$x$data, "[[", "y"))
42+
#' if (!is.numeric(xDat) || !is.numeric(yDat)) {
43+
#' stop("Must have numeric data on both x and y axes to enforce aspect ratios", call. = FALSE)
44+
#' }
45+
#'
46+
#' # warn about any pre-populated domains, they will get squashed
47+
#' xDom <- p$x$layout[["xaxis"]]$domain %||% c(0, 1)
48+
#' yDom <- p$x$layout[["yaxis"]]$domain %||% c(0, 1)
49+
#' if (!identical(yDom, c(0, 1)) || !identical(xDom, c(0, 1))) {
50+
#' warning(
51+
#' "coord_fix() won't respect prespecified axis domains (other than the default)",
52+
#' call. = FALSE
53+
#' )
54+
#' }
55+
#'
56+
#' xRng <- range(xDat, na.rm = TRUE)
57+
#' yRng <- range(yDat, na.rm = TRUE)
58+
#' asp <- ratio * diff(yRng) / diff(xRng)
59+
#' if (asp < 1) {
60+
#' p$x$layout[["yaxis"]]$domain <- c(0 + asp / 2, 1 - asp / 2)
61+
#' } else {
62+
#' asp <- 1 / asp
63+
#' p$x$layout[["xaxis"]]$domain <- c(0 + asp / 2, 1 - asp / 2)
64+
#' }
65+
#' p
66+
#' }

R/dev.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#' plotly_json(plot_ly())
1313
#' plotly_json(plot_ly(), FALSE)
1414

15-
plotly_json <- function(p = plot_ly(), jsonedit = interactive(), ...) {
15+
plotly_json <- function(p = last_plot(), jsonedit = interactive(), ...) {
1616
plotlyJSON <- to_JSON(plotly_build(p)$x, pretty = TRUE)
1717
if (jsonedit) {
1818
if (system.file(package = "listviewer") == "") {

R/helpers.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ colorbar <- function(p, ...) {
1616
if (sum(isBar) != 1) {
1717
stop("This function only works with one colorbar")
1818
}
19-
p$x$data[[which(isBar)]]$marker$colorbar <- modify_list(
20-
p$x$data[[which(isBar)]]$marker$colorbar, list(...)
21-
)
19+
tr <- p$x$data[[which(isBar)]]
20+
if (inherits(tr, "zcolor")) {
21+
p$x$data[[which(isBar)]][["colorbar"]] <- modify_list(
22+
tr[["colorbar"]], list(...)
23+
)
24+
} else {
25+
p$x$data[[which(isBar)]]$marker$colorbar <- modify_list(
26+
tr$marker$colorbar, list(...)
27+
)
28+
}
2229
p
2330
}
2431

0 commit comments

Comments
 (0)