【问题标题】:RMarkdown flexdashboard vertical_scroll is not working with facet_wrapRMarkdown flexdashboard vertical_scroll 不适用于 facet_wrap
【发布时间】:2019-09-12 06:03:56
【问题描述】:

我希望 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
```

【问题讨论】:

    标签: r ggplot2 r-markdown facet-wrap flexdashboard


    【解决方案1】:

    您可以尝试使用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
    ```
    

    【讨论】:

      猜你喜欢
      • 2020-09-12
      • 2016-10-06
      • 2018-04-30
      • 2017-10-27
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-21
      相关资源
      最近更新 更多