Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
^data-raw$
CONDUCT.md
CONTRIBUTING.md
build_site.R
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ Rapp.history
*.RData
*.Rproj.user
.Rproj.user
build_site.R
inst/examples/*/*.html
inst/examples/*/rsconnect/*
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: plotly
Title: Create Interactive Web Graphics via Plotly's JavaScript Graphing Library
Version: 3.3.1
Title: Create Interactive Web Graphics via 'plotly.js'
Version: 3.3.2
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
email = "cpsievert1@gmail.com"),
person("Chris", "Parmer", role = c("aut", "cph"),
Expand All @@ -16,7 +16,7 @@ Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
person("Pedro", "Despouy", role = "aut",
email = "pedro@plot.ly"))
License: MIT + file LICENSE
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.
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.
URL: https://plot.ly/r, https://github.com/ropensci/plotly
BugReports: https://github.com/ropensci/plotly/issues
Depends:
Expand Down Expand Up @@ -47,7 +47,8 @@ Suggests:
RColorBrewer,
Rserve,
RSclient,
broom
broom,
hexbin
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 5.0.1
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ S3method(to_basic,GeomDensity)
S3method(to_basic,GeomDensity2d)
S3method(to_basic,GeomErrorbar)
S3method(to_basic,GeomErrorbarh)
S3method(to_basic,GeomHex)
S3method(to_basic,GeomHline)
S3method(to_basic,GeomJitter)
S3method(to_basic,GeomLine)
S3method(to_basic,GeomLinerange)
S3method(to_basic,GeomMap)
S3method(to_basic,GeomPointrange)
S3method(to_basic,GeomRaster)
S3method(to_basic,GeomRect)
Expand Down
62 changes: 38 additions & 24 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
3.3.1 -- 10 Mar 2015
3.4.0 -- 12 Mar 2016

NEW FEATURES:

* geom_map() and geom_hex() are now supported.

CHANGES:

* The default value of the fileopt argument was changed from "new" to "overwrite".

BUGFIX:

* Made a number of bugfixes/improvements to hoverinfo & conversion of geom_tile()/geom_point().

3.3.1 -- 10 Mar 2016

CHANGES:

Expand All @@ -8,13 +22,13 @@ BUGFIX:

* Redundant legend entries are no longer shown.

3.2.1 -- 10 Mar 2015
3.2.1 -- 10 Mar 2016

BUGFIX:

* Proper formatting for date tooltips.

3.2.0 -- 10 Mar 2015
3.2.0 -- 10 Mar 2016

CHANGES:

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

3.1.0 -- 8 Mar 2015
3.1.0 -- 8 Mar 2016

CHANGES:

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

3.0.0 -- 8 Mar 2015
3.0.0 -- 8 Mar 2016

NEW FEATURES:

Expand All @@ -48,7 +62,7 @@ BUG FIXES:

* 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

2.5.0 -- 1 Mar 2015
2.5.0 -- 1 Mar 2016

NEW FEATURES

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

2.4.4 -- 13 Feb 2015
2.4.4 -- 13 Feb 2016

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

2.4.3 -- 11 Feb 2015
2.4.3 -- 11 Feb 2016

Ensure that we always return HTTPS links. Fixes #455

2.4.2 -- 9 Feb 2015
2.4.2 -- 9 Feb 2016

Fix for on-premise domain configuration.

2.4.1 -- 2 Feb 2015
2.4.1 -- 2 Feb 2016

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

2.4.0 -- 1 Feb 2015
2.4.0 -- 1 Feb 2016

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

2.3.4 -- 1 Feb 2015
2.3.4 -- 1 Feb 2016

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

2.3.3 -- 27 Jan 2015
2.3.3 -- 27 Jan 2016

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

2.3.2 -- 25 Jan 2015
2.3.2 -- 25 Jan 2016

More accurate list of data_array properties. Fixes #415

2.3.1 -- 25 Jan 2015
2.3.1 -- 25 Jan 2016

More accurate conversion of path width. Fixes #373.

2.3.0 -- 19 Jan 2015
2.3.0 -- 19 Jan 2016

Add sharing argument and deprecate world_readable. Fixes #332

2.2.4 -- 18 Jan 2015
2.2.4 -- 18 Jan 2016

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

2.2.3 -- 18 Jan 2015
2.2.3 -- 18 Jan 2016

Fix for geom_vline(). See #402.

2.2.2 -- 18 Jan 2015
2.2.2 -- 18 Jan 2016

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

2.2.1 -- 18 Jan 2015
2.2.1 -- 18 Jan 2016

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

2.2.0 -- 13 Jan 2015
2.2.0 -- 13 Jan 2016

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

2.1.3 -- 12 Jan 2015
2.1.3 -- 12 Jan 2016

Fix size and alpha translation for geom_point. Fixes #386

2.1.2 -- 11 Jan 2015
2.1.2 -- 11 Jan 2016

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

2.1.1 -- 11 Jan 2015
2.1.1 -- 11 Jan 2016

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

Expand Down
16 changes: 10 additions & 6 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,8 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
)
# remove leading/trailing dots in "hidden" stat aes
map <- sub("^\\.\\.", "", sub("\\.\\.$", "", map))
# TODO: allow users to specify a _list_ of mappings?
if (!identical(tooltip, "all")) {
map <- map[names(map) %in% tooltip]
map <- map[tooltip]
}
# tooltips for discrete positional scales are misleading
if (scales$get_scales("x")$is_discrete()) {
Expand All @@ -217,15 +216,20 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
scaleName <- scales$get_scales(aesName)$scale_name
# convert "milliseconds from the UNIX epoch" to a date/datetime
# http://stackoverflow.com/questions/13456241/convert-unix-epoch-to-date-object-in-r
if ("datetime" %in% scaleName) forMat <- function(x) as.POSIXct(x / 1000, origin = "1970-01-01")
if ("datetime" %in% scaleName) forMat <- function(x) as.POSIXct(x, origin = "1970-01-01")
# convert "days from the UNIX epoch" to a date/datetime
if ("date" %in% scaleName) forMat <- function(x) as.Date(as.POSIXct(x * 86400, origin = "1970-01-01"))
} else {
if (aesName != "text") aesName <- paste0(aesName, "_plotlyDomain")
}
# add a line break if hovertext already exists
if ("hovertext" %in% names(x)) x$hovertext <- paste0(x$hovertext, "<br>")
x$hovertext <- paste0(x$hovertext, varName, ": ", forMat(x[[aesName]]))
# text aestheic should be taken verbatim (for custom tooltips)
prefix <- if (identical(aesName, "text")) "" else paste0(varName, ": ")
# look for the domain, if that's not found, provide the range (useful for identity scales)
suffix <- tryCatch(
forMat(x[[paste0(aesName, "_plotlyDomain")]] %||% x[[aesName]]),
error = function(e) ""
)
x$hovertext <- paste0(x$hovertext, prefix, suffix)
}
x
}, data, aesMap)
Expand Down
74 changes: 53 additions & 21 deletions R/layers2traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ layers2traces <- function(data, prestats_data, layers, layout, scales, labels) {
apply(d[idx], 1, paste, collapse = "@%&"),
levels = apply(lvls, 1, paste, collapse = "@%&")
)
if (all(is.na(fac))) fac <- 1
dl <- split(d, fac, drop = TRUE)
# list of traces for this layer
trs <- Map(geom2trace, dl, paramz[i])
Expand Down Expand Up @@ -200,6 +201,20 @@ to_basic.GeomRect <- function(data, prestats_data, layout, params, ...) {
prefix_class(data, "GeomPolygon")
}

#' @export
to_basic.GeomMap <- function(data, prestats_data, layout, params, ...) {
common <- intersect(data$map_id, params$map$id)
data <- data[data$map_id %in% common, , drop = FALSE]
map <- params$map[params$map$id %in% common, , drop = FALSE]
# TODO: do we need coord_munch() as in GeomMap$draw_panel()
data$id <- data$map_id
data$map_id <- NULL
data$group <- NULL
data <- merge(data, map, by = "id", sort = FALSE)
data$group <- interaction(data[names(data) %in% c("PANEL", "group", "id")])
prefix_class(data, c("GeomPolygon", "GeomMap"))
}

#' @export
to_basic.GeomRaster <- function(data, prestats_data, layout, params, ...) {
data <- prefix_class(data, "GeomTile")
Expand All @@ -219,6 +234,23 @@ to_basic.GeomTile <- function(data, prestats_data, layout, params, ...) {
}
}

#' @export
to_basic.GeomHex <- function(data, prestats_data, layout, params, ...) {
# see ggplot2:::hexGrob
dx <- resolution(data$x, FALSE)
dy <- resolution(data$y, FALSE)/sqrt(3)/2 * 1.15
hexC <- hexbin::hexcoords(dx, dy, n = 1)
n <- nrow(data)
data$size <- ifelse(data$size < 1, data$size ^ (1 / 6), data$size ^ 6)
x <- rep.int(hexC$x, n) * rep(data$size, each = 6) + rep(data$x, each = 6)
y <- rep.int(hexC$y, n) * rep(data$size, each = 6) + rep(data$y, each = 6)
data <- data[rep(seq_len(n), each = 6), ]
data$x <- x
data$y <- y
data$group <- rep(seq_len(n), each = 6)
prefix_class(data, c("GeomPolygon", "GeomHex"))
}

#' @export
to_basic.GeomContour <- function(data, prestats_data, layout, params, ...) {
if (!"fill" %in% names(data)) data$fill <- NA
Expand All @@ -227,6 +259,10 @@ to_basic.GeomContour <- function(data, prestats_data, layout, params, ...) {

#' @export
to_basic.GeomDensity2d <- function(data, prestats_data, layout, params, ...) {
if ("hovertext" %in% names(data)) {
data$hovertext <- paste0(data$hovertext, "<br>")
}
data$hovertext <- paste0(data$hovertext, "Level: ", data$level)
if (!"fill" %in% names(data)) data$fill <- NA
prefix_class(data, "GeomPath")
}
Expand Down Expand Up @@ -272,6 +308,7 @@ to_basic.GeomJitter <- function(data, prestats_data, layout, params, ...) {
prefix_class(data, "GeomPoint")
}


#' @export
to_basic.GeomErrorbar <- function(data, prestats_data, layout, params, ...) {
# width for ggplot2 means size of the entire bar, on the data scale
Expand Down Expand Up @@ -338,7 +375,6 @@ geom2trace.GeomPath <- function(data, params) {
x = data$x,
y = data$y,
text = data$hovertext,
hoverinfo = "text",
type = "scatter",
mode = "lines",
name = if (inherits(data, "GeomSmooth")) "fitted values",
Expand Down Expand Up @@ -380,7 +416,8 @@ geom2trace.GeomPoint <- function(data, params) {
)
# fill is irrelevant for pch %in% c(1, 15:20)
pch <- uniq(data$shape) %||% params$shape %||% GeomPoint$default_aes$shape
if (any(pch %in% c(1, 15:20))) {
if (any(pch %in% c(1, 15:20)) ||
all(grepl("open$", shape)) && all(L$marker$color %in% "transparent")) {
L$marker$color <- L$marker$line$color
}
L
Expand Down Expand Up @@ -432,8 +469,7 @@ geom2trace.GeomPolygon <- function(data, params) {
)
)
if (inherits(data, "GeomSmooth")) {
L$name <- "standard error"
L$showlegend <- FALSE
L$hoverinfo <- "x+y"
}
L

Expand Down Expand Up @@ -491,27 +527,23 @@ geom2trace.GeomText <- function(data, params) {
#' @export
geom2trace.GeomTile <- function(data, params) {
# make sure order of value make sense before throwing z in matrix
data <- data[order(data$x, order(data$y, decreasing = T)), ]
data <- data[order(order(data$x), data$y), ]
x <- sort(unique(data$x))
y <- sort(unique(data$y))
fill <- data$fill_plotlyDomain
colorscale <- cbind(
c(0, 1),
data[c(which.min(fill), which.max(fill)), "fill"]
)
fill <- scales::rescale(data$fill_plotlyDomain)
txt <- data$hovertext
# create the colorscale, which should ignore NAs
data <- data[!is.na(fill), ]
o <- data[order(data$fill_plotlyDomain), "fill"]
n <- length(o)
qs <- seq(0, 1, length.out = min(n, 100))
idx <- o[pmax(1, round(n * qs))]
colorscale <- cbind(qs, idx)
list(
x = x,
y = y,
z = matrix(
scales::rescale(fill),
nrow = length(y),
ncol = length(x)
),
text = matrix(
data$hovertext,
nrow = length(y),
ncol = length(x)
),
z = matrix(fill, nrow = length(y), ncol = length(x)),
text = matrix(txt, nrow = length(y), ncol = length(x)),
colorscale = colorscale,
type = "heatmap",
showscale = FALSE,
Expand Down Expand Up @@ -619,10 +651,10 @@ make_error <- function(data, params, xy = "x") {
e <- list(
x = data$x,
y = data$y,
text = data$hovertext,
type = "scatter",
mode = "lines",
opacity = 0,
hoverinfo = "none",
line = list(color = color)
)
e[[paste0("error_", xy)]] <- list(
Expand Down
Loading