'Combine several chorddiag/htmlwidget plots to a single plot in R
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"
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
