Skip to content

Better support for trellis displays #727

@cpsievert

Description

@cpsievert

There are a few different ways to do a trellis display currently, but these are all a bit esoteric

one_plot <- function(d) {
  plot_ly(d, x = ~wt, y = ~mpg)
}

mtcars %>%
  group_by(vs) %>%
  do(plot = one_plot(.)) %>%
  subplot(nrows = NROW(.))

plot_ly(mtcars, x = ~wt, y = ~mpg, color = ~factor(vs), yaxis = ~paste0("y", vs + 1)) %>%
  subplot(nrows = 2)

plot_ly(mtcars, x = ~wt, y = ~mpg, split = ~factor(vs), yaxis = ~paste0("y", vs + 1)) %>%
  subplot(nrows = 2)

#726 implements a trellis argument, which essentially maps that variable to sensible trace anchors, then uses subplot()'s machinery to populate axis objects. The problem is, we have guarantee a subplot is returned if we want a sensible result for:

plot_ly(mtcars, x = ~wt, y = ~mpg, trellis = ~vs)

Thus, we lose the ability to specify the number of rows in that subplot

It'd be better to have trellis() function:

trellis <- function(p, formula, ...) {
  # do some stuff here
  subplot(p, ...)
}

Ideally, the trellising would work a lot like ggplot2 facets (trellising variables should not appear in legends, and appear as annotations instead). This is what we do in ggplotly() via clever use of showlegend and legendgroup.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions