✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

3D subplots with set axes

Hi I need help with creating 3D scatterplot subplots with set axis when the subplot axis have the same values. Is that possible? What am I missing? Very grateful for help on this.

#I have created two scatterplots of the exact same data and modified the axis:
fig <- plot_ly(lex_tibble, x = ~B, y = ~C, z = ~A, size=~count,marker=list(sizeref=0.02, sizemode=“area”))
fig <- layout(fig, scene = list(xaxis = list(autick=F,dtick=1, title = “B”, range = c(0,4)), yaxis = list(autick=F,dtick=1,title = “C”, range = c(0,4)), zaxis = list(autick=F,dtick=1,title = “A”)))

fig2 <- plot_ly(lex_tibble, x = ~B, y = ~C, z = ~A, size=~count,marker=list(sizeref=0.02, sizemode=“area”))
fig2 <- layout(fig2, scene = list(xaxis = list(autick=F,dtick=1, title = “B”, range = c(0,4)), yaxis = list(autick=F,dtick=1,title = “C”, range = c(0,4)), zaxis = list(autick=F,dtick=1,title = “A”)))
fig2

##lex_tibble:

A tibble: 7 x 4

Groups: A, B [7]

  A     B     C count


1 1 0 3 6
2 1 3 0 1
3 2 0 2 8
4 2 1 1 3
5 3 0 1 11
6 3 1 0 3
7 4 0 0 6

#Now I want to combine these two plots using subplots, but they overlap

subplot(fig1,fig2) #they overlap
fig3<-subplot(fig1,fig2)%>%
layout(scene = list(domain = list(x = c(0.5, 1), y = c(0,1)))) #shifted, but still overlapping

#If I don’t modify the axes (still the exact same graph), and add the scene=‘scene1/2’ they don’t overlap
fig <- plot_ly(lex_tibble, x = ~B, y = ~C, z = ~A,scene=‘scene1’, size=~count,marker=list(sizeref=0.02, sizemode=“area”))
fig2 <- plot_ly(lex_tibble, x = ~B, y = ~C, z = ~A,scene=‘scene2’, size=~count,marker=list(sizeref=0.02, sizemode=“area”))

subplot(fig,fig2)

#If I add the scene=‘scene1’ argument to the first plot, the plot is the same as without it:
fig1 <- plot_ly(lex_tibble, x = ~B, y = ~C, z = ~A,scene=‘scene1’, size=~count,marker=list(sizeref=0.02, sizemode=“area”))
fig1 <- layout(fig1, scene = list(xaxis = list(autick=F,dtick=1, title = “B”, range = c(0,4)), yaxis = list(autick=F,dtick=1,title = “C”, range = c(0,4)), zaxis = list(autick=F,dtick=1,title = “A”)))

fig1 <- plot_ly(lex_tibble, x = ~B, y = ~C, z = ~A, size=~count,marker=list(sizeref=0.02, sizemode=“area”))
fig1 <- layout(fig1, scene = list(xaxis = list(autick=F,dtick=1, title = “B”, range = c(0,4)), yaxis = list(autick=F,dtick=1,title = “C”, range = c(0,4)), zaxis = list(autick=F,dtick=1,title = “A”)))

#However, I cannot create a second plot with scene=‘scene2’ and still change the axes
fig2 <- plot_ly(lex_tibble, x = ~B, y = ~C, z = ~A,scene=‘scene2’, size=~count,marker=list(sizeref=0.02, sizemode=“area”))
fig2 <- layout(fig2, scene = list(xaxis = list(autick=F,dtick=1, title = “B”, range = c(0,4)), yaxis = list(autick=F,dtick=1,title = “C”, range = c(0,4)), zaxis = list(autick=F,dtick=1,title = “A”))) ##this does not work

#but the two plots with two different axes don’t overlap when I plot them
fig <- subplot(fig1, fig2)
fig <- fig %>% layout(title = “3D Subplots”,
scene = list(domain=list(x=c(0,0.5),y=c(0.5,1)),
xaxis=axx, yaxis=axx, zaxis=axx,
aspectmode=‘cube’),
scene1 = list(domain=list(x=c(0.5,1),y=c(0.5,1)),
xaxis=axx, yaxis=axx, zaxis=axx,
aspectmode=‘cube’))