You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Setting anchor = "free" in R subplot() causes the graph to disappear #1768
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.
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"
I think this is a plotly.js bug...that R code generates this fatal JS error:
UncaughtTypeError: t.matchisnotafunctionatr.cleanId(plotly-latest.min.js:61)atObject.r.cleanLayout(plotly-latest.min.js:61)atObject.r.plot(plotly-latest.min.js:61)atObject.renderValue(plotly.js:162)athtmlwidgets.js:653atArray.forEach(<anonymous>)
at forEach (htmlwidgets.js:55)
at htmlwidgets.js:576
at Array.forEach (<anonymous>)
at forEach (htmlwidgets.js:55)
@cpsievert, I don't have experience with plotly outside of R, do you know if this is reproducible in a non-R context? (I understand your point that the error is coming from plotly and not R.) In your experience, is plotly (the organization) responsive to bugs like that?
I just filed an issue here plotly/plotly.js#4844. Please follow that thread for updates (then, if and when it gets fixed in plotly.js, you can poke me about updating plotly.js in the R package :) )
Oh actually, this is not a plotly.js problem. And now that I look closer, why do you need subplot(plt) instead of plt?
For this particular example I don't, I was just trying to provide a minimal set of code that didn't function. My use case that uncovered this issue was trying to create a subplot of two "stacked" plots using subplot()
Try 1.
This approach works, but the axis are overlapped.
require(plotly)
df <- data.frame(x = 1:10, y = 1:10, y2 = (10:19)^2)
plt1 <- 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(
side = "left",
title = "y_1"
),
yaxis2 = list(
side = "left",
title = "y_2",
## anchor = "free",
## position = .10,
overlaying = "y"
),
margin = list(
pad = 60
)
)
plt2 <- 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(
side = "left",
title = "y_1"
),
yaxis2 = list(
side = "left",
title = "y_2",
## anchor = "free",
## position = .10,
overlaying = "y3"
),
margin = list(
pad = 60
)
)
subplot(plt1, plt2, nrows = 2)
##Try 2
When you un-comment out the anchor = "free" argument the entire plot disappears, regardless of where position is set.
Require(plotly)
df <- data.frame(x = 1:10, y = 1:10, y2 = (10:19)^2)
plt1 <- 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(
side = "left",
title = "y_1"
),
yaxis2 = list(
side = "left",
title = "y_2",
anchor = "free",
position = .10,
overlaying = "y"
),
margin = list(
pad = 60
)
)
plt2 <- 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(
side = "left",
title = "y_1"
),
yaxis2 = list(
side = "left",
title = "y_2",
anchor = "free",
position = .10,
overlaying = "y3"
),
margin = list(
pad = 60
)
)
subplot(plt1, plt2, nrows = 2)
In my testing I found that even if only a single plot obj was added to the subplot() function, the plot would be blank, which is why I constructed the REPREX in the above manner.
Not quite related, but I find it confusing from a plot construction perspective that the overlaying argument on the second plot is indexed at a "global" level, that is, it must be set to overlaying = "y3" instead of overlaying = "y" to appear in the right place.
Not sure if that's a design feature, or unintended consequence of subplot()
Activity
cpsievert commentedon May 19, 2020
I think this is a plotly.js bug...that R code generates this fatal JS error:
r2evans commentedon May 19, 2020
@cpsievert, I don't have experience with plotly outside of R, do you know if this is reproducible in a non-R context? (I understand your point that the error is coming from plotly and not R.) In your experience, is plotly (the organization) responsive to bugs like that?
cpsievert commentedon May 19, 2020
I just filed an issue here plotly/plotly.js#4844. Please follow that thread for updates (then, if and when it gets fixed in plotly.js, you can poke me about updating plotly.js in the R package :) )
cpsievert commentedon May 19, 2020
Oh actually, this is not a plotly.js problem. And now that I look closer, why do you need
subplot(plt)instead ofplt?duncanrellis commentedon May 20, 2020
For this particular example I don't, I was just trying to provide a minimal set of code that didn't function. My use case that uncovered this issue was trying to create a subplot of two "stacked" plots using
subplot()Try 1.
##Try 2
anchor = "free"argument the entire plot disappears, regardless of wherepositionis set.In my testing I found that even if only a single plot obj was added to the
subplot()function, the plot would be blank, which is why I constructed the REPREX in the above manner.Hope that's clear.
duncanrellis commentedon May 20, 2020
overlayingargument on the second plot is indexed at a "global" level, that is, it must be set tooverlaying = "y3"instead ofoverlaying = "y"to appear in the right place.Not sure if that's a design feature, or unintended consequence of
subplot()