Skip to content

ggplotly design, internals, technical stuff

Toby Dylan Hocking edited this page May 5, 2014 · 7 revisions

legends

ggplot2 legends are more sophisticated than plotly legends, so it is impossible to translate everything. In particular there may be several legends in ggplot2 (color, linetype, etc) but only 1 in plotly. Plotly takes the legend labels from the names of the traces.

themes

theme stuff you are correct that there are many things not supported. It is more because I first wanted to focus on implementing data-driven elements like geoms. We would like the plotly version to look as similar as possible to the ggplot, and I encourage you to contribute if you notice any differences, but please be aware that there are some ggplot features again that plotly does not support. One example is minor gridlines.

things the plotly web site does not support

Chris (did you meet him yet?) gave me a more extensive list of features that he thought plotly does not support, about a month ago https://github.com/tdhock/ggplotly/blob/master/README-old.org --- but now that I know plotly better, I think we could at least draw all of those actually.

ggplotly development function

copy/paste the following code into your ~/.Rprofile

library(plotly)
Plotly <- plotly("YOUR_USERNAME", "YOUR_KEY")
ggplotly <- function(gg, p=Plotly){
  if(!is.ggplot(gg)){
    stop("gg must be a ggplot")
  }
  if(!is.function(p$plotly)){
    stop("p must be a plotly interface object")
  }
  pargs <- gg2list(gg)
  resp <- do.call(p$plotly, pargs)
  browseURL(resp$url)
  invisible(list(data=pargs, response=resp))
}

Ordinarily package users will do Plotly$ggplotly() to send their last ggplot to plotly, but for development I find that it is easier to try new code by first editing plotly/R/ggplotly.R, then doing source("plotly/R/ggplotly.R"), then ggplotly(g) with some ggplot g. Otherwise you have the additional step of re-making the Plotly <- plotly(...) object every time you edit the code.

Clone this wiki locally