将多个chorddiag/htmlwidget图合并为R中的单个图

发布于 2025-01-14 23:55:22 字数 745 浏览 5 评论 0原文

我正在 R 中生成几个 chorddiag 图,并希望将它们组合在一起形成一个图。下面是 3 个 chorddiag 图的示例列表:

library(chorddiag)
m <- matrix(c(11975,  5871, 8916, 2868,
              1951, 10048, 2060, 6171,
              8010, 16145, 8090, 8045,
              1013,   990,  940, 6907),
            byrow = TRUE,
            nrow = 4, ncol = 4)
haircolors <- c("black", "blonde", "brown", "red")
dimnames(m) <- list(haircolors,haircolors)
groupColors <- c("#000000", "#FFDD89", "#957244", "#F26223")
ll <- lapply(1:3,function(i) chorddiag(m, groupColors = groupColors, groupnamePadding = 20))

如果这些是plotly 对象,我会使用plotly 的subplot 函数。对于以下情况是否有等效的内容:

> class(ll[[1]])
[1] "chorddiag"  "htmlwidget"

I'm generating several chorddiag plots in R and would like to combine them together to a single plot. Here's an example list of 3 chorddiag plots:

library(chorddiag)
m <- matrix(c(11975,  5871, 8916, 2868,
              1951, 10048, 2060, 6171,
              8010, 16145, 8090, 8045,
              1013,   990,  940, 6907),
            byrow = TRUE,
            nrow = 4, ncol = 4)
haircolors <- c("black", "blonde", "brown", "red")
dimnames(m) <- list(haircolors,haircolors)
groupColors <- c("#000000", "#FFDD89", "#957244", "#F26223")
ll <- lapply(1:3,function(i) chorddiag(m, groupColors = groupColors, groupnamePadding = 20))

If these were plotly object I'd use plotly's subplot function. Is there anything equivalent for case of:

> class(ll[[1]])
[1] "chorddiag"  "htmlwidget"

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

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

发布评论

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

评论(1

挖鼻大婶 2025-01-21 23:55:22

我还没有尝试过chorddiag包(我不认为它在CRAN上,也许是其他一些存储库?),但是manipulateWidget包可能就是你想要的。 example(combineWidgets) 具有以下代码:

data(iris)
library(manipulateWidget); library(plotly)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
combineWidgets(title = "The Iris dataset",
               plot_ly(iris, x = ~Sepal.Length, type = "histogram", nbinsx = 20),
               plot_ly(iris, x = ~Sepal.Width, type = "histogram", nbinsx = 20),
               plot_ly(iris, x = ~Petal.Length, type = "histogram", nbinsx = 20),
               plot_ly(iris, x = ~Petal.Width, type = "histogram", nbinsx = 20)
)

创建于 2022-03-24 reprex 包 (v2.0.1)

编辑为添加:

好的,我在 Github 上找到了 chorddiaghttps://github.com/马特弗洛/chorddiag/ 。运行代码后,这三个图表结合在一起:

manipulateWidgets::combineWidgets(shiny::tagList(ll))

它们不能很好地调整大小;我怀疑这是因为 chorddiag 想要全屏显示,但也许这是 manipulateWidgets 中的问题。您可能需要修补其中之一。

I haven't tried the chorddiag package (I don't think it's on CRAN, maybe some other repos?), but the manipulateWidget package may be what you want. example(combineWidgets) has this code:

data(iris)
library(manipulateWidget); library(plotly)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
combineWidgets(title = "The Iris dataset",
               plot_ly(iris, x = ~Sepal.Length, type = "histogram", nbinsx = 20),
               plot_ly(iris, x = ~Sepal.Width, type = "histogram", nbinsx = 20),
               plot_ly(iris, x = ~Petal.Length, type = "histogram", nbinsx = 20),
               plot_ly(iris, x = ~Petal.Width, type = "histogram", nbinsx = 20)
)

Created on 2022-03-24 by the reprex package (v2.0.1)

EDITED to add:

Okay, I found chorddiag on Github: https://github.com/mattflor/chorddiag/ . After running your code, this combines the three diagrams:

manipulateWidgets::combineWidgets(shiny::tagList(ll))

They don't resize nicely; I suspect that's because chorddiag wants to be fullscreen, but maybe it's a problem in manipulateWidgets. You'll probably have to patch one or the other.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文