在软件包`crosstalk'中,是否有函数`bsrows()`and'和'rows+ cols'混合了吗?

发布于 2025-01-25 07:59:16 字数 637 浏览 5 评论 0原文

在软件包crosstalk中,有函数bscols()使绘图连续对齐。但是我找不到函数bsrows()行+cols混合,任何软件包都有这样的函数吗?谢谢!

library(plotly)
library(tidyr)
library(crosstalk)

m <- gather(mtcars, variable, value, -vs)
msd <- highlight_key(m, ~variable)
gg <- ggplot(msd, aes(factor(vs), value)) + 
  geom_jitter(alpha = 0.3)

bscols(
  widths = c(11, 6, 6),
  filter_select("id", "Select a variable", msd, ~variable, multiple = FALSE),
  ggplotly(gg, dynamicTicks = "y") %>% layout(margin = list(l = 30)),
  plot_ly(msd, x = ~jitter(vs), y = ~value) %>% add_markers(alpha = 0.3)
)

In package crosstalk, there is function bscols() make plots align in a row. But I cant't find function bsrows() and rows+cols mixed , is any package have such function? Thanks!

library(plotly)
library(tidyr)
library(crosstalk)

m <- gather(mtcars, variable, value, -vs)
msd <- highlight_key(m, ~variable)
gg <- ggplot(msd, aes(factor(vs), value)) + 
  geom_jitter(alpha = 0.3)

bscols(
  widths = c(11, 6, 6),
  filter_select("id", "Select a variable", msd, ~variable, multiple = FALSE),
  ggplotly(gg, dynamicTicks = "y") %>% layout(margin = list(l = 30)),
  plot_ly(msd, x = ~jitter(vs), y = ~value) %>% add_markers(alpha = 0.3)
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不是你的备胎 2025-02-01 07:59:16

我一直在寻找同一件事,直到意识到12是crosstalk :: bscols()中的最大列数。这意味着您可以通过为上一个指定widths = 12将每个小部件都放在下一行上。通过调整宽度,您可以调整两个列以及介绍新行时。这可能不是您所希望的界面,但可以使用。这是一个示例,您的宽度在单独的行上(我添加了htmltools以使用断裂):

library(plotly)
library(tidyr)
library(crosstalk)
library(htmltools)

m <- gather(mtcars, variable, value, -vs)
msd <- highlight_key(m, ~variable)
gg <- ggplot(msd, aes(factor(vs), value)) + 
  geom_jitter(alpha = 0.3)

suppressWarnings({
  bscols(
    widths = c(12, 12, 12),
    filter_select("id", "Select a variable", msd, ~variable, multiple = FALSE),
    htmltools::br(),
    ggplotly(gg, dynamicTicks = "y") %>% layout(margin = list(l = 30)),
    htmltools::br(),
    plot_ly(msd, x = ~jitter(vs), y = ~value) %>% add_markers(alpha = 0.3)
  )
})

I was searching for the same thing until realizing that 12 is the maximum number of columns in crosstalk::bscols(). This means that you can put every widget on next row just by specifying widths = 12 for the previous one. By adjusting widths you can adjust both columns and when new rows are introduces. It is probably not the interface you were hoping for but it works. Here is an example with your widgests on separate rows (I added htmltools to use breaks):

library(plotly)
library(tidyr)
library(crosstalk)
library(htmltools)

m <- gather(mtcars, variable, value, -vs)
msd <- highlight_key(m, ~variable)
gg <- ggplot(msd, aes(factor(vs), value)) + 
  geom_jitter(alpha = 0.3)

suppressWarnings({
  bscols(
    widths = c(12, 12, 12),
    filter_select("id", "Select a variable", msd, ~variable, multiple = FALSE),
    htmltools::br(),
    ggplotly(gg, dynamicTicks = "y") %>% layout(margin = list(l = 30)),
    htmltools::br(),
    plot_ly(msd, x = ~jitter(vs), y = ~value) %>% add_markers(alpha = 0.3)
  )
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文