【问题标题】:R Plotly: subplot with tableR Plotly:带表格的子图
【发布时间】:2019-10-09 13:15:44
【问题描述】:

我不知道如何使用 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

【问题讨论】:

    标签: r plotly


    【解决方案1】:

    我刚刚阅读了 Plotly 的文档:

    在 Plotly 中,没有本地方法可以将 Plotly 表插入到 子情节。

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

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

    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))
      )
    

    然后为左侧的表格和右侧的散点图添加“布局”:

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

    【讨论】:

    • 你知道如何在这个解决方案中将 frame 参数添加到 plot_ly() 中吗?如果帧是时间,我需要情节和表格来更新时间。它适用于绘图,但即使我添加了 frame 参数,表格也会显示整个表格。所以我想类型表没有它。你有什么想法吗?
    • 很抱歉我没有 - 也许您可能想就此发表一个单独的问题?
    • 一个月前做过,可惜找不到人帮忙
    猜你喜欢
    • 2018-02-02
    • 2017-12-08
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 2020-02-09
    • 1970-01-01
    • 2020-11-23
    • 2023-03-29
    相关资源
    最近更新 更多