【发布时间】:2021-04-02 12:24:16
【问题描述】:
我正在使用 tidytuesday 联合国投票数据集并尝试通过nrows 调整 facet plot 以占据 flexdashboard 中的 full height情节,但它几乎没有利用一半的空间,使情节不那么明显。
另一种选择是我可以制作 5 个不同的绘图,但是当它可以使用 facet 一次性完成时,这将运行 代码 5 次。
我也试过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
弹性仪表板
---
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")
```
【问题讨论】:
标签: r shiny flexdashboard facet-wrap