我正在尝试在Flexdashboard的单个选项卡上放置多个笔画图。我尝试了here和here
的许多不同选项我的RMD文件如下:
---
title: "Project Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: scroll
---
# Intro {.sidebar}
# Page 1
## Column 1 {.tabset .tabset-fade data-width=850}
### Site 1
```{r Data, echo=FALSE, fig.height=2}
s <- dygraph(as.xts(df,order.by=df$DateTime), group = "NC") %>%
dyOptions(drawPoints = TRUE, pointSize = 1) %>%
dyAxis("y", label = "Salinity (PSU)", valueRange = c(16, 30)) %>%
dyRangeSelector(height = 20) %>%
dyLegend(width = 400)
t <- dygraph(as.xts(df,order.by=df$DateTime), group = "NC") %>%
dyOptions(drawPoints = TRUE, pointSize = 1) %>%
dyAxis("y", label = "Temperature (°C)", valueRange = c(0, 30)) %>%
dyRangeSelector(height = 20) %>%
dyLegend(show = "follow", width = 400)
dy_graph <- list(s,t)
pt <- htmltools::browsable(htmltools::tagList(dy_graph))
pt
```
我已经尝试了多种其他组合,但是它要么只是绘制第一个图,要么将两个图重叠在一起,要么将它们挤压到一个很小的空间中。我什至尝试使用4级降价标头(####),但这似乎也不起作用。
有什么想法吗?
答案 0 :(得分:0)
不确定如何在dygraph程序包中执行此操作,但是如果您转换为ggplot,则可以使用gridExtra程序包中的grid.arrange将多个图放置在一个“页面”中。
请参见包含以下示例的https://cran.r-project.org/web/packages/egg/vignettes/Ecosystem.html
:
require(ggplot)
require(gridExtra)
p1 <- qplot(mpg, wt, data = mtcars, colour = cyl)
p2 <- qplot(mpg, data = mtcars) + ggtitle("title")
grid.arrange(p1, p2, nrow = 1)
答案 1 :(得分:0)
请不要错过section '13.2.3 CSS flexbox' here(在密谋范围内有效)。
library(htmltools)
p <- plot_ly(x = rnorm(100))
# NOTE: you don't need browsable() in rmarkdown,
# but you do at the R prompt
browsable(div(
style = "display: flex; flex-wrap: wrap; justify-content: center",
div(p, style = "width: 40%; border: solid;"),
div(p, style = "width: 40%; border: solid;"),
div(p, style = "width: 100%; border: solid;")
))
答案 2 :(得分:0)
在这里,您可以使用splitLayout
在选项卡集中放置多个图形。我还没有弄清楚如何堆叠,就像2x2的数字一样。
---
title: "Project Dashboard"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: scroll
---
Page with Tabset {.tabset .tabset-fade}
-------------------------------------
### Two Plots on one Tab
```{r}
library(shiny)
library(flexdashboard)
library(dygraphs)
temperature <- ts(frequency = 12, start = c(1980, 1),
data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5,
25.2, 26.5, 23.3, 18.3, 13.9, 9.6))
rainfall <- ts(frequency = 12, start = c(1980, 1),
data = c(49.9, 71.5, 106.4, 129.2, 144.0, 176.0,
135.6, 148.5, 216.4, 194.1, 95.6, 54.4))
output$p1 <- renderDygraph( dygraph(temperature))
output$p2 <- renderDygraph( dygraph(rainfall))
```
```{r}
splitLayout(cellWidths = c("50%"), dygraphOutput("p1"), dygraphOutput("p2"))
```
### Another Tab
Hello
生产中...