代码之家  ›  专栏  ›  技术社区  ›  dan

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

  •  0
  • dan  · 技术社区  · 3 年前

    我正在生成几个 chorddiag 图中的R,并希望将它们组合成一个单独的图。以下是3个示例列表 弦线图 绘图:

    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"
    
    0 回复  |  直到 3 年前
        1
  •  1
  •   user2554330    3 年前

    我还没试过 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 package (v2.0.1)

    编辑以添加:

    好吧,我找到了 弦线图 在Github上: https://github.com/mattflor/chorddiag/ 。运行完代码后,这将结合三个图表:

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

    它们不能很好地调整大小;我怀疑那是因为 弦线图 想成为全屏显示,但可能在 manipulateWidgets 。你可能需要修补其中一个。

    推荐文章