-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_explore-counts-longseries.Rmd
176 lines (142 loc) · 4.16 KB
/
3_explore-counts-longseries.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---
title: "Počty úředníků: 2003-2018"
author: "Petr Bouchal"
date: "11/2/2019"
output: html_document
execute:
freeze: auto
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = T, warning = F, message = F, rows.print = 20)
library(readr)
library(dplyr)
library(ggplot2)
library(tidyr)
library(tibble)
library(lubridate)
library(purrr)
knitr::opts_chunk$set(echo = TRUE)
options(scipen = 6)
```
```{r}
c13o <- read_csv(here::here("data-output/legacy/groups_ALL.csv"))
dt0 <- read_rds(here::here("data-interim/objemy_pocty_scraped_raw_2012_2018.rds"))
```
```{r, max.print = 15}
unique(c13o$variable) %>% enframe(name = NULL)
unique(c13o$grp) %>% enframe(name = NULL)
unique(dt0$type) %>% enframe(name = NULL)
```
# Explore & prep to merge {.tabset}
```{r, include=F}
c13o %>%
select(grp, sgrp) %>%
distinct()
```
## Prep data 2013+
```{r}
dt <- dt0 %>%
filter(kap_num == "C E L K E M" & indicator == "count") %>%
select(year, grp = type, schvaleny = rozp,
skutecnost, upraveny, rozdil, index, plneni) %>%
mutate(grp = recode(grp,
`jedn. OSS státní správy` = "neústřední st. správa",
`ST.SPRÁVA` = "St. sprava se SOBCPO"),
plneni = 2-plneni/100, rozdil = -rozdil)
```
## Prep data 2003+
```{r}
dto <- c13o %>%
filter(promenna == "Zam") %>%
select(grp, sgrp, variable, value, udaj, promenna, UO, exekutiva, Year) %>%
set_names(tolower(names(.))) %>%
mutate_at(vars(udaj, variable, promenna), tolower) %>%
mutate(year = year(year),
udaj = recode(udaj, upr2skut = "plneni",
uprminusskut = "rozdil"),
grp = recode(grp, UO = "ÚO", `OSS-RO` = "OSS sum",
PO = "PO sum",
`OSS-SS` = "neústřední st. správa",
OOSS = "ostatní OSS")) %>%
filter(grp %in% c("ÚO", "ST.SPRÁVA", "SOBCPO", "OSS sum", "ostatní OSS",
"PO sum", "St. sprava se SOBCPO",
"neústřední st. správa"))
```
## Check groupings {.tabset}
### 2003+
```{r}
unique(dto$grp) %>% enframe(name = NULL)
```
### 2013+
```{r}
unique(dt$grp) %>% enframe(name = NULL)
```
## Check data by comparing grouping sizes {.tabset}
### 2003+
```{r}
dto %>%
filter(udaj == "schvaleny" & year == 2013) %>%
ggplot(aes(grp, value/1000)) +
geom_col() + coord_flip() + ggtitle("2013 - data 2003-2012") +
scale_y_continuous(limits = c(0,250))
```
### 2013+
```{r}
dt %>%
filter(year == 2013) %>%
filter(!(grp %in% c("Příslušníci a vojáci"))) %>%
ggplot(aes(grp, skutecnost/1e3)) +
geom_col() + coord_flip() + ggtitle("2013 - data 2013-2018") +
scale_y_continuous(limits = c(0,250))
```
## Merge data:
```{r}
srs <- bind_rows(dto %>% mutate(ds = "old") %>%
filter(year != 2013) %>%
select(year, grp, value, udaj),
dt %>% pivot_longer(names_to = "udaj", values_to = "value",
cols = c(schvaleny, skutecnost,
upraveny, rozdil,
index, plneni)) %>%
mutate(ds = "new", year = as.numeric(year)))
```
# First charts {.tabset}
NB:
- skok v roce 2012 je daný redefinicí MV, které od 2012 zahrnuje i velení policie a hasičů
- řada příslušníků a vojáků začíná až v 2013, protože z minulé analýzy jsme je tuším úplně vypustil nebo v interních datech MF nebyli
## Absolute - comparable
```{r}
srs %>%
filter(udaj == "skutecnost") %>%
ggplot(aes(year, value)) +
geom_line() +
facet_wrap(~grp)
```
## Absolute - focus on changes
```{r}
srs %>%
filter(udaj == "skutecnost") %>%
ggplot(aes(year, value)) +
geom_line() +
facet_wrap(~grp, scales = "free_y")
```
# Comparisons {.tabset}
## Plan vs. reality
```{r}
srs %>%
filter(udaj == "plneni") %>%
ggplot(aes(year, 2-value)) +
geom_line() +
facet_wrap(~grp)
```
## Growth from 2003 base
```{r}
srs %>%
filter(udaj == "skutecnost") %>%
group_by(grp) %>%
arrange(year) %>%
mutate(index = value/first(value)) %>%
ggplot(aes(year, index)) +
geom_line() +
facet_wrap(~grp)
```