plotly / plotly/plotly.R

Better support for trellis displays

Open
#727 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the trellis argument proposed in #726 and the existing subplot() machinery first. A completed solution should provide a trellis() function that preserves control over subplot rows and supports ggplot2-like behavior, including keeping trellising variables out of legends and showing them as annotations.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.