Skip to content

Commit 5e5aded

Browse files
committed
fix #486
1 parent 271b271 commit 5e5aded

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

R/ggplotly.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,11 @@ gg2list <- function(p, width = NULL, height = NULL, mapping = "all", source = "A
215215
forMat <- function(x) if (is.numeric(x)) round(x, 2) else x
216216
if (aesName %in% c("x", "y")) {
217217
scaleName <- scales$get_scales(aesName)$scale_name
218-
# convert "milliseconds from the UNIX epoch" back to a date/datetime
218+
# convert "milliseconds from the UNIX epoch" to a date/datetime
219219
# http://stackoverflow.com/questions/13456241/convert-unix-epoch-to-date-object-in-r
220-
if ("date" %in% scaleName) forMat <- function(x) as.Date(as.POSIXct(x / 1000, origin = "1970-01-01"))
221220
if ("datetime" %in% scaleName) forMat <- function(x) as.POSIXct(x / 1000, origin = "1970-01-01")
221+
# convert "days from the UNIX epoch" to a date/datetime
222+
if ("date" %in% scaleName) forMat <- function(x) as.Date(as.POSIXct(x * 86400, origin = "1970-01-01"))
222223
} else {
223224
if (aesName != "text") aesName <- paste0(aesName, "_plotlyDomain")
224225
}

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@ devtools::install_github("ropensci/plotly")
2020

2121
## Introduction
2222

23-
If you use [ggplot2](http://cran.r-project.org/package=ggplot2), use `ggplotly()` to convert your ggplot to an interactive, web-based version!
23+
If you use [ggplot2](http://cran.r-project.org/package=ggplot2), `ggplotly()` converts your plots to an interactive, web-based version! It also provide sensible tooltips that make it easier to decode values encoded as visual properties in the plot.
2424

2525
```r
2626
library(plotly)
27-
set.seed(100)
28-
d <- diamonds[sample(nrow(diamonds), 1000), ]
29-
p <- ggplot(data = d, aes(x = carat, y = price)) +
30-
geom_point(aes(text = paste("Clarity:", clarity))) +
31-
geom_smooth(aes(colour = cut, fill = cut)) + facet_wrap(~ cut)
32-
(gg <- ggplotly(p))
27+
g <- ggplot(faithful, aes(x = eruptions, y = waiting)) +
28+
stat_density_2d(aes(fill = ..level..), geom = "polygon") +
29+
xlim(1, 6) + ylim(40, 100)
30+
ggplotly(g)
3331
```
3432

35-
![https://plot.ly/~agvd/1153](http://i.imgur.com/tbKybEb.png)
33+
![https://plot.ly/~cpsievert/9836](http://imgur.com/6G4zv7b)
3634

37-
[Click here](https://plot.ly/~agvd/1153) to interact with the resulting graph (notice the custom hover text!)
35+
TODO: mention event stuff
3836

3937
__plotly__ also supports certain chart types that ggplot2 doesn't support (such as 3D [surface](https://plot.ly/r/3d-surface-plots/), [point](https://plot.ly/r/3d-scatter-plots/), and [line](https://plot.ly/r/3d-line-plots/) plots). You can easily create these (or any other plotly) charts using the high-level interface.
4038

0 commit comments

Comments
 (0)