【发布时间】:2020-03-01 23:16:29
【问题描述】:
我想用一个滑块来控制用 plotly 创建的多个子图。我在 Python 中找到了类似以下两个的答案:
- Plot.ly. Using slider control with multiple plots
- https://community.plot.ly/t/using-one-slider-to-control-multiple-subplots-not-multiple-traces/13955/4
示例(第二个链接):
import plotly.graph_objs as go
from plotly.tools import make_subplots
fig = make_subplots(1, 2)
fig.add_scatter(y=[1, 3, 2], row=1, col=1, visible=True)
fig.add_scatter(y=[3, 1, 1.5], row=1, col=1, visible='legendonly')
fig.add_scatter(y=[2, 2, 1], row=1, col=1, visible='legendonly')
fig.add_scatter(y=[1, 3, 2], row=1, col=2, visible=True)
fig.add_scatter(y=[1.5, 2, 2.5], row=1, col=2, visible='legendonly')
fig.add_scatter(y=[2.5, 1.2, 2.9], row=1, col=2, visible='legendonly')
steps = []
for i in range(3):
step = dict(
method = 'restyle',
args = ['visible', ['legendonly'] * len(fig.data)],
)
step['args'][1][i] = True
step['args'][1][i+3] = True
steps.append(step)
sliders = [dict(
steps = steps,
)]
fig.layout.sliders = sliders
go.FigureWidget(fig)
但是我如何在 R 中实现这一点?
【问题讨论】:
标签: r slider plotly subplot r-plotly