Skip to content

Plotly drops secondary axis series when subplot() is called #1113

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

Closed
ErhardMenker opened this issue Sep 7, 2017 · 1 comment
Closed

Plotly drops secondary axis series when subplot() is called #1113

ErhardMenker opened this issue Sep 7, 2017 · 1 comment

Comments

@ErhardMenker
Copy link


It looks like Plotly can execute the plot_ly() command properly when there is a secondary axis, but it drops them when multiple plots are stacked together via the subplot() command. See the example below where var2 is represented properly in graph p1 on a secondary axis, but gets dropped when subplot() is called to stack that with another graph p2:

library(plotly)

set.seed(11)

# initialize a 5-record data.table with 4 random normal series
df <- data.frame(date = c("1980", "1981", "1982", "1983", "1984"),
                 var1 = rnorm(5), var2 = 10 * rnorm(5), var3 = rnorm(5), 
                 var4 = 10 * rnorm(5))

# plot var1 & var2 on the same plot, different axes
p1 <- plot_ly(df, type = 'scatter', mode = 'lines') %>%
        add_trace(x = ~date, y = ~var1, name = "var1") %>%
        add_trace(x = ~date, y = ~var2, name = "var2", yaxis = "y2") %>%
        layout(yaxis2 = list(side = "right", overlaying = "y", zeroline = FALSE))
p1

# plot var3 & var4 on the same plot, same axis
p2 <- plot_ly(df, type = 'scatter', mode = 'lines') %>%
        add_trace(x = ~date, y = ~var3, name = "var3") %>%
        add_trace(x = ~date, y = ~var4, name = "var4") 
p2

# stack plots p1 & p2
plots <- subplot(p1, p2, nrows = 2, shareY = F, shareX = F)
plots
@cpsievert
Copy link
Collaborator

Duplicate of #1203

@cpsievert cpsievert marked this as a duplicate of #1203 Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants