Skip to content

Commit 606d996

Browse files
committed
Merge pull request #500 from ropensci/fix/CRAN-release
Fix/cran release
2 parents de00838 + a7cddcd commit 606d996

19 files changed

+327
-83
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
^data-raw$
55
CONDUCT.md
66
CONTRIBUTING.md
7+
build_site.R

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ Rapp.history
44
*.RData
55
*.Rproj.user
66
.Rproj.user
7+
build_site.R
8+
inst/examples/*/*.html
9+
inst/examples/*/rsconnect/*

DESCRIPTION

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: plotly
2-
Title: Create Interactive Web Graphics via Plotly's JavaScript Graphing Library
3-
Version: 3.3.1
2+
Title: Create Interactive Web Graphics via 'plotly.js'
3+
Version: 3.3.2
44
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
55
email = "cpsievert1@gmail.com"),
66
person("Chris", "Parmer", role = c("aut", "cph"),
@@ -16,7 +16,7 @@ Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
1616
person("Pedro", "Despouy", role = "aut",
1717
email = "pedro@plot.ly"))
1818
License: MIT + file LICENSE
19-
Description: Easily translate ggplot2 graphs to an interactive web-based version and/or create custom web-based visualizations directly from R. Once uploaded to a plotly account, plotly graphs (and the data behind them) can be viewed and modified in a web browser.
19+
Description: Easily translate 'ggplot2' graphs to an interactive web-based version and/or create custom web-based visualizations directly from R. Once uploaded to a 'plotly' account, 'plotly' graphs (and the data behind them) can be viewed and modified in a web browser.
2020
URL: https://plot.ly/r, https://github.com/ropensci/plotly
2121
BugReports: https://github.com/ropensci/plotly/issues
2222
Depends:
@@ -47,7 +47,8 @@ Suggests:
4747
RColorBrewer,
4848
Rserve,
4949
RSclient,
50-
broom
50+
broom,
51+
hexbin
5152
LazyData: true
5253
VignetteBuilder: knitr
5354
RoxygenNote: 5.0.1

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ S3method(to_basic,GeomDensity)
2121
S3method(to_basic,GeomDensity2d)
2222
S3method(to_basic,GeomErrorbar)
2323
S3method(to_basic,GeomErrorbarh)
24+
S3method(to_basic,GeomHex)
2425
S3method(to_basic,GeomHline)
2526
S3method(to_basic,GeomJitter)
2627
S3method(to_basic,GeomLine)
2728
S3method(to_basic,GeomLinerange)
29+
S3method(to_basic,GeomMap)
2830
S3method(to_basic,GeomPointrange)
2931
S3method(to_basic,GeomRaster)
3032
S3method(to_basic,GeomRect)

NEWS

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
3.3.1 -- 10 Mar 2015
1+
3.4.0 -- 12 Mar 2016
2+
3+
NEW FEATURES:
4+
5+
* geom_map() and geom_hex() are now supported.
6+
7+
CHANGES:
8+
9+
* The default value of the fileopt argument was changed from "new" to "overwrite".
10+
11+
BUGFIX:
12+
13+
* Made a number of bugfixes/improvements to hoverinfo & conversion of geom_tile()/geom_point().
14+
15+
3.3.1 -- 10 Mar 2016
216

317
CHANGES:
418

@@ -8,13 +22,13 @@ BUGFIX:
822

923
* Redundant legend entries are no longer shown.
1024

11-
3.2.1 -- 10 Mar 2015
25+
3.2.1 -- 10 Mar 2016
1226

1327
BUGFIX:
1428

1529
* Proper formatting for date tooltips.
1630

17-
3.2.0 -- 10 Mar 2015
31+
3.2.0 -- 10 Mar 2016
1832

1933
CHANGES:
2034

@@ -27,14 +41,14 @@ NEW FEATURES:
2741
* geom_violin() is now supported.
2842
* ggplotly() gains a mapping argument to control the set of aesthetics to appears in the tooltip as well as their order.
2943

30-
3.1.0 -- 8 Mar 2015
44+
3.1.0 -- 8 Mar 2016
3145

3246
CHANGES:
3347

3448
* The "hidden" sharing option in plotly_POST() was renamed to "secret".
3549
* The default value in the scale argument in plotly_IMAGE() is now 1.
3650

37-
3.0.0 -- 8 Mar 2015
51+
3.0.0 -- 8 Mar 2016
3852

3953
NEW FEATURES:
4054

@@ -48,7 +62,7 @@ BUG FIXES:
4862

4963
* ggplotly() now supports most of scale_*()/theme()/guides(). As a result, this fixes a lot of issues (#482, #481, #479, #476, #473, #460, #456, #454, #453, #447, #443, #434, #422, #421, #399, #379, #378, #357, #318, #316, #242, #232, #211, #203, #185, #184, #161). In order to support all of scale_x_*() an scale_y_*(), we always use linear axis types, and supply ticktext/tickvals to plotly.js. This has some unfortunate consequences on hoverformatting, which may be addressed in future releases of plotly.js -- https://github.com/plotly/plotly.js/issues/320
5064

51-
2.5.0 -- 1 Mar 2015
65+
2.5.0 -- 1 Mar 2016
5266

5367
NEW FEATURES
5468

@@ -64,76 +78,76 @@ CHANGES
6478
The arguments filename, fileopt, world_readable in ggplotly() were removed as
6579
they should be provided to plotly_POST() instead.
6680

67-
2.4.4 -- 13 Feb 2015
81+
2.4.4 -- 13 Feb 2016
6882

6983
as.widget() now returns htmlwidget objects untouched. See #449.
7084

71-
2.4.3 -- 11 Feb 2015
85+
2.4.3 -- 11 Feb 2016
7286

7387
Ensure that we always return HTTPS links. Fixes #455
7488

75-
2.4.2 -- 9 Feb 2015
89+
2.4.2 -- 9 Feb 2016
7690

7791
Fix for on-premise domain configuration.
7892

79-
2.4.1 -- 2 Feb 2015
93+
2.4.1 -- 2 Feb 2016
8094

8195
Attach base_url in as.widget() so it works in multiple contexts
8296

83-
2.4.0 -- 1 Feb 2015
97+
2.4.0 -- 1 Feb 2016
8498

8599
* Pass plot configuration using ... to avoid conflicts in defaults/documentation
86100
* Upgrade to plotly.js 1.5.1
87101

88-
2.3.4 -- 1 Feb 2015
102+
2.3.4 -- 1 Feb 2016
89103

90104
Added a plotly_api_domain environment variable for configuring the API domain. Fixes #441
91105

92-
2.3.3 -- 27 Jan 2015
106+
2.3.3 -- 27 Jan 2016
93107

94108
Bump axis number for each trace matching a panel number. fixes #318
95109

96-
2.3.2 -- 25 Jan 2015
110+
2.3.2 -- 25 Jan 2016
97111

98112
More accurate list of data_array properties. Fixes #415
99113

100-
2.3.1 -- 25 Jan 2015
114+
2.3.1 -- 25 Jan 2016
101115

102116
More accurate conversion of path width. Fixes #373.
103117

104-
2.3.0 -- 19 Jan 2015
118+
2.3.0 -- 19 Jan 2016
105119

106120
Add sharing argument and deprecate world_readable. Fixes #332
107121

108-
2.2.4 -- 18 Jan 2015
122+
2.2.4 -- 18 Jan 2016
109123

110124
Fix for error in embed_notebook(). See #409.
111125

112-
2.2.3 -- 18 Jan 2015
126+
2.2.3 -- 18 Jan 2016
113127

114128
Fix for geom_vline(). See #402.
115129

116-
2.2.2 -- 18 Jan 2015
130+
2.2.2 -- 18 Jan 2016
117131

118132
Fix bar orientation when we detect geom_bar() + coord_flip() in ggplotly(). Fixes #390.
119133

120-
2.2.1 -- 18 Jan 2015
134+
2.2.1 -- 18 Jan 2016
121135

122136
Search for axis title in scene object. fixes #393.
123137

124-
2.2.0 -- 13 Jan 2015
138+
2.2.0 -- 13 Jan 2016
125139

126140
The default for layout.hovermode is now 'closest' for non-line scatter traces
127141

128-
2.1.3 -- 12 Jan 2015
142+
2.1.3 -- 12 Jan 2016
129143

130144
Fix size and alpha translation for geom_point. Fixes #386
131145

132-
2.1.2 -- 11 Jan 2015
146+
2.1.2 -- 11 Jan 2016
133147

134148
Upgraded to plotlyjs 1.4.1. For a list of changes, see https://github.com/plotly/plotly.js/releases/tag/v1.4.1
135149

136-
2.1.1 -- 11 Jan 2015
150+
2.1.1 -- 11 Jan 2016
137151

138152
Upgraded to plotlyjs 1.4. For a list of changes, see https://github.com/plotly/plotly.js/releases/tag/v1.4.0
139153

R/ggplotly.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,8 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
189189
)
190190
# remove leading/trailing dots in "hidden" stat aes
191191
map <- sub("^\\.\\.", "", sub("\\.\\.$", "", map))
192-
# TODO: allow users to specify a _list_ of mappings?
193192
if (!identical(tooltip, "all")) {
194-
map <- map[names(map) %in% tooltip]
193+
map <- map[tooltip]
195194
}
196195
# tooltips for discrete positional scales are misleading
197196
if (scales$get_scales("x")$is_discrete()) {
@@ -217,15 +216,20 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
217216
scaleName <- scales$get_scales(aesName)$scale_name
218217
# convert "milliseconds from the UNIX epoch" to a date/datetime
219218
# http://stackoverflow.com/questions/13456241/convert-unix-epoch-to-date-object-in-r
220-
if ("datetime" %in% scaleName) forMat <- function(x) as.POSIXct(x / 1000, origin = "1970-01-01")
219+
if ("datetime" %in% scaleName) forMat <- function(x) as.POSIXct(x, origin = "1970-01-01")
221220
# convert "days from the UNIX epoch" to a date/datetime
222221
if ("date" %in% scaleName) forMat <- function(x) as.Date(as.POSIXct(x * 86400, origin = "1970-01-01"))
223-
} else {
224-
if (aesName != "text") aesName <- paste0(aesName, "_plotlyDomain")
225222
}
226223
# add a line break if hovertext already exists
227224
if ("hovertext" %in% names(x)) x$hovertext <- paste0(x$hovertext, "<br>")
228-
x$hovertext <- paste0(x$hovertext, varName, ": ", forMat(x[[aesName]]))
225+
# text aestheic should be taken verbatim (for custom tooltips)
226+
prefix <- if (identical(aesName, "text")) "" else paste0(varName, ": ")
227+
# look for the domain, if that's not found, provide the range (useful for identity scales)
228+
suffix <- tryCatch(
229+
forMat(x[[paste0(aesName, "_plotlyDomain")]] %||% x[[aesName]]),
230+
error = function(e) ""
231+
)
232+
x$hovertext <- paste0(x$hovertext, prefix, suffix)
229233
}
230234
x
231235
}, data, aesMap)

R/layers2traces.R

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ layers2traces <- function(data, prestats_data, layers, layout, scales, labels) {
4949
apply(d[idx], 1, paste, collapse = "@%&"),
5050
levels = apply(lvls, 1, paste, collapse = "@%&")
5151
)
52+
if (all(is.na(fac))) fac <- 1
5253
dl <- split(d, fac, drop = TRUE)
5354
# list of traces for this layer
5455
trs <- Map(geom2trace, dl, paramz[i])
@@ -200,6 +201,20 @@ to_basic.GeomRect <- function(data, prestats_data, layout, params, ...) {
200201
prefix_class(data, "GeomPolygon")
201202
}
202203

204+
#' @export
205+
to_basic.GeomMap <- function(data, prestats_data, layout, params, ...) {
206+
common <- intersect(data$map_id, params$map$id)
207+
data <- data[data$map_id %in% common, , drop = FALSE]
208+
map <- params$map[params$map$id %in% common, , drop = FALSE]
209+
# TODO: do we need coord_munch() as in GeomMap$draw_panel()
210+
data$id <- data$map_id
211+
data$map_id <- NULL
212+
data$group <- NULL
213+
data <- merge(data, map, by = "id", sort = FALSE)
214+
data$group <- interaction(data[names(data) %in% c("PANEL", "group", "id")])
215+
prefix_class(data, c("GeomPolygon", "GeomMap"))
216+
}
217+
203218
#' @export
204219
to_basic.GeomRaster <- function(data, prestats_data, layout, params, ...) {
205220
data <- prefix_class(data, "GeomTile")
@@ -219,6 +234,23 @@ to_basic.GeomTile <- function(data, prestats_data, layout, params, ...) {
219234
}
220235
}
221236

237+
#' @export
238+
to_basic.GeomHex <- function(data, prestats_data, layout, params, ...) {
239+
# see ggplot2:::hexGrob
240+
dx <- resolution(data$x, FALSE)
241+
dy <- resolution(data$y, FALSE)/sqrt(3)/2 * 1.15
242+
hexC <- hexbin::hexcoords(dx, dy, n = 1)
243+
n <- nrow(data)
244+
data$size <- ifelse(data$size < 1, data$size ^ (1 / 6), data$size ^ 6)
245+
x <- rep.int(hexC$x, n) * rep(data$size, each = 6) + rep(data$x, each = 6)
246+
y <- rep.int(hexC$y, n) * rep(data$size, each = 6) + rep(data$y, each = 6)
247+
data <- data[rep(seq_len(n), each = 6), ]
248+
data$x <- x
249+
data$y <- y
250+
data$group <- rep(seq_len(n), each = 6)
251+
prefix_class(data, c("GeomPolygon", "GeomHex"))
252+
}
253+
222254
#' @export
223255
to_basic.GeomContour <- function(data, prestats_data, layout, params, ...) {
224256
if (!"fill" %in% names(data)) data$fill <- NA
@@ -227,6 +259,10 @@ to_basic.GeomContour <- function(data, prestats_data, layout, params, ...) {
227259

228260
#' @export
229261
to_basic.GeomDensity2d <- function(data, prestats_data, layout, params, ...) {
262+
if ("hovertext" %in% names(data)) {
263+
data$hovertext <- paste0(data$hovertext, "<br>")
264+
}
265+
data$hovertext <- paste0(data$hovertext, "Level: ", data$level)
230266
if (!"fill" %in% names(data)) data$fill <- NA
231267
prefix_class(data, "GeomPath")
232268
}
@@ -272,6 +308,7 @@ to_basic.GeomJitter <- function(data, prestats_data, layout, params, ...) {
272308
prefix_class(data, "GeomPoint")
273309
}
274310

311+
275312
#' @export
276313
to_basic.GeomErrorbar <- function(data, prestats_data, layout, params, ...) {
277314
# width for ggplot2 means size of the entire bar, on the data scale
@@ -338,7 +375,6 @@ geom2trace.GeomPath <- function(data, params) {
338375
x = data$x,
339376
y = data$y,
340377
text = data$hovertext,
341-
hoverinfo = "text",
342378
type = "scatter",
343379
mode = "lines",
344380
name = if (inherits(data, "GeomSmooth")) "fitted values",
@@ -380,7 +416,8 @@ geom2trace.GeomPoint <- function(data, params) {
380416
)
381417
# fill is irrelevant for pch %in% c(1, 15:20)
382418
pch <- uniq(data$shape) %||% params$shape %||% GeomPoint$default_aes$shape
383-
if (any(pch %in% c(1, 15:20))) {
419+
if (any(pch %in% c(1, 15:20)) ||
420+
all(grepl("open$", shape)) && all(L$marker$color %in% "transparent")) {
384421
L$marker$color <- L$marker$line$color
385422
}
386423
L
@@ -432,8 +469,7 @@ geom2trace.GeomPolygon <- function(data, params) {
432469
)
433470
)
434471
if (inherits(data, "GeomSmooth")) {
435-
L$name <- "standard error"
436-
L$showlegend <- FALSE
472+
L$hoverinfo <- "x+y"
437473
}
438474
L
439475

@@ -491,27 +527,23 @@ geom2trace.GeomText <- function(data, params) {
491527
#' @export
492528
geom2trace.GeomTile <- function(data, params) {
493529
# make sure order of value make sense before throwing z in matrix
494-
data <- data[order(data$x, order(data$y, decreasing = T)), ]
530+
data <- data[order(order(data$x), data$y), ]
495531
x <- sort(unique(data$x))
496532
y <- sort(unique(data$y))
497-
fill <- data$fill_plotlyDomain
498-
colorscale <- cbind(
499-
c(0, 1),
500-
data[c(which.min(fill), which.max(fill)), "fill"]
501-
)
533+
fill <- scales::rescale(data$fill_plotlyDomain)
534+
txt <- data$hovertext
535+
# create the colorscale, which should ignore NAs
536+
data <- data[!is.na(fill), ]
537+
o <- data[order(data$fill_plotlyDomain), "fill"]
538+
n <- length(o)
539+
qs <- seq(0, 1, length.out = min(n, 100))
540+
idx <- o[pmax(1, round(n * qs))]
541+
colorscale <- cbind(qs, idx)
502542
list(
503543
x = x,
504544
y = y,
505-
z = matrix(
506-
scales::rescale(fill),
507-
nrow = length(y),
508-
ncol = length(x)
509-
),
510-
text = matrix(
511-
data$hovertext,
512-
nrow = length(y),
513-
ncol = length(x)
514-
),
545+
z = matrix(fill, nrow = length(y), ncol = length(x)),
546+
text = matrix(txt, nrow = length(y), ncol = length(x)),
515547
colorscale = colorscale,
516548
type = "heatmap",
517549
showscale = FALSE,
@@ -619,10 +651,10 @@ make_error <- function(data, params, xy = "x") {
619651
e <- list(
620652
x = data$x,
621653
y = data$y,
654+
text = data$hovertext,
622655
type = "scatter",
623656
mode = "lines",
624657
opacity = 0,
625-
hoverinfo = "none",
626658
line = list(color = color)
627659
)
628660
e[[paste0("error_", xy)]] <- list(

0 commit comments

Comments
 (0)