diff --git a/README.md b/README.md index be0c75d..cdeee25 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ Research Institute for Nature and Forest (INBO)[^cph][^fnd] -Repository (under construction) accompanying the development of monitoring programmes for the invasive alien species of Union concern. +Repository (under construction) accompanying the development of monitoring schemes for the invasive alien species of Union concern in Flanders. +This is an overarching repository. diff --git a/inst/en_gb.dic b/inst/en_gb.dic index dc00588..261d742 100644 --- a/inst/en_gb.dic +++ b/inst/en_gb.dic @@ -2,6 +2,7 @@ AAN AFW BEP BUI +Fase GEV IAS IRR diff --git a/renv.lock b/renv.lock index 849f940..36c1505 100644 --- a/renv.lock +++ b/renv.lock @@ -28,6 +28,16 @@ ], "Hash": "065ae649b05f1ff66bb0c793107508f5" }, + "Deriv": { + "Package": "Deriv", + "Version": "4.1.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "methods" + ], + "Hash": "bc727aba82bcda74db0bbe188ec6757c" + }, "KernSmooth": { "Package": "KernSmooth", "Version": "2.23-24", @@ -71,6 +81,19 @@ ], "Hash": "1920b2f11133b12350024297d8a4ff4a" }, + "MatrixModels": { + "Package": "MatrixModels", + "Version": "0.5-3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "Matrix", + "R", + "methods", + "stats" + ], + "Hash": "0776bf7526869e0286b0463cb72fb211" + }, "R6": { "Package": "R6", "Version": "2.5.1", @@ -121,6 +144,45 @@ ], "Hash": "5ea2700d21e038ace58269ecdbeb9ec0" }, + "RcppEigen": { + "Package": "RcppEigen", + "Version": "0.3.4.0.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "Rcpp", + "stats", + "utils" + ], + "Hash": "df49e3306f232ec28f1604e36a202847" + }, + "SparseM": { + "Package": "SparseM", + "Version": "1.84-2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "graphics", + "methods", + "stats", + "utils" + ], + "Hash": "e78499cbcbbca98200254bd171379165" + }, + "abind": { + "Package": "abind", + "Version": "1.4-5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods", + "utils" + ], + "Hash": "4f57884290cc75ab22f4af9e9d4ca862" + }, "askpass": { "Package": "askpass", "Version": "1.2.0", @@ -209,6 +271,18 @@ ], "Hash": "40415719b5a479b87949f3aa0aee737c" }, + "boot": { + "Package": "boot", + "Version": "1.3-30", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "graphics", + "stats" + ], + "Hash": "96abeed416a286d4a0f52e550b612343" + }, "brew": { "Package": "brew", "Version": "1.0-10", @@ -226,6 +300,26 @@ ], "Hash": "c1ee497a6d999947c2c224ae46799b1a" }, + "broom": { + "Package": "broom", + "Version": "1.0.6", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "backports", + "dplyr", + "generics", + "glue", + "lifecycle", + "purrr", + "rlang", + "stringr", + "tibble", + "tidyr" + ], + "Hash": "a4652c36d1f8abfc3ddf4774f768c934" + }, "bslib": { "Package": "bslib", "Version": "0.7.0", @@ -272,6 +366,52 @@ ], "Hash": "d7e13f49c19103ece9e58ad2d83a7354" }, + "car": { + "Package": "car", + "Version": "3.1-2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "MASS", + "R", + "abind", + "carData", + "grDevices", + "graphics", + "lme4", + "mgcv", + "nlme", + "nnet", + "pbkrtest", + "quantreg", + "scales", + "stats", + "utils" + ], + "Hash": "839b351f31d56e0147439eb22c00a66a" + }, + "carData": { + "Package": "carData", + "Version": "3.0-5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "ac6cdb8552c61bd36b0e54d07cf2aab7" + }, + "cellranger": { + "Package": "cellranger", + "Version": "1.1.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "rematch", + "tibble" + ], + "Hash": "f61dbaec772ccd2e17705c1e872e9e7c" + }, "checklist": { "Package": "checklist", "Version": "0.3.6", @@ -419,6 +559,24 @@ ], "Hash": "f20c47fd52fae58b4e377c37bb8c335b" }, + "cols4all": { + "Package": "cols4all", + "Version": "0.7-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "abind", + "colorspace", + "grDevices", + "methods", + "png", + "spacesXYZ", + "stats", + "stringdist" + ], + "Hash": "9dd4e7c6c4edf979020dd92679573613" + }, "commonmark": { "Package": "commonmark", "Version": "1.9.1", @@ -426,6 +584,30 @@ "Repository": "CRAN", "Hash": "5d8225445acb167abf7797de48b2ee3c" }, + "corrplot": { + "Package": "corrplot", + "Version": "0.92", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "fcf11a91936fd5047b2ee9bc00595e36" + }, + "cowplot": { + "Package": "cowplot", + "Version": "1.1.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "ggplot2", + "grDevices", + "grid", + "gtable", + "methods", + "rlang", + "scales" + ], + "Hash": "8ef2084dd7d28847b374e55440e4f8cb" + }, "cpp11": { "Package": "cpp11", "Version": "0.4.7", @@ -598,6 +780,30 @@ ], "Hash": "fd6824ad91ede64151e93af67df6376b" }, + "doBy": { + "Package": "doBy", + "Version": "4.6.22", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "Deriv", + "MASS", + "Matrix", + "R", + "boot", + "broom", + "cowplot", + "dplyr", + "ggplot2", + "methods", + "microbenchmark", + "modelr", + "rlang", + "tibble", + "tidyr" + ], + "Hash": "a9b56885b9596c284168df26d6179c40" + }, "downlit": { "Package": "downlit", "Version": "0.4.4", @@ -728,6 +934,28 @@ ], "Hash": "15aeb8c27f5ea5161f9f6a641fafd93a" }, + "gargle": { + "Package": "gargle", + "Version": "1.5.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "fs", + "glue", + "httr", + "jsonlite", + "lifecycle", + "openssl", + "rappdirs", + "rlang", + "stats", + "utils", + "withr" + ], + "Hash": "fc0b272e5847c58cd5da9b20eedbd026" + }, "generics": { "Package": "generics", "Version": "0.1.3", @@ -779,6 +1007,74 @@ ], "Hash": "44c6a2f8202d5b7e878ea274b1092426" }, + "ggpubr": { + "Package": "ggpubr", + "Version": "0.6.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cowplot", + "dplyr", + "ggplot2", + "ggrepel", + "ggsci", + "ggsignif", + "glue", + "grid", + "gridExtra", + "magrittr", + "polynom", + "purrr", + "rlang", + "rstatix", + "scales", + "stats", + "tibble", + "tidyr", + "utils" + ], + "Hash": "c957612b8bb1ee9ab7b2450d26663e7e" + }, + "ggrepel": { + "Package": "ggrepel", + "Version": "0.9.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "Rcpp", + "ggplot2", + "grid", + "rlang", + "scales", + "withr" + ], + "Hash": "cc3361e234c4a5050e29697d675764aa" + }, + "ggsci": { + "Package": "ggsci", + "Version": "3.2.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "ggplot2", + "grDevices", + "scales" + ], + "Hash": "0c3268cddf4d3a3ce4e7e6330f8e92c8" + }, + "ggsignif": { + "Package": "ggsignif", + "Version": "0.6.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "ggplot2" + ], + "Hash": "a57f0f5dbcfd0d77ad4ff33032f5dc79" + }, "gh": { "Package": "gh", "Version": "1.4.1", @@ -818,6 +1114,73 @@ ], "Hash": "e0b3a53876554bd45879e596cdb10a52" }, + "googledrive": { + "Package": "googledrive", + "Version": "2.1.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "gargle", + "glue", + "httr", + "jsonlite", + "lifecycle", + "magrittr", + "pillar", + "purrr", + "rlang", + "tibble", + "utils", + "uuid", + "vctrs", + "withr" + ], + "Hash": "e99641edef03e2a5e87f0a0b1fcc97f4" + }, + "googlesheets4": { + "Package": "googlesheets4", + "Version": "1.1.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cellranger", + "cli", + "curl", + "gargle", + "glue", + "googledrive", + "httr", + "ids", + "lifecycle", + "magrittr", + "methods", + "purrr", + "rematch2", + "rlang", + "tibble", + "utils", + "vctrs", + "withr" + ], + "Hash": "d6db1667059d027da730decdc214b959" + }, + "gridExtra": { + "Package": "gridExtra", + "Version": "2.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "grDevices", + "graphics", + "grid", + "gtable", + "utils" + ], + "Hash": "7d7f283939f563670a697165b2cf5560" + }, "gtable": { "Package": "gtable", "Version": "0.3.5", @@ -959,6 +1322,17 @@ ], "Hash": "e957e989ea17f937964f0d46b0f0bca0" }, + "ids": { + "Package": "ids", + "Version": "1.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "openssl", + "uuid" + ], + "Hash": "99df65cfef20e525ed38c3d2577f7190" + }, "inborutils": { "Package": "inborutils", "Version": "0.4.0", @@ -1197,6 +1571,32 @@ ], "Hash": "08cff46381a242d44c0d8dd0aabd9f71" }, + "lme4": { + "Package": "lme4", + "Version": "1.1-35.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "MASS", + "Matrix", + "R", + "Rcpp", + "RcppEigen", + "boot", + "graphics", + "grid", + "lattice", + "methods", + "minqa", + "nlme", + "nloptr", + "parallel", + "splines", + "stats", + "utils" + ], + "Hash": "16a08fc75007da0d08e0c0388c7c33e6" + }, "lubridate": { "Package": "lubridate", "Version": "1.9.3.9000", @@ -1248,6 +1648,17 @@ ], "Hash": "110ee9d83b496279960e162ac97764ce" }, + "microbenchmark": { + "Package": "microbenchmark", + "Version": "1.4.10", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "graphics", + "stats" + ], + "Hash": "db81b552e393ed092872cf7023469bc2" + }, "mime": { "Package": "mime", "Version": "0.12", @@ -1270,6 +1681,34 @@ ], "Hash": "fec5f52652d60615fdb3957b3d74324a" }, + "minqa": { + "Package": "minqa", + "Version": "1.2.7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "Rcpp" + ], + "Hash": "aba060ef3c097b26a4d304ea39d87f32" + }, + "modelr": { + "Package": "modelr", + "Version": "0.1.11", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "broom", + "magrittr", + "purrr", + "rlang", + "tibble", + "tidyr", + "tidyselect", + "vctrs" + ], + "Hash": "4f50122dc256b1b6996a4703fecea821" + }, "munsell": { "Package": "munsell", "Version": "0.5.1", @@ -1295,6 +1734,35 @@ ], "Hash": "2769a88be217841b1f33ed469675c3cc" }, + "nloptr": { + "Package": "nloptr", + "Version": "2.1.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "27550641889a3abf3aec4d91186311ec" + }, + "nnet": { + "Package": "nnet", + "Version": "7.3-19", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "stats", + "utils" + ], + "Hash": "2c797b46eea7fb58ede195bc0b1f1138" + }, + "numDeriv": { + "Package": "numDeriv", + "Version": "2016.8-1.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "df58958f293b166e4ab885ebcad90e02" + }, "oai": { "Package": "oai", "Version": "0.4.0", @@ -1319,6 +1787,24 @@ ], "Hash": "2bcca3848e4734eb3b16103bc9aa4b8e" }, + "pbkrtest": { + "Package": "pbkrtest", + "Version": "0.5.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "MASS", + "Matrix", + "R", + "broom", + "doBy", + "dplyr", + "lme4", + "methods", + "numDeriv" + ], + "Hash": "938e6bbc4ac57534f8b43224506a8966" + }, "pillar": { "Package": "pillar", "Version": "1.9.0", @@ -1452,6 +1938,17 @@ ], "Hash": "bd54ba8a0a5faded999a7aab6e46b374" }, + "polynom": { + "Package": "polynom", + "Version": "1.4-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "graphics", + "stats" + ], + "Hash": "ceb5c2a59ba33d42d051285a3e8a5118" + }, "praise": { "Package": "praise", "Version": "1.0.0", @@ -1565,6 +2062,24 @@ ], "Hash": "1cba04a4e9414bdefc9dcaa99649a8dc" }, + "quantreg": { + "Package": "quantreg", + "Version": "5.98", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "MASS", + "Matrix", + "MatrixModels", + "R", + "SparseM", + "graphics", + "methods", + "stats", + "survival" + ], + "Hash": "017561f17632c065388b7062da030952" + }, "ragg": { "Package": "ragg", "Version": "1.3.2", @@ -1645,6 +2160,13 @@ ], "Hash": "9de96463d2117f6ac49980577939dfb3" }, + "rematch": { + "Package": "rematch", + "Version": "2.0.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "cbff1b666c6fa6d21202f07e2318d4f1" + }, "rematch2": { "Package": "rematch2", "Version": "2.1.2", @@ -1781,6 +2303,29 @@ ], "Hash": "4c8415e0ec1e29f3f4f6fc108bef0144" }, + "rstatix": { + "Package": "rstatix", + "Version": "0.7.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "broom", + "car", + "corrplot", + "dplyr", + "generics", + "magrittr", + "purrr", + "rlang", + "stats", + "tibble", + "tidyr", + "tidyselect", + "utils" + ], + "Hash": "5045fbb71b143878d8c51975d1d7d56d" + }, "rstudioapi": { "Package": "rstudioapi", "Version": "0.16.0", @@ -1942,6 +2487,27 @@ ], "Hash": "75940133cca2e339afce15a586f85b11" }, + "spacesXYZ": { + "Package": "spacesXYZ", + "Version": "1.3-0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "507dc00e31b82a5e3932c175bbd8243c" + }, + "stringdist": { + "Package": "stringdist", + "Version": "0.9.12", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "parallel" + ], + "Hash": "f360720fa3feb7db9d4133b31ebb067f" + }, "stringi": { "Package": "stringi", "Version": "1.8.4", @@ -1972,6 +2538,22 @@ ], "Hash": "960e2ae9e09656611e0b8214ad543207" }, + "survival": { + "Package": "survival", + "Version": "3.7-0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "Matrix", + "R", + "graphics", + "methods", + "splines", + "stats", + "utils" + ], + "Hash": "5aaa9cbaf4aba20f8e06fdea1850a398" + }, "svglite": { "Package": "svglite", "Version": "2.1.3", @@ -2236,6 +2818,16 @@ ], "Hash": "62b65c52671e6665f803ff02954446e9" }, + "uuid": { + "Package": "uuid", + "Version": "1.2-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "34e965e62a41fcafb1ca60e9b142085b" + }, "vctrs": { "Package": "vctrs", "Version": "0.6.5", diff --git a/source/functions/make_ganttchart.R b/source/functions/make_ganttchart.R new file mode 100644 index 0000000..b2ca258 --- /dev/null +++ b/source/functions/make_ganttchart.R @@ -0,0 +1,336 @@ +make_ganttchart <- function( + data_sheet, + col_var, + phase_no_plot = 1, + show_tasks_withoutdate = FALSE, + tasklabel_textsize = 3, + tasklabel_linebreak_nchar = 20, + show_brackets = TRUE, + brackets_vjust = -0.6, + brackets_distance = 2, + barwidth_scalingfactor = 5, + cols4all_palette = "carto.pastel" + ) { + # + # process data for plotting + data_sheet_upd <- data_sheet |> + dplyr::rename( + !!"start" := "termijn_begin", + !!"end" := "termijn_einde", + !!"task_no" := "taak_nr", + !!"task" := "taak_naam", + !!"phase_no" := "fase_nr", + !!"step" := "stap_naam", + !!"block" := "bouwsteen_naam", + !!"element" := "element_naam", + !!"responsible" := "trekker" + ) |> + dplyr::mutate( + start = as.Date(start), + end = as.Date(end), + phase = paste("fase", get("phase_no")), + status = dplyr::case_when( + grepl("niet gestart", status) ~ "not started", + grepl("lopend", status) ~ "ongoing", + grepl("voltooid", status) ~ "done" + ), + # adjust appearance based on status + text_col = dplyr::case_when( + grepl("^done", status) ~ "darkgrey", + TRUE ~ "black" + ), + text_fontface = dplyr::case_when( + grepl("ongoing", status) ~ "bold", + TRUE ~ "plain" + ), + bar_alpha = dplyr::case_when( + grepl("not started", status) ~ 1, + TRUE ~ .3 + ) + ) + # add line breaks and spaces to tasks + data_sheet_upd$task <- sapply( + seq_len(nrow(data_sheet_upd)), function(x) { + stringi::stri_wrap( + str = data_sheet_upd$task[x], + width = tasklabel_linebreak_nchar + ) |> + paste0(collapse = "\n") + } + ) + + data_sheet_upd$task <- paste0(" ", data_sheet_upd$task) + # bar size based on number of linebreaks + data_sheet_upd <- data_sheet_upd |> + dplyr::mutate( + bar_size = ( + stringr::str_count(get("task"), "\n") + 2 + ) * barwidth_scalingfactor + ) + # + # rearrange, filter data for plotting + if (show_tasks_withoutdate) { + # dummy dates (not shown) if show_tasks_withoutdate = TRUE + data_plot <- data_sheet_upd |> + dplyr::filter(is.na(start) & is.na(end)) |> + dplyr::mutate( + start = as.Date("2024-08-05"), # monday + end = as.Date("2024-08-09"), # friday + phase = paste(get("phase"), "(taken zonder termijn)") + ) + } else { + data_plot <- data_sheet_upd |> + tidyr::drop_na(dplyr::any_of(c("start", "end"))) + } + # reorder tasks & responsibles + data_plot <- data_plot |> + dplyr::arrange(get("task_no")) |> + dplyr::filter(get("phase_no") %in% get("phase_no_plot")) + task_ordered <- data_plot |> dplyr::pull(get("task")) |> rev() + responsible_ordered <- c( + c("Janne", "Diederick"), data_plot$responsible + ) |> unique() + data_plot_final <- data_plot |> + dplyr::mutate( + task = factor( + x = get("task"), + levels = task_ordered + ), + responsible = factor( + x = get("responsible"), + levels = responsible_ordered + ) + ) + # + # get weekends / weekdays + date_min <- data_plot_final$start |> min(x = _, na.rm = TRUE) + date_max <- data_plot_final$end |> max(x = _, na.rm = TRUE) + data_dates <- data.frame( + date = seq( + date_min, + date_max, + by = "1 day") + ) |> + dplyr::mutate( + weekday = weekdays(date) + ) |> + dplyr::mutate( + weekend = dplyr::case_when( + grepl("Saturday|Sunday|zaterdag|zondag", weekday) ~ date, + TRUE ~ NA + ), + weekend_mid = dplyr::case_when( + grepl("Saturday|zaterdag", weekday) ~ date + 0.5, + TRUE ~ NA + ), + workday = dplyr::case_when( + grepl("Saturday|Sunday|zaterdag|zondag", weekday) ~ NA, + TRUE ~ date + ), + monday = dplyr::case_when( + grepl("Monday|maandag", weekday) ~ date, + TRUE ~ NA + ) + ) + # + # remove dates christmas break + breakdates <- seq( + paste0(lubridate::year(date_min), "-12-24") |> as.Date(), + paste0(lubridate::year(date_min) + 1, "-01-01") |> as.Date(), + by = "1 day") + data_dates <- data_dates |> dplyr::filter(! date %in% breakdates) + # + # data for brackets + if (show_brackets) { + data_brackets <- lapply(c("element", "block", "step"), function(x) { + dplyr::full_join( + data_plot_final |> + dplyr::group_by(dplyr::across(dplyr::all_of(x))) |> + dplyr::slice(1) |> + dplyr::ungroup() |> + dplyr::select(c("task", x)) |> + dplyr::rename(!!"xmin" := "task", !!"label" := x), + data_plot_final |> + dplyr::group_by(dplyr::across(dplyr::all_of(x))) |> + dplyr::slice(dplyr::n()) |> + dplyr::ungroup() |> + dplyr::select(c("task", x)) |> + dplyr::rename(!!"xmax" := "task", !!"label" := x) + ) |> + dplyr::mutate(type = x) + } + ) |> + dplyr::bind_rows() |> + dplyr::mutate( + ypos = dplyr::case_when( + grepl("element", type) ~ date_min - (1 * brackets_distance), + grepl("block", type) ~ date_min - (2 * brackets_distance), + grepl("step", type) ~ date_min - (3 * brackets_distance), + ) + ) |> + na.omit() + # adapt xmin, xmax + data_brackets <- data_brackets |> + dplyr::mutate( + xmin = as.numeric(get("xmin")) + 0.25, + xmax = as.numeric(get("xmax")) - 0.25 + ) + # reformat brackets label for plot + data_brackets$spaces <- stringr::str_count(data_brackets$label, " ") + spaces_max <- data_brackets$spaces |> max(x = _, na.rm = TRUE) + data_brackets$label_re <- sapply( + seq_len(nrow(data_brackets)), + function(x) { + paste0( + paste0( + rep("\n", spaces_max - data_brackets$spaces[x]), + collapse = ""), + data_brackets$label[x] + ) + } + ) + data_brackets$label_re <- gsub(" ", "\n", data_brackets$label_re) + } + # + # colors + col_var_upd <- switch( + col_var, + trekker = "responsible" + ) + # trick to get full legend + responsible_diff <- setdiff( + data_sheet_upd$responsible |> na.omit() |> unique(), + data_plot_final$responsible |> na.omit() |> unique() + ) + if (length(responsible_diff) > 0) { + tmp <- data_plot_final[1, ] |> + dplyr::slice(rep(1, each = length(responsible_diff))) |> + dplyr::mutate( + responsible = responsible_diff, + start = NA, + end = NA + ) + data_plot_final <- dplyr::bind_rows( + tmp, + data_plot_final + ) + } + # + # make plot + ggplot2::ggplot(data_plot_final) + { + # weekends + if (!show_tasks_withoutdate) + ggplot2::geom_hline( + data = data_dates, + ggplot2::aes(yintercept = .data$weekend_mid), + color = "grey90", + linewidth = 5 + ) + } + { + # current date + if (!show_tasks_withoutdate) + ggplot2::geom_hline( + yintercept = Sys.Date(), + linetype = "dashed" + ) + } + + # bars + ggplot2::geom_segment( + ggplot2::aes( + y = get("start"), yend = end, x = get("task"), + color = get(col_var_upd) + ), + size = data_plot_final$bar_size, + lineend = "butt", + alpha = data_plot_final$bar_alpha + ) + + # tasks + ggplot2::geom_text( + ggplot2::aes(y = get("start"), x = get("task"), label = get("task")), + col = data_plot_final$text_col, + fontface = data_plot_final$text_fontface, + hjust = 0, + size = tasklabel_textsize, + lineheight = .8 + ) + { + # brackets + if (show_brackets) + ggpubr::geom_bracket( + data = data_brackets, + ggplot2::aes( + xmin = get("xmin"), + xmax = get("xmax"), + y.position = get("ypos") + ), + label = data_brackets$label_re |> unique(), + tip.length = c(-0.01, -0.01), + size = 0.5, + coord.flip = TRUE, + vjust = brackets_vjust, + angle = 90, + label.size = tasklabel_textsize, + lineheight = .8 + ) + } + + # facet by phase + ggplot2::facet_wrap( + ggplot2::vars(get("phase")), + ncol = 1, + scales = "free" + ) + + ggplot2::labs( + x = "", + y = "", + title = "", + colour = col_var + ) + + cols4all::scale_color_discrete_c4a_cat(palette = cols4all_palette) + + ggplot2::theme_bw() + + ggplot2::theme( + panel.grid.major.y = ggplot2::element_blank(), + panel.grid.major.x = if (show_tasks_withoutdate) { + ggplot2::element_blank() + } else { + NULL + }, + panel.grid.minor = ggplot2::element_blank(), + axis.ticks.y = ggplot2::element_blank(), + axis.ticks.x = if (show_tasks_withoutdate) { + ggplot2::element_blank() + } else { + ggplot2::element_line(linewidth = 2) + }, + axis.text.y = ggplot2::element_blank(), + axis.text.x = if (show_tasks_withoutdate) { + ggplot2::element_blank() + } else { + ggplot2::element_text( + angle = 45, + hjust = 1, + size = tasklabel_textsize * 3 + ) + }, + legend.text = ggplot2::element_text( + margin = ggplot2::margin(0, 0, 0, 20, "pt"), + size = tasklabel_textsize * 3 + ), + legend.title = ggplot2::element_text( + size = tasklabel_textsize * 3 + ), + legend.position = "bottom", + strip.background = ggplot2::element_blank(), + strip.text = ggplot2::element_text(size = tasklabel_textsize * 3) + ) + + ggplot2::scale_y_date( + date_labels = "%a %d %b", + limits = c( + date_min - ifelse(show_brackets, 3 * brackets_distance, 0), + date_max + 5 + ), + breaks = data_dates$monday |> na.omit() + ) + + ggplot2::guides(color = ggplot2::guide_legend( + override.aes = list(linewidth = 10, width = 15) + )) + + ggplot2::coord_flip() +} diff --git a/source/report/planning_ganttchart.Rmd b/source/report/planning_ganttchart.Rmd new file mode 100644 index 0000000..eb5270b --- /dev/null +++ b/source/report/planning_ganttchart.Rmd @@ -0,0 +1,55 @@ +--- +title: "Planning" +author: "Janne Adolf" +date: "`r Sys.Date()`" +output: + html_document +knit: (function(inputFile, encoding) { + rmarkdown::render(inputFile, encoding = encoding, output_dir = "../../output") }) + + +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE) +list.files("../functions", full.names = TRUE) |> + lapply(source) |> + invisible() +``` + +```{css, echo=FALSE} +h1, h2 { +margin-top: 50px; +margin-bottom: 25px; +} +``` + + +```{r read-in-sheet} +sheet_url <- paste0( + "https://docs.google.com/spreadsheets/d/", + "1HpDGXbUmCl_KNabdHB9ESW59m6Wc2x1ccQ8uEktDcRY/edit?usp=sharing" +) +data_sheet <- googlesheets4::read_sheet( + ss = sheet_url, + sheet = "algemeen" +) +``` + +## Fase 1 +```{r chart-fase-1, fig.width = 40, fig.height = 25} +make_ganttchart( + data_sheet = data_sheet, + col_var = "trekker", + tasklabel_textsize = 9, + tasklabel_linebreak_nchar = 100, + brackets_vjust = -1, + brackets_distance = 7, + barwidth_scalingfactor = 10, + show_tasks_withoutdate = FALSE +) + ggplot2::theme( + strip.text = ggplot2::element_blank() +) +``` + +