R Plotly:使用表格创建子图

4
我无法弄清如何在R和Plotly中正确地制作一个表格子图。
以下是我所说的内容。我有两个图,一个是散点图,一个是表格。使用subplot函数,表格图不会按预期工作。
我的散点图要么失去了互动性,要么出现了重叠的散点图/表格图。请告诉我是否遗漏了什么或者这是一个错误。
我正在使用plotly版本4.9.0
提前致谢!
library(plotly)

df <- data.frame(x = 1:10,
                 y = 1:10)

p1 <- 
  plot_ly(data = df,
          type = "scatter",
          mode = "line",
          x = ~x,
          y = ~y) %>%
  layout(xaxis = list(fixedrange=T),
         yaxis = list(fixedrange=T)) %>%
  config(displayModeBar = F)

p2 <-
  plot_ly(
    type = 'table',
    header = list(values = c("x", "y")),
    cells = list(values = rbind(df$x, df$y))
  )


subplot(p1, p2, nrows = 2) # overlapping plots

subplot(p2, p1, nrows = 2) # loses interactivity on p2

subplot(p1, p1, nrows = 2) # works as expected
1个回答

4

我刚刚在Plotly的文档中看到:

在Plotly中,没有原生的方法将Plotly表格插入到子图中。

https://plot.ly/python/table-subplots/

但是似乎我们可以创建自己的布局。对于表格,我添加了“domain”以将其定位于左侧:

p2 <-
  plot_ly(
    type = 'table',
    domain = list(x=c(0,0.5), y=c(0,1)),
    header = list(values = c("x", "y")),
    cells = list(values = rbind(df$x, df$y))
  )

然后在左侧表格和右侧散点图上添加了'layout':

subplot(p1, p2, nrows = 2) %>%
  layout(xaxis = list(domain=c(0.5,1.0)),
         xaxis2 = list(domain=c(0,0.5)))

你知道如何在这个解决方案中向plot_ly()添加frame参数吗?如果frame是时间,我需要图表和表格根据时间更新。它对于图表有效,但即使我添加了frame参数,表格仍然显示整个表格。所以我想表格类型可能没有这个参数。你有什么想法吗? - MaMo
抱歉,我不知道 - 也许你想单独发布一个问题? - Ben
我一个月前尝试过,但不幸的是,我找不到任何人来帮助我。 - MaMo
1
尝试使用manipulateWidget::combineWidgets(list = list(p1, p2))来在图表下方获取表格。 - undefined

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