r - 在 R-Markdown 中的网格上显示多个 dygraph

标签 r markdown dygraphs r-dygraphs

关注话题 here , 有没有办法在网格中组织输出 dygraphs?将一个或多个图表排成一行。

下面的代码将生成 4 个垂直排列的 dygraph。
有没有办法在 4x4 网格中组织它们?

我尝试使用 tags$div但它将所有图形包装在一个 div 中。
有没有办法应用 CSS 属性,例如 display: inline-block;到每个 dygraph 小部件?或任何其他更好的方法?

```{r}
library(dygraphs)
library(htmltools)


makeGraphs = function(i){
  dygraph(lungDeaths[, i], width = 300, height = 300, group = "lung-deaths")%>%
    dyOptions(strokeWidth = 3) %>%
    dyRangeSelector(height = 20)
}


lungDeaths <- cbind(mdeaths, fdeaths, ldeaths, mdeaths)
res <- lapply(1:4, makeGraphs )
htmltools::tagList(tags$div(res, style = "width: 620px; padding: 1em; border: solid; background-color:#e9e9e9"))
```

当前输出截图:

enter image description here

最佳答案

我想我想通了,不确定它是最好的解决方案,但是添加了一个带有 display:inline-block; 的包装器 div。属性(property)似乎运作得很好。

我刚刚将此行添加到生成每个 dygraph 的函数中:

htmltools::tags$div(theGraph, style = "padding:10px; width: 250px; border: solid; background-color:#e9e9e9; display:inline-block;")

所以更新后的代码如下所示:
```{r graphs}
library(dygraphs)
library(htmltools)


makeGraphs = function(i){
  theGraph <- dygraph(lungDeaths[, i], width = 400, height = 300, group = "lung-deaths")%>%
    dyOptions(strokeWidth = 3) %>%
    dyRangeSelector(height = 20)

  htmltools::tags$div(theGraph, style = "padding:10px; width: 450px; border: solid; background-color:#e9e9e9; display:inline-block;")

}



lungDeaths <- cbind(mdeaths, fdeaths, ldeaths, mdeaths)
res <- lapply(1:4, makeGraphs )
htmltools::tagList(res) 

```

输出截图:
enter image description here

关于r - 在 R-Markdown 中的网格上显示多个 dygraph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51007551/

相关文章:

r - 在同一图表R上绘制两个图,ggplot2 par(mfrow())

markdown - 除了 derobins 之外,还有更新版本的 WMD Markdown 吗?

javascript - 删除 Dygraphs 右侧的空白

javascript - 在 javascript 中的 php-Statement 上使用 php 进行循环

r - 在R中仅删除数据帧中的相邻重复项

r - Knit 不渲染 googleVis

javascript - 如何从 React 组件渲染 Markdown?

使用 ctags 的 Vim Markdown 导航 : using 'tagbar' + 'markdown2ctags' with 'vim-pandoc'

javascript - dyGraphs 将变量用作 'y2' 时不显示第二个 Y 轴

r - 按一列分组并折叠所有其他列而无需 NA