如何增加 Plot 的高度以在 r 中闪亮的 flexdashboard 中占据全高 space?
How to increase height of Plot to occupy full height space in flexdashboard shiny in r?
我正在使用 tidytuesday UN votes 数据集并尝试通过 nrows
调整 facet plot 以占据 全高 在情节的 flexdashboard 中,但它几乎没有利用一半 space 并使情节不那么明显。
备选方案 是我可以制作 5 个不同的图,但这将 运行 编码 5 次 当它可以完成时一次 facet
.
我也试过 facet_grid
、par(mfrow = c(1,1))
,但都没有用。
代码:
library(flexdashboard)
library(shiny)
library(tidyverse)
library(scales)
library(glue)
library(countrycode)
library(tidytuesdayR)
remotes::install_github("davidsjoberg/ggstream") # for creating streamgraph
数据:
tt <- tt_load("2021-03-23")
unvotes <- tt$unvotes
head(unvotes)
rcid country country_code vote vote_number date amend
<dbl> <chr> <chr> <chr> <dbl> <date> <dbl>
1 3 United States US yes 1 1946-01-01 1
2 3 Canada CA no -1 1946-01-01 1
3 3 Cuba CU yes 1 1946-01-01 1
4 3 Haiti HT yes 1 1946-01-01 1
5 3 Dominican Re~ DO yes 1 1946-01-01 1
6 3 Mexico MX yes 1 1946-01-01 1
flexdashboard
---
title: "UN Country Votes"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
theme: space
runtime: shiny
resource_files:
- .RData
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(tidyverse)
library(scales)
library(glue)
library(countrycode)
library(ggstream)
library(wesanderson)
```
Trend {data-icon="fa-bar-chart"}
=====================================
Inputs {.sidebar}
-----------------------------------------------------------------------
Column {data-width=550}
-----------------------------------------------------------------------
### UN Vote Trend over the years
```{r}
# Space for other plot
```
Column {data-width=450}
-----------------------------------------------------------------------
### UN Vote Trend by Continents
```{r}
# par(mfrow = c(1,1))
unvotes %>%
mutate(continent = countrycode(country_code, "iso2c", "continent")) %>%
# mutate_all(as.factor) %>%
group_by(continent, years = year(date) , vote) %>%
summarise(count = n(), .groups = "drop_last") %>%
na.omit() %>%
# mutate(pct = count/sum(count)) %>%
ggplot(aes(x = years, y = count, fill = vote)) +
ggstream::geom_stream(show.legend = FALSE) +
geom_stream_label(aes(label = vote)) +
scale_y_continuous(labels = comma, breaks = seq(-2000,2000, 500)) +
scale_fill_manual(values = wes_palette("Darjeeling2")) +
theme(panel.grid.major = element_blank()) +
facet_wrap(~continent, nrow = 5) +
labs(title = "World UN Voting trend over the years by continent",
y = "", x = "",
caption = "created by ViSa")
```
使用 renderPlot
包装您的图,使其响应:
---
title: "UN Country Votes"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
theme: space
runtime: shiny
resource_files:
- .RData
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(tidyverse)
```
# Trend {data-icon="fa-bar-chart"}
## Inputs {.sidebar}
## Column {data-width="550"}
### UN Vote Trend over the years
```{r}
# Space for other plot
```
## Column {data-width="450"}
### UN Vote Trend by Continents
```{r}
# par(mfrow = c(1,1))
renderPlot ({
ggplot(iris) +
geom_point(aes(Sepal.Length, Sepal.Width))
})
```
我用最少的示例简化了您的代码。
我正在使用 tidytuesday UN votes 数据集并尝试通过 nrows
调整 facet plot 以占据 全高 在情节的 flexdashboard 中,但它几乎没有利用一半 space 并使情节不那么明显。
备选方案 是我可以制作 5 个不同的图,但这将 运行 编码 5 次 当它可以完成时一次 facet
.
我也试过 facet_grid
、par(mfrow = c(1,1))
,但都没有用。
代码:
library(flexdashboard)
library(shiny)
library(tidyverse)
library(scales)
library(glue)
library(countrycode)
library(tidytuesdayR)
remotes::install_github("davidsjoberg/ggstream") # for creating streamgraph
数据:
tt <- tt_load("2021-03-23")
unvotes <- tt$unvotes
head(unvotes)
rcid country country_code vote vote_number date amend
<dbl> <chr> <chr> <chr> <dbl> <date> <dbl>
1 3 United States US yes 1 1946-01-01 1
2 3 Canada CA no -1 1946-01-01 1
3 3 Cuba CU yes 1 1946-01-01 1
4 3 Haiti HT yes 1 1946-01-01 1
5 3 Dominican Re~ DO yes 1 1946-01-01 1
6 3 Mexico MX yes 1 1946-01-01 1
flexdashboard
---
title: "UN Country Votes"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
theme: space
runtime: shiny
resource_files:
- .RData
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(tidyverse)
library(scales)
library(glue)
library(countrycode)
library(ggstream)
library(wesanderson)
```
Trend {data-icon="fa-bar-chart"}
=====================================
Inputs {.sidebar}
-----------------------------------------------------------------------
Column {data-width=550}
-----------------------------------------------------------------------
### UN Vote Trend over the years
```{r}
# Space for other plot
```
Column {data-width=450}
-----------------------------------------------------------------------
### UN Vote Trend by Continents
```{r}
# par(mfrow = c(1,1))
unvotes %>%
mutate(continent = countrycode(country_code, "iso2c", "continent")) %>%
# mutate_all(as.factor) %>%
group_by(continent, years = year(date) , vote) %>%
summarise(count = n(), .groups = "drop_last") %>%
na.omit() %>%
# mutate(pct = count/sum(count)) %>%
ggplot(aes(x = years, y = count, fill = vote)) +
ggstream::geom_stream(show.legend = FALSE) +
geom_stream_label(aes(label = vote)) +
scale_y_continuous(labels = comma, breaks = seq(-2000,2000, 500)) +
scale_fill_manual(values = wes_palette("Darjeeling2")) +
theme(panel.grid.major = element_blank()) +
facet_wrap(~continent, nrow = 5) +
labs(title = "World UN Voting trend over the years by continent",
y = "", x = "",
caption = "created by ViSa")
```
使用 renderPlot
包装您的图,使其响应:
---
title: "UN Country Votes"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
theme: space
runtime: shiny
resource_files:
- .RData
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(tidyverse)
```
# Trend {data-icon="fa-bar-chart"}
## Inputs {.sidebar}
## Column {data-width="550"}
### UN Vote Trend over the years
```{r}
# Space for other plot
```
## Column {data-width="450"}
### UN Vote Trend by Continents
```{r}
# par(mfrow = c(1,1))
renderPlot ({
ggplot(iris) +
geom_point(aes(Sepal.Length, Sepal.Width))
})
```
我用最少的示例简化了您的代码。