作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我使用 flexdashboard 在 .Rmd 文件中绘制多个图时,第二个图比第一个小得多。这是下面 reprex 的屏幕截图。
为什么第二个地 block 比第一个地 block 小得多,我怎样才能使它们大小相同?
我知道 flexdashboard 经常调整项目的大小以适合屏幕,但我不知道这里到底发生了什么。从 2021 年 10 月开始,我在 SO 上发现了完全相同的问题:R Flexdashboard multiple plots sizing , 但无人回答。
这是一个简单的代表。
---
title: "Reprex"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
---
My Tab
=======================================================================
```{r include=TRUE, results="asis", echo=FALSE, fig.height=3, fig.width=5}
library(dplyr)
library(ggplot2)
dat <- tribble(
~item, ~subitem, ~x, ~y,
'foo', 'a', 3.2, 101,
'foo', 'a', 2.2, 94,
'foo', 'a', 1.2, 32,
'foo', 'b', 12.2, 49,
'foo', 'b', 0.2, 83,
'foo', 'b', 7.7, 29,
'bar', 'a', 13.2, 10,
'bar', 'a', 7.0, 8,
'bar', 'a', 0.1, 100,
'bar', 'b', 10.2, 93,
'bar', 'b', 4.0, 74,
'bar', 'b', 10.3, 35
)
items <- unique(dat$item)
for(i in items){
cat("\n")
cat(paste("####", i, "\n"))
cat("\n")
p <- ggplot(filter(dat, item == i), aes(x, y)) +
geom_point() +
facet_wrap(~subitem)
print(p)
cat("\n")
}
cat("\n")
```
最佳答案
根据 flexdashboard docs ,
Dashboards are divided into columns and rows, with output components delineated using level 3 markdown headers (###).
因此,只要我们坚持使用三个井号(即 ###
),flexdashboard 的行为就会一致,
---
title: "Reprex"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
---
```{r include=FALSE}
knitr::opts_chunk$set(fig.height = 3, fig.width = 5)
```
My Tab
=======================================================================
```{r include=TRUE, results="asis", echo=FALSE}
library(dplyr)
library(ggplot2)
dat <- tribble(
~item, ~subitem, ~x, ~y,
'foo', 'a', 3.2, 101,
'foo', 'a', 2.2, 94,
'foo', 'a', 1.2, 32,
'foo', 'b', 12.2, 49,
'foo', 'b', 0.2, 83,
'foo', 'b', 7.7, 29,
'bar', 'a', 13.2, 10,
'bar', 'a', 7.0, 8,
'bar', 'a', 0.1, 100,
'bar', 'b', 10.2, 93,
'bar', 'b', 4.0, 74,
'bar', 'b', 10.3, 35
)
items <- unique(dat$item)
for(i in items){
cat("\n")
cat(paste("###", i, "\n"))
cat("\n")
p <- ggplot(filter(dat, item == i), aes(x, y)) +
geom_point() +
facet_wrap(~subitem)
print(p)
cat("\n")
}
cat("\n")
```
关于r - flexdashboard 第二个图比第一个图小得多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73555205/
我是一名优秀的程序员,十分优秀!