在闪亮的图中添加动态数量的轨迹
有人要求将动态数量的跟踪数添加到plot_ly绘图中。这是基于最近的问题已被删除。我希望下面的答案可以帮助其他正在寻找类似情况的答案的人。
Someone requested to add dynamic number of traces to a plot_ly plot. This is based on a recent question that has been deleted. I hope the answer below helps someone else who is looking for an answer with a similar situation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如上所述,这是我早期答案在这里的重复。
但是, @ybs的方法过于复杂,我想提供直接比较的可能性。使用
data.frame
以ggplot
或plotly
是首选的方法(使用egdata.table ::融化
从宽到长)。这样,我们可以使用plot_ly
'ssplit
,name
或color
参数参数以基于数据创建多个跟踪:As mentioned above this is a duplicate of my earlier answer here.
However, @YBS' approach is overly complex and I'd like to provide the possibility for a direct comparison. Using a
data.frame
in long format forggplot
orplotly
is the preferred way to go (Use e.g.data.table::melt
to convert from wide to long). This way we can useplot_ly
'ssplit
,name
orcolor
parameter to create multiple traces based on the data:一种方法是通过
selectInput
选择所有可以包含在时间序列中的变量。然后绘制旁边有复选标记的那些。完整代码。One way to do it is to select all the variables that could be included in the time series via
selectInput
. Then plot the ones that have a check mark next to them. Full code.