gpt4 book ai didi

R plotly : subplot with table

转载 作者:行者123 更新时间:2023-12-04 14:19:52 27 4
gpt4 key购买 nike

我不知道如何使用 R 和 Plotly 使表格子图正常工作。

下面演示了我的意思。我有两张图,一张散点图和一张 table 。使用 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

最佳答案

我刚刚阅读了 Plotly 的文档:

In Plotly there is no native way to insert a Plotly Table into a Subplot.



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

关于R plotly : subplot with table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56267164/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com