FlexDashboard - ggplot 宽度以填充单元格宽度
FlexDashboard - ggplot width to fill cell width
有没有办法让 ggplot 在不指定 fig.width 的情况下填充 flexdashboard 单元格内的宽度,以便响应?
在下面的示例中,我希望每个单元格中的单个图表从左到右填充,因此顶行的图表会更宽,下面的两个图表会更宽一些。
---
title: "Test Flex Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: rows
---
```{r include=FALSE}
pacman::p_load(tidyverse)
```
Raw Data
=====================================
Row
-------------------------------------
### **Upper Row**
```{r}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```
Row
---------------------------
### **Lower Row, Col 1**
```{r}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```
### **Lower Row, Col 2**
```{r}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```
这可以通过内联 CSS 来完成!我知道你说没有 fig.width
设置,但我给了 fig.width
默认值 20(对于我的屏幕分辨率),让它填充顶栏,但使用下面的内联 CSS 代码...
```{css, echo=FALSE}
.fluid-row {
font-size: 5.9vw;
}
```
这使流体排具有响应效果。所以这是我渲染的 flexdashboard 的全屏。
然后我将桌面上的 window 拖到较小的 window
下面是你的代码和我的解决方案,如果你有问题请告诉我。谢谢
---
title: "Test Flex Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: rows
---
```{css, echo=FALSE}
.fluid-row {
font-size: 5.9vw;
}
```
```{r include=FALSE}
pacman::p_load(tidyverse)
```
Raw Data
=====================================
Row
-------------------------------------
### **Upper Row**
```{r, fig.width=20}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```
Row
---------------------------
### **Lower Row, Col 1**
```{r}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```
### **Lower Row, Col 2**
```{r}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```
有没有办法让 ggplot 在不指定 fig.width 的情况下填充 flexdashboard 单元格内的宽度,以便响应?
在下面的示例中,我希望每个单元格中的单个图表从左到右填充,因此顶行的图表会更宽,下面的两个图表会更宽一些。
---
title: "Test Flex Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: rows
---
```{r include=FALSE}
pacman::p_load(tidyverse)
```
Raw Data
=====================================
Row
-------------------------------------
### **Upper Row**
```{r}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```
Row
---------------------------
### **Lower Row, Col 1**
```{r}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```
### **Lower Row, Col 2**
```{r}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```
这可以通过内联 CSS 来完成!我知道你说没有 fig.width
设置,但我给了 fig.width
默认值 20(对于我的屏幕分辨率),让它填充顶栏,但使用下面的内联 CSS 代码...
```{css, echo=FALSE}
.fluid-row {
font-size: 5.9vw;
}
```
这使流体排具有响应效果。所以这是我渲染的 flexdashboard 的全屏。
然后我将桌面上的 window 拖到较小的 window
下面是你的代码和我的解决方案,如果你有问题请告诉我。谢谢
---
title: "Test Flex Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: rows
---
```{css, echo=FALSE}
.fluid-row {
font-size: 5.9vw;
}
```
```{r include=FALSE}
pacman::p_load(tidyverse)
```
Raw Data
=====================================
Row
-------------------------------------
### **Upper Row**
```{r, fig.width=20}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```
Row
---------------------------
### **Lower Row, Col 1**
```{r}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```
### **Lower Row, Col 2**
```{r}
ggplot(mtcars, aes(x = row.names(mtcars), y = mpg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5)) +
ggtitle("MT Cars")
```