首页 > 解决方案 > RMarkdown flexdashboard vertical_scroll 不适用于 facet_wrap

问题描述

我希望 flex 仪表板占据全屏(全宽、全高)并滚动以适应刻面环绕中的大量图。使用下面提供的 nycflights13 使我的问题可重现,并产生不可读的超级垂直压缩图。如何在 flex 仪表板中实现这一点?

下面的针织输出:https ://imgur.com/a/LyfZTw3

---
title: "facet test"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: scroll
---

```{r setup, include=FALSE}
library(flexdashboard)
library(nycflights13)
library(tidyr)
library(dplyr)
library(ggplot2)
```

Column
-----------------------------------------------------------------------

### Chart A

```{r dfs and plots, include=FALSE, warning=FALSE, cache=FALSE}

df <- flights %>%
  group_by(dest, time_hour) %>%
  summarise(n = n()) %>%
  ungroup()

sp <- ggplot(df, aes(x=time_hour, y=n)) + geom_line()

fr <- sp + facet_wrap(~ dest)
```

```{r  facet, out.width = '100%', warning=FALSE, echo=FALSE, message=FALSE, error=TRUE}
fr
```

标签: rggplot2r-markdownfacet-wrapflexdashboard

解决方案


您可以尝试使用fig.heightfig.width选项。这为我提供了一个相当合理的输出:

---
title: "facet test"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: scroll
---

```{r setup, include=FALSE}
library(flexdashboard)
library(nycflights13)
library(tidyr)
library(dplyr)
library(ggplot2)
```

Column
-----------------------------------------------------------------------

### Chart A

```{r dfs and plots, include=FALSE, warning=FALSE, cache=FALSE}

df <- flights %>%
  group_by(dest, time_hour) %>%
  summarise(n = n()) %>%
  ungroup()

sp <- ggplot(df, aes(x=time_hour, y=n)) + geom_line() 

fr <- 
  sp + 
  facet_wrap(~ dest) +
  theme(strip.text.x = element_text(size = 8))
```

```{r facet, echo=FALSE, error=TRUE, fig.height=20, fig.width=16, message=FALSE, warning=FALSE}
fr
```

推荐阅读