-
Notifications
You must be signed in to change notification settings - Fork 0
/
WHO Case.R
70 lines (48 loc) · 1.33 KB
/
WHO Case.R
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
library(tidyverse)
who <- tidyr::who
str(who)
summary(who)
who_unpivot <- who %>%
gather(new_sp_m014:newrel_f65, key = "key", value = "cases", na.rm = TRUE)
str(who_unpivot)
summary(who_unpivot)
who_unpivot %>%
count(key)
#Replaced Strings
who2 <- who_unpivot %>%
mutate(key = stringr::str_replace(key, "newrel", "new_rel"))
who2
head(who2)
who3 <- who2 %>%
separate(key, c("new", "type", "sexage"), sep = "_")
who3
who3 %>%
count(new)
who4 <- who3 %>%
select(-new, -iso2, -iso3)
whocleaner <- who4 %>%
separate(sexage, c("sex", "age"), sep = 1)
whocleaner
whocleaner %>%
group_by(country, year, sex) %>%
filter(year > 1995) %>%
summarise(cases = sum(cases)) %>%
unite(country_sex, country, sex, remove = FALSE) %>%
ggplot(aes(x = year, y = cases, group = country_sex, colour = sex)) +
geom_line()
whocleaner %>%
group_by(country, year, sex) %>%
filter(year > 1995) %>%
summarise(cases = sum(cases))
whocleaner %>%
group_by(country, year, sex) %>%
filter(year > 1995) %>%
summarise(cases = sum(cases)) %>%
unite(country_sex, country, sex, remove = FALSE)
whocleaner %>%
group_by(country, year, sex) %>%
filter(year > 2011) %>%
summarise(cases = sum(cases)) %>%
unite(country_sex, country, sex, remove = FALSE) %>%
ggplot(aes(x = country, y = cases, colour = sex)) +
geom_line()