rplottime-seriesdygraphs

Arrange Multiple `dygraphs::dygraph()` Plots in Multiple Columns in a Figure in R


I know I can make a figure with 6 dygraph::dygraphs() plots arranged in 6 rows and one column.

library (dygraphs)
library (htmltools)
mdeaths <- structure(c(2134, 1863, 1877, 1877, 1492, 1249, 1280, 1131, 1209, 1492, 1621, 1846, 2103, 2137, 2153, 1833, 1403, 1288, 1186, 1133, 1053, 1347, 1545, 2066, 2020, 2750, 2283, 1479, 1189, 1160, 1113, 970, 999, 1208, 1467, 2059, 2240, 1634, 1722, 1801, 1246, 1162, 1087, 1013, 959, 1179, 1229, 1655, 2019, 2284, 1942, 1423, 1340, 1187, 1098, 1004, 970, 1140, 1110, 1812, 2263, 1820, 1846, 1531, 1215, 1075, 1056, 975, 940, 1081, 1294, 1341), tsp = c(1974, 1979.91666666667, 12), class = "ts")
Plot_List <- lapply(1:6, function (x) {
  dygraphs::dygraph(mdeaths)
})
htmltools::browsable(htmltools::tagList(Plot_List))

How can I arrange these plots in 1 column with 6 rows? How can I arrange them in 2 columns with 3 rows?


Solution

  • With manipulateWidget::combineWidgets:

    library(dygraphs)
    
    lungDeaths <- cbind(mdeaths, fdeaths)
    
    Plot_List <- lapply(1:6, function (x) {
      dygraphs::dygraph(lungDeaths)
    })
    
    library(manipulateWidget)
    combineWidgets(
      list = Plot_List,
      nrow = 3, ncol = 2
    )