Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subplot() doesn't account for dual axes #1203

Open
TriLe965 opened this issue Feb 23, 2018 · 3 comments
Open

subplot() doesn't account for dual axes #1203

TriLe965 opened this issue Feb 23, 2018 · 3 comments

Comments

@TriLe965
Copy link

I think there is something wrong with the subplot function when there is yaxis2

I tried to use subplot with 2 plots that have yaxis2. Each plot looks like this:
image

foo_plot <- function(n) {
  x <- rnorm(n)
  den <- density(x)
  p <- plot_ly()
  p <- add_trace(p, x=x, type="histogram", name="Histogram",
    marker=list(line=list(color="#000", width=1), color="#555"))
  p <- add_trace(p, x=den$x, y=den$y, yaxis="y2", name="Density",
    type="scatter", mode="lines", line=list(color="#222"))
  p <- layout(p,
    yaxis2=list(overlaying="y", side="right", rangemode="nonnegative",
      showgrid=F, showline=T, ticks="outside"),
    yaxis=list(showline=T, ticks="outside"))
  return(p)
}

p <- subplot(foo_plot(1000), foo_plot(1000), nrows=2, shareX=F, shareY=F)

The density curves were missing when I merge the two plots.
image

This is the result of sessionInfo()
image

@cpsievert cpsievert changed the title Subplot with yaxis2 subplot() doesn't account for dual axes Feb 23, 2018
@PAllen0518
Copy link

try this
#954 (comment)

@romanzenka
Copy link

We got tripped by this bug as well, and I think I found a way to solve the problem.

Internally, subplot translates names of all Y axes in all the subplots to unique names. Unfortunately, the "overlaying" parameter is not getting mapped. That is equivalent to reconfiguring your plots arbitrarily, which causes issues. The workaround of manually guessing the y axis rename and setting "overlaying" parameter to the end result works, but frankly, this is insane and we can do better. I will submit a PR, but I am not familiar with this project that much, so I'll need someone to thoroughly review it.

@romanzenka
Copy link

I reran the original reprex with my bugfix, obtaining this:

Image

I believe that is the desired output (modulo some bad spacing with the legend).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants