-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_plan.R
143 lines (117 loc) · 3.67 KB
/
project_plan.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
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
pacman::p_load(tidyverse,
glue,
janitor,
gt,
ganttrify,
readxl)
# Variables ----
weca_core_colours <- c(
"Dark Blue" = "#354753",
"Blue" = "#6bd4f2",
"Pink" = "#ed749d",
"Yellow" = "#ffd900",
"Green" = "#79decc") %>%
unname()
date_label <- Sys.Date() %>%
as.character() %>%
str_replace_all("\\s|\\.|\\:|\\-", "")
# from monitoring framework state of nature:: project plan LOCAL
lnrs_tbl <- read_xlsx('data/project_plan.xlsx',
sheet = 'project_plan_3')
# Functions ----
read_spot_tbl <- function(filename = "data/project_plan.xlsx",
sheetname) {
read_xlsx(filename, sheet = sheetname) %>%
mutate(spot_date = as.Date(spot_date),
spot_type = toupper(spot_type))
}
# make clean table for ganttrification
make_clean_tbl <- function(tbl) {
tbl %>%
filter(!is.na(activity),
!is.na(start_date)) %>%
fill(wp, .direction = "down") %>%
mutate(across(.cols = ends_with("date"), as.Date))
}
# Make GT table for detailed plan
make_activity_table_gt <- function(tbl) {
tbl %>%
select(wp, activity, detail = Detail, start_date, end_date) %>%
mutate(across(.cols = ends_with("date"), .fns = ~format(.x, "%b %y")),
detail = if_else(is.na(detail), "", detail)) %>%
group_by(wp) %>%
gt() %>%
cols_label_with(columns = ends_with("date"),
fn = compose(~str_replace(., "_", "\n"), str_to_title)) %>%
cols_label_with(columns = everything(),
fn = str_to_title) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_column_labels()
) %>%
tab_style(
style = cell_text(weight = 'bold', size = 'large'),
locations = cells_row_groups()
)
}
my_ganntrify <- function(clean_tbl,
spot_tbl,
core_colours = weca_core_colours,
title,
caption) {
clean_tbl %>%
ganttrify(
label_wrap = 30,
colour_palette = core_colours,
spots = spot_tbl,
month_number_label = FALSE,
alpha_activity = 0.6,
by_date = TRUE,
size_text_relative = 1.2,
mark_quarters = TRUE) +
labs(title = title,
caption = caption)
}
save_gantt <- function(gantt_object, filename, date_label, width = 15, height = 14){
path = glue("plots/gantt_{filename}_{date_label}.png")
ggsave(path,
device = "png",
plot = gantt_object,
bg = "white",
width = width,
height = height)
return(path)
}
# create the output M&E ----
clean_tbl <- make_clean_tbl(lnrs_tbl) %>%
filter(primary == 4)
spot_tbl <- read_spot_tbl(sheetname = "m_and_e_spot")
m_and_e_gantt <- my_ganntrify(clean_tbl,
spot_tbl,
title = "Open Data Portal: M&E Activities",
caption = "U = Update\nR = Reporting\nS = Survey")
m_and_e_gantt
save_gantt(m_and_e_gantt,
"m_and_e",
width = 10,
height = 11,
date_label)
# Overall Project Updated ----
clean_tbl <- make_clean_tbl(lnrs_tbl) %>%
filter(primary != 5)
spot_tbl <- read_spot_tbl(sheetname = "project_spot_data_2")
overall_project_gantt <- my_ganntrify(
clean_tbl,
spot_tbl,
title = "Open Data Portal: Project Overview",
caption = "")
overall_project_gantt
save_gantt(overall_project_gantt,
"overall_project_gantt",
width = 14,
height = 16,
date_label)
# Output project plan
clean_tbl %>%
make_activity_table_gt() %>%
gtsave(glue("plots/activity_table_portal_{date_label}.png"))