-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rmd_plus_Shiny.Rmd
94 lines (73 loc) · 2.34 KB
/
Rmd_plus_Shiny.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
title: "Rmd + Shiny"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
library(tidyr)
library(ggplot2)
library(southafricastats)
```
```{r, include=FALSE}
totals <- population_zaf %>%
filter(year == 2013) %>%
select(province, total)
compare_provinces <- mortality_zaf %>%
left_join(population_zaf) %>%
filter(!is.na(total)) %>%
mutate(mortality = deaths / total * 1e3) %>%
group_by(province, indicator) %>%
summarise(mortality = mean(mortality, na.rm = TRUE)) %>%
ungroup %>%
left_join(totals) %>%
spread(indicator, mortality)
```
```{r, eval=FALSE, include=FALSE}
ggplot(compare_provinces, aes(`Cerebrovascular diseases (I60-I69)`,
`Diabetes mellitus (E10-E14)`,
size = total,
label = province)) +
geom_point(alpha = 0.7, color = "midnightblue") +
geom_text(aes(size = 1.8e6), vjust = -1.5) +
theme_minimal() +
xlim(c(0.3, 0.7)) +
ylim(c(0.3, 0.55)) +
theme(legend.position="none")
```
```{r, echo=FALSE}
selectInput(inputId = "x",
label = "X-axis:",
choices = colnames(compare_provinces)[3:20],
selected = "Other forms of heart disease (I30-I52)")
selectInput(inputId = "y",
label = "Y-axis:",
choices = colnames(compare_provinces)[3:20],
selected = "Non-natural causes")
```
```{r, include=FALSE}
selected_df <- reactive({
subset_df <- compare_provinces[, c(1:2,
which(colnames(compare_provinces) == input$x),
which(colnames(compare_provinces) == input$y))]
colnames(subset_df) <- c("province", "total",
"selected_x", "selected_y")
subset_df
})
```
```{r, echo=FALSE}
fillCol(height = 1800,
renderPlot({
ggplot(selected_df(), aes(x = selected_x,
y = selected_y,
size = total,
label = province)) +
geom_point(alpha = 0.7, color = "midnightblue") +
theme_minimal() +
labs(x = input$x, y = input$y) +
geom_text(aes(size = 1e7), vjust = 2) +
theme_minimal(base_size = 14) +
theme(legend.position="none")
}),width = 1800)
```