plotly / plotly/plotly.R

Setting anchor = "free" in R subplot() causes the graph to disappear

Open
#1,768 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I'm trying to build a subplot of stacked scatter plots, where there are multiple axes on each scatter plot.

Below is an example of the type of plot. To position the yaxis side-by-side, I have layout(yaxis(anchor = "free")) set am using position to place the axis.

image

All my attempts to set anchor = "free" in subplots left my plot space completely blank. Some testing revealed that even a subplot constructed from a single plot will not display if anchor="free"

Please see below REPREX.

require(plotly)
df <- data.frame(x = 1:10, y = 1:10, y2 = 10:19)
plt <- plot_ly(data = df) %>%
  add_trace(x = ~x, y = ~y,
            mode = "markers", type = "scatter",
            yaxis = "y") %>%
  add_trace(x = ~x, y = ~y2,
            mode = "markers", type = "scatter",
            yaxis = "y2") %>%
  layout(
    xaxis = list(
      domain = c(.12, .88)
    ),
    yaxis = list(
      title = "y_1"
    ),
    yaxis2 = list(
      title = "y_2",
      anchor = "free",
      position = .10,
      overlaying = "y"
    ),
    margin = list(
      pad = 60
    )
  )
subplot(plt)

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

Start by running the supplied R reprex with plot_ly(), layout(), and subplot() to confirm that anchor = "free" produces a blank plot. Then trace how subplot() handles the yaxis and yaxis2 settings, especially anchor, position, and overlaying. Done means the subplot renders its traces while preserving the free-positioned axis.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.