我想要两个并排的图共享相同的 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
先感谢您!
我们可以用matches
在 R 中就像在 python 中一样。
Run schema()
并导航:
对象 ► 布局 ► layoutAttributes ► xaxis ► 匹配
了解更多信息。
这使所有 (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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)