[英]R Plotly: subplot with table
我不知道如何使用 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
我剛剛閱讀了 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)))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.