-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanData
48 lines (38 loc) · 2.17 KB
/
cleanData
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
df = import('https://raw.githubusercontent.com/datalake101/climatedata-imf/main/climateChangeIMF.csv')
df %>%
rowwise() %>%
mutate(
mean2010 = mean(c(.data$`2010Q1`, .data$`2010Q2`, .data$`2010Q3`, .data$`2010Q4`), na.rm = T),
mean2011 = mean(c(.data$`2011Q1`, .data$`2011Q2`, .data$`2011Q3`, .data$`2011Q4`), na.rm = T),
mean2012 = mean(c(.data$`2012Q1`, .data$`2012Q2`, .data$`2012Q3`, .data$`2012Q4`), na.rm = T),
mean2013 = mean(c(.data$`2013Q1`, .data$`2013Q2`, .data$`2013Q3`, .data$`2013Q4`), na.rm = T),
mean2014 = mean(c(.data$`2014Q1`, .data$`2014Q2`, .data$`2014Q3`, .data$`2014Q4`), na.rm = T),
mean2015 = mean(c(.data$`2015Q1`, .data$`2015Q2`, .data$`2015Q3`, .data$`2015Q4`), na.rm = T),
mean2016 = mean(c(.data$`2016Q1`, .data$`2016Q2`, .data$`2016Q3`, .data$`2016Q4`), na.rm = T),
mean2017 = mean(c(.data$`2017Q1`, .data$`2017Q2`, .data$`2017Q3`, .data$`2017Q4`), na.rm = T),
mean2018 = mean(c(.data$`2018Q1`, .data$`2018Q2`, .data$`2018Q3`, .data$`2018Q4`), na.rm = T),
mean2019 = mean(c(.data$`2019Q1`, .data$`2019Q2`, .data$`2019Q3`, .data$`2019Q4`), na.rm = T),
mean2020 = mean(c(.data$`2020Q1`, .data$`2020Q2`, .data$`2020Q3`, .data$`2020Q4`), na.rm = T),
mean2021 = mean(c(.data$`2021Q1`, .data$`2021Q2`, .data$`2021Q3`, .data$`2021Q4`), na.rm = T),
mean2022 = mean(c(.data$`2022Q1`, .data$`2022Q2`, .data$`2022Q3`, .data$`2022Q4`), na.rm = T)
)
df %>% mutate(meanCol = rowMeans(.[, c(56,57)], na.rm = T))
df %>%
pivot_longer(
cols = all_of(4:57 ),
names_to = c("year", "quarter"),
names_pattern = "(\\d+)(Q\\d)",
values_to = "value"
)
df %>%
mutate(year = as.character(year)) %>%
group_by(year, Industry, Country, gasType) %>%
summarise(mean = mean(value)) %>%
ggplot(aes(x = year, y = mean, color = Industry, group = interaction(Industry))) +
geom_line() +
facet_grid(rows = vars(Country), cols = vars(gasType)) +
labs(x = "Year", y = "Mean Value", color = "") +
theme_minimal() +
theme(legend.direction = "horizontal", legend.position = "bottom",
legend.title = element_blank(), legend.box.spacing = unit(0.2, "cm"),
legend.spacing = unit(0.2, "cm"))