Plotly: 并排图之间的共享X轴

3
我想要两个并排的图表共享相同的X轴和工具栏。这意味着,通过在第一个图表中缩放,第二个图表应自动调整为相同的缩放区域。
一种方法是将图表堆叠在一起,使用“shareX=TRUE”,但我需要它们并排放置。
在Python中,似乎有一种方法可以做到这一点,使用“fig.update_xaxes(matches='x')”。R中是否有类似的选项?
以下是示例代码:
library(plotly) 

n = 10
x = 1:n
y = rnorm(n)

fig1 <- plot_ly(x = x, y = y, type = 'scatter', mode = 'lines+markers') 
fig2 <- plot_ly(x = x, y = y, type = 'scatter', mode = 'lines+markers') 
fig  <- subplot(fig1, fig2, shareX = TRUE) # shareX actually not working here
fig

Thank you in advance!

1个回答

2
我们可以像在Python中一样,在R中使用matches。运行schema()并导航至:

object ► layout ► layoutAttributes ► xaxis ► matches

以获取更多信息。这将保持所有(x&y)轴同步。
library(plotly) 

n = 10
x = 1:n
y = rnorm(n)

fig1 <- plot_ly(x = x, y = y, type = 'scatter', mode = 'lines+markers') 
fig2 <- plot_ly(x = x, y = y, type = 'scatter', mode = 'lines+markers', xaxis = "x") %>% layout(xaxis = list(matches = "x"))
fig  <- subplot(fig1, fig2, shareX = TRUE, shareY = TRUE)
fig

result


对于未来的读者:在这里你可以找到一个相关的帖子。 - ismirsehregal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接