From 8dcf7c74ec4d30c1cc78fbfc81477856ad901692 Mon Sep 17 00:00:00 2001 From: erstearns Date: Fri, 28 Jun 2024 14:18:59 -0400 Subject: [PATCH 1/6] added colour_by arg and adjusted code to define colour_field using the arg and set palette to correct number of unique vals and changed names to match unique vals of colour_by arg --- R/ganttrify.R | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/R/ganttrify.R b/R/ganttrify.R index 437d190..4d11cf6 100644 --- a/R/ganttrify.R +++ b/R/ganttrify.R @@ -14,6 +14,7 @@ #' @param project_start_date The date when the project starts. It can be a date, #' or a string in the format "2020-03" or "2020-03-01". Ignored if #' `month_number_date` is set to FALSE. +#' @param colour_by The input data field that should inform colours. Default being project$wp #' @param colour_palette A character vector of colours or a colour palette. If #' necessary, colours are recycled as needed. Defaults to #' `wesanderson::wes_palette("Darjeeling1")`. For more palettes, consider also @@ -109,6 +110,7 @@ ganttrify <- function(project, by_date = FALSE, exact_date = FALSE, project_start_date = Sys.Date(), + colour_by = "wp", colour_palette = wesanderson::wes_palette("Darjeeling1"), font_family = "sans", mark_quarters = FALSE, @@ -139,6 +141,7 @@ ganttrify <- function(project, month_breaks = 1, show_vertical_lines = TRUE, axis_text_align = "right") { + # use gannt_verify function (written in eponymously named script) to ensure input data is formatted properly project <- gantt_verify( project = project, by_date = by_date, @@ -149,11 +152,24 @@ ganttrify <- function(project, if (hide_wp & hide_activities) { cli::cli_abort("At least one of {.arg hide_wp} or {.arg hide_activities} must be {.code TRUE}, otherwise there's nothing left to show.") } - - # repeat colours if not enough colours given - colour_palette <- rep(colour_palette, length(unique(project$wp)))[1:length(unique(project$wp))] - names(colour_palette) <- colour_palette - + + #define colour field as colour_by arg indicates + colour_field <- unique(project[[colour_by]]) + + # repeat colours if not enough colours given ------------------- NOTE -- if trying to use colour to uniquely + # identify groups, then repeating colour will not work + if(length(colour_palette != length(colour_field))){ + message("You do not have the same number of colours in your palette as unique values of your colour_by var. Repeating palette as needed to match number of unique colour_by values.") + # repear colours if needed + colour_palette <- rep(colour_palette, length(colour_field))[1:length(colour_field)] + # Name colours using the colour_by field mapped to said color + names(colour_palette) <- colour_field # -------------------- NOTE: will want to verify if this works when things actually coloured + #names(colour_palette) <- colour_palette + } else { + message("Hooray! You have the same number of colours in your palette as unique values of your colour_by var.") + names(colour_palette) <- colour_field + } + if (is.null(line_end) == FALSE) { line_end_wp <- line_end line_end_activity <- line_end From ccae903c6ce948b6d8168f2619cc4b4ec44a24ad Mon Sep 17 00:00:00 2001 From: erstearns Date: Fri, 28 Jun 2024 16:10:14 -0400 Subject: [PATCH 2/6] added lots of comments to help my future self remember what everything is doing and also added order_by arg to function and testing as i go --- R/ganttrify.R | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/R/ganttrify.R b/R/ganttrify.R index 4d11cf6..e3c76bf 100644 --- a/R/ganttrify.R +++ b/R/ganttrify.R @@ -22,6 +22,7 @@ #' MetBrewer::met.brewer("Lakota")`. Colours can be passed as a vector of hex #' codes (e.g. `colour_palette = c("#6ACCEA", "#00FFB8", "#B90000", #' "#6C919C")`) +#' @param order_by How should the bars in the chart be ordered? Character indicating field name to order by; default is by activity #' @param font_family A character vector of length 1, defaults to "sans". It is #' recommended to use a narrow/condensed font such as Roboto Condensed for #' more efficient use of text space. @@ -112,6 +113,7 @@ ganttrify <- function(project, project_start_date = Sys.Date(), colour_by = "wp", colour_palette = wesanderson::wes_palette("Darjeeling1"), + order_by = NULL, font_family = "sans", mark_quarters = FALSE, mark_years = FALSE, @@ -170,11 +172,13 @@ ganttrify <- function(project, names(colour_palette) <- colour_field } + #Defining line endings (round or butt) if (is.null(line_end) == FALSE) { line_end_wp <- line_end line_end_activity <- line_end } + # ensuring fields are proper type based on whether the dates are already formatted if (by_date == FALSE) { df <- project %>% dplyr::mutate( @@ -218,6 +222,7 @@ ganttrify <- function(project, } if (exact_date == TRUE) { + # ensure df is properly formatted - dates are dates, wp & project are characters df <- project %>% dplyr::mutate( start_date = as.Date(start_date), @@ -226,6 +231,7 @@ ganttrify <- function(project, activity = as.character(activity) ) + # create a df that pushes start date to earliest day of indicated month, and end date to latest day of indicated month df_yearmon <- df %>% dplyr::mutate( start_date = zoo::as.Date(zoo::as.yearmon(start_date), frac = 0), @@ -233,12 +239,14 @@ ganttrify <- function(project, ) } + # create ordered character vector of the first day of the month dates from start of df time period to end sequence_months <- seq.Date( from = min(df_yearmon[["start_date"]]), to = max(df_yearmon[["end_date"]]), by = "1 month" ) + # modify sequence_months if an odd number of months by adding one month to end date if (length(sequence_months) %% 2 != 0) { sequence_months <- seq.Date( from = min(df_yearmon[["start_date"]]), @@ -247,11 +255,13 @@ ganttrify <- function(project, ) } + # not sure why this is done ---------------------------------- NOTE: figure out purpose of this matrix date_range_matrix <- matrix(as.numeric(sequence_months), ncol = 2, byrow = TRUE ) + # create tibble using matrix containing only start and end dates --- NOTE: why not just subset to date cols and rename from df_yearmon? date_range_df <- tibble::tibble( start = zoo::as.Date.numeric(date_range_matrix[, 1]), end = zoo::as.Date.numeric(date_range_matrix[, 2]) @@ -265,12 +275,16 @@ ganttrify <- function(project, )), frac = 0.5) + # create vector of quarter date breaks corresponding to start of first year in start_date to start of year following end date + # -- used for mark_quarter = TRUE arg date_breaks_q <- seq.Date( from = lubridate::floor_date(x = min(df_yearmon[["start_date"]]), unit = "year"), to = lubridate::ceiling_date(x = max(df_yearmon[["end_date"]]), unit = "year"), by = "1 quarter" ) + # create vector of year start date breaks corresponding to start of first year in start_date to start of year following end date + # -- used for mark_year = TRUE arg date_breaks_y <- seq.Date( from = lubridate::floor_date(x = min(df_yearmon[["start_date"]]), unit = "year"), to = lubridate::ceiling_date(x = max(df_yearmon[["end_date"]]), unit = "year"), @@ -292,6 +306,7 @@ ganttrify <- function(project, dplyr::ungroup() %>% dplyr::mutate(gantt_colour = colour_palette) + #mapping colours to wp (?) distinct_colours_df <- dplyr::bind_rows( distinct_yearmon_levels_df %>% dplyr::transmute( @@ -306,6 +321,7 @@ ganttrify <- function(project, ) ) + # tibble with unduplicated wp name and list of corresponding activities per unique wp distinct_yearmon_labels_df <- df_yearmon %>% dplyr::distinct(wp, activity) %>% dplyr::group_by(wp) %>% @@ -316,10 +332,12 @@ ganttrify <- function(project, by = "wp" ) + # adding html code to wp values to enable bold script upon rendering if arg set to true if (wp_label_bold) { distinct_yearmon_labels_df <- distinct_yearmon_labels_df %>% dplyr::mutate(wp = stringr::str_c("", wp, "")) + #if adding spots if (is.null(spots) == FALSE) { wp_v <- project %>% dplyr::distinct(wp) %>% @@ -329,11 +347,13 @@ ganttrify <- function(project, } } + # creating tibble of labels level_labels_df <- tibble::tibble( levels = rev(unlist(t(matrix(c(distinct_yearmon_levels_df$wp, distinct_yearmon_levels_df$wp_activity), ncol = 2)))), labels = rev(unlist(t(matrix(c(distinct_yearmon_labels_df$wp, distinct_yearmon_labels_df$activity), ncol = 2)))) ) + # if indicated to wrap labels, then setting arg 'label_wrap' to character count at which to wrap and setting labels to wrap using html code if (label_wrap != FALSE) { if (isTRUE(label_wrap)) { label_wrap <- 32 @@ -347,7 +367,8 @@ ganttrify <- function(project, spots$activity <- stringr::str_replace_all(string = spots$activity, pattern = "\n", replacement = "
") } } - + + # creating df input for plotting -- here at the end, rows are ordered by activity, which has the WP appended to it if (exact_date == TRUE) { df_yearmon_fct <- dplyr::bind_rows( @@ -369,6 +390,7 @@ ganttrify <- function(project, ) %>% dplyr::mutate(activity = factor(x = activity, levels = level_labels_df$levels)) %>% dplyr::arrange(activity) + } else { df_yearmon_fct <- dplyr::bind_rows( @@ -392,17 +414,25 @@ ganttrify <- function(project, dplyr::arrange(activity) } - + # arrange/order as arg indicates + if(is.null(order_by) == FALSE){ + df_yearmon_fct <- df_yearmon_fct %>% + dplyr::arrange(df_yearmon_fct[[order_by]]) + } + + # If hiding WP labels and rows, then must remove them from plotting df if (hide_wp == TRUE) { df_yearmon_fct <- df_yearmon_fct %>% dplyr::filter(type != "wp") } + # If hiding activity labels and rows, then must remove them from plotting df if (hide_activities == TRUE) { df_yearmon_fct <- df_yearmon_fct %>% dplyr::filter(type != "activity") } +# -------------------------------------------- LET THE PLOTTING BEGIN ----------------------------------- gg_gantt <- ggplot2::ggplot( data = df_yearmon_fct, mapping = ggplot2::aes( From 745c6ff2f319776ce9ccc6c1c6280a02ce5901b9 Mon Sep 17 00:00:00 2001 From: erstearns Date: Fri, 28 Jun 2024 17:15:46 -0400 Subject: [PATCH 3/6] figured out how to get colour mapping mapped to colour field properly and coded up the inclusion of a legend --- R/ganttrify.R | 88 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 18 deletions(-) diff --git a/R/ganttrify.R b/R/ganttrify.R index e3c76bf..f86c512 100644 --- a/R/ganttrify.R +++ b/R/ganttrify.R @@ -23,6 +23,8 @@ #' codes (e.g. `colour_palette = c("#6ACCEA", "#00FFB8", "#B90000", #' "#6C919C")`) #' @param order_by How should the bars in the chart be ordered? Character indicating field name to order by; default is by activity +#' @param include_legend TRUE/FALSE -- keep legend or not? +#' @param legend_title Character with title to add to top of legend if keeping one #' @param font_family A character vector of length 1, defaults to "sans". It is #' recommended to use a narrow/condensed font such as Roboto Condensed for #' more efficient use of text space. @@ -114,6 +116,8 @@ ganttrify <- function(project, colour_by = "wp", colour_palette = wesanderson::wes_palette("Darjeeling1"), order_by = NULL, + include_legend = FALSE, + legend_title = NULL, font_family = "sans", mark_quarters = FALSE, mark_years = FALSE, @@ -170,6 +174,7 @@ ganttrify <- function(project, } else { message("Hooray! You have the same number of colours in your palette as unique values of your colour_by var.") names(colour_palette) <- colour_field + #names(colour_palette) <- colour_palette } #Defining line endings (round or butt) @@ -433,6 +438,7 @@ ganttrify <- function(project, } # -------------------------------------------- LET THE PLOTTING BEGIN ----------------------------------- + #initial base gg plot gg_gantt <- ggplot2::ggplot( data = df_yearmon_fct, mapping = ggplot2::aes( @@ -440,7 +446,8 @@ ganttrify <- function(project, y = activity, xend = end_date, yend = activity, - colour = gantt_colour + #colour = gantt_colour + colour = .data[[colour_by]] ) ) + # background shaded bands @@ -474,6 +481,8 @@ ganttrify <- function(project, df_yearmon_fct <- df_yearmon_fct %>% dplyr::mutate(wp_alpha = ifelse(type == "wp", alpha_wp, 0)) + # adding lines for each project ------------------------NOTE: legend exists here, and shows values of hex codes, + # also seems the order of projects is not corresponding to start date but are instead grouped by WP again if (utils::packageVersion("ggplot2") > "3.3.6") { gg_gantt <- gg_gantt + ### activities @@ -508,6 +517,7 @@ ganttrify <- function(project, ) } + # X-axis labels -- just years? years + relative month number? month date? if (month_number_label == TRUE & month_date_label == TRUE) { gg_gantt <- gg_gantt + ggplot2::scale_x_date( @@ -540,6 +550,7 @@ ganttrify <- function(project, ggplot2::scale_x_date(name = NULL) } + # align y axis labels if (axis_text_align == "right") { axis_text_align_n <- 1 } else if (axis_text_align == "centre" | axis_text_align == "center") { @@ -550,23 +561,64 @@ ganttrify <- function(project, axis_text_align_n <- 1 } - gg_gantt <- gg_gantt + - ggplot2::scale_y_discrete( - name = NULL, - breaks = level_labels_df$levels, - labels = level_labels_df$labels - ) + - ggplot2::theme_minimal() + - ggplot2::scale_colour_manual(values = colour_palette) + - ggplot2::theme( - text = ggplot2::element_text(family = font_family), - axis.text.y.left = ggtext::element_markdown( - size = ggplot2::rel(size_text_relative), - hjust = axis_text_align_n - ), - axis.text.x = ggplot2::element_text(size = ggplot2::rel(size_text_relative)), - legend.position = "none" - ) + # updating plot aesthetics: + # project labels - removing WP appended label, wrapping text, and other markdown/html encoded functionalities + # color project lines by WP/colour field + # legend + if(include_legend == TRUE & is.null(legend_title) == FALSE){ + gg_gantt <- gg_gantt + + ggplot2::scale_y_discrete( + name = NULL, + breaks = level_labels_df$levels, + labels = level_labels_df$labels + ) + + ggplot2::theme_minimal() + + ggplot2::scale_colour_manual(values = colour_palette, name = (legend_title)) + + ggplot2::theme( + text = ggplot2::element_text(family = font_family), + axis.text.y.left = ggtext::element_markdown( + size = ggplot2::rel(size_text_relative), + hjust = axis_text_align_n + ), + axis.text.x = ggplot2::element_text(size = ggplot2::rel(size_text_relative)) + ) + } else if(include_legend == TRUE & is.null(legend_title) == TRUE){ + gg_gantt <- gg_gantt + + ggplot2::scale_y_discrete( + name = NULL, + breaks = level_labels_df$levels, + labels = level_labels_df$labels + ) + + ggplot2::theme_minimal() + + ggplot2::scale_colour_manual(values = colour_palette, name = "") + + ggplot2::theme( + text = ggplot2::element_text(family = font_family), + axis.text.y.left = ggtext::element_markdown( + size = ggplot2::rel(size_text_relative), + hjust = axis_text_align_n + ), + axis.text.x = ggplot2::element_text(size = ggplot2::rel(size_text_relative)) + ) + } else if(include_legend == FALSE){ + gg_gantt <- gg_gantt + + ggplot2::scale_y_discrete( + name = NULL, + breaks = level_labels_df$levels, + labels = level_labels_df$labels + ) + + ggplot2::theme_minimal() + + ggplot2::scale_colour_manual(values = colour_palette, name = "") + + ggplot2::theme( + text = ggplot2::element_text(family = font_family), + axis.text.y.left = ggtext::element_markdown( + size = ggplot2::rel(size_text_relative), + hjust = axis_text_align_n + ), + axis.text.x = ggplot2::element_text(size = ggplot2::rel(size_text_relative)), + legend.position = "none" + ) + } + if (is.null(spots) == FALSE) { if (is.data.frame(spots) == TRUE) { From 5b6a0a3a94c01352775c7793f9ddbdfbf26c9d01 Mon Sep 17 00:00:00 2001 From: erstearns Date: Fri, 28 Jun 2024 18:21:42 -0400 Subject: [PATCH 4/6] tested in full and all is working now! --- R/ganttrify.R | 93 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 31 deletions(-) diff --git a/R/ganttrify.R b/R/ganttrify.R index f86c512..b385b61 100644 --- a/R/ganttrify.R +++ b/R/ganttrify.R @@ -23,6 +23,7 @@ #' codes (e.g. `colour_palette = c("#6ACCEA", "#00FFB8", "#B90000", #' "#6C919C")`) #' @param order_by How should the bars in the chart be ordered? Character indicating field name to order by; default is by activity +#' @param order_ascending TRUE/FALSE - ascending = TRUE, descending = FALSE #' @param include_legend TRUE/FALSE -- keep legend or not? #' @param legend_title Character with title to add to top of legend if keeping one #' @param font_family A character vector of length 1, defaults to "sans". It is @@ -116,6 +117,7 @@ ganttrify <- function(project, colour_by = "wp", colour_palette = wesanderson::wes_palette("Darjeeling1"), order_by = NULL, + order_ascending = NULL, include_legend = FALSE, legend_title = NULL, font_family = "sans", @@ -169,12 +171,10 @@ ganttrify <- function(project, # repear colours if needed colour_palette <- rep(colour_palette, length(colour_field))[1:length(colour_field)] # Name colours using the colour_by field mapped to said color - names(colour_palette) <- colour_field # -------------------- NOTE: will want to verify if this works when things actually coloured - #names(colour_palette) <- colour_palette + names(colour_palette) <- colour_field } else { message("Hooray! You have the same number of colours in your palette as unique values of your colour_by var.") names(colour_palette) <- colour_field - #names(colour_palette) <- colour_palette } #Defining line endings (round or butt) @@ -419,12 +419,17 @@ ganttrify <- function(project, dplyr::arrange(activity) } - # arrange/order as arg indicates - if(is.null(order_by) == FALSE){ + # arrange/order as arg indicates then create a row enumeration by which to order within ggplot calls + if(is.null(order_by) == FALSE & order_ascending == TRUE){ + df_yearmon_fct <- df_yearmon_fct %>% + dplyr::arrange(df_yearmon_fct[[order_by]]) %>% + mutate(order_id = row_number()) + } else if (is.null(order_by) == FALSE & order_ascending == FALSE){ df_yearmon_fct <- df_yearmon_fct %>% - dplyr::arrange(df_yearmon_fct[[order_by]]) + dplyr::arrange(desc(df_yearmon_fct[[order_by]])) %>% + mutate(order_id = row_number()) } - + # If hiding WP labels and rows, then must remove them from plotting df if (hide_wp == TRUE) { df_yearmon_fct <- df_yearmon_fct %>% @@ -439,29 +444,55 @@ ganttrify <- function(project, # -------------------------------------------- LET THE PLOTTING BEGIN ----------------------------------- #initial base gg plot - gg_gantt <- ggplot2::ggplot( - data = df_yearmon_fct, - mapping = ggplot2::aes( - x = start_date, - y = activity, - xend = end_date, - yend = activity, - #colour = gantt_colour - colour = .data[[colour_by]] - ) - ) + - # background shaded bands - ggplot2::geom_rect( - data = date_range_df, ggplot2::aes( - xmin = start, - xmax = end, - ymin = -Inf, - ymax = Inf - ), - inherit.aes = FALSE, - alpha = 0.4, - fill = colour_stripe - ) + if(is.null(order_by) == FALSE){ + gg_gantt <- ggplot2::ggplot( + data = df_yearmon_fct, + mapping = ggplot2::aes( + x = start_date, + y = reorder(activity, order_id), + xend = end_date, + yend = activity, + #colour = gantt_colour + colour = .data[[colour_by]] + ) + ) + + # background shaded bands + ggplot2::geom_rect( + data = date_range_df, ggplot2::aes( + xmin = start, + xmax = end, + ymin = -Inf, + ymax = Inf + ), + inherit.aes = FALSE, + alpha = 0.4, + fill = colour_stripe + ) + } else { + gg_gantt <- ggplot2::ggplot( + data = df_yearmon_fct, + mapping = ggplot2::aes( + x = start_date, + y = activity, + xend = end_date, + yend = activity, + #colour = gantt_colour + colour = .data[[colour_by]] + ) + ) + + # background shaded bands + ggplot2::geom_rect( + data = date_range_df, ggplot2::aes( + xmin = start, + xmax = end, + ymin = -Inf, + ymax = Inf + ), + inherit.aes = FALSE, + alpha = 0.4, + fill = colour_stripe + ) + } if (mark_quarters == TRUE) { gg_gantt <- gg_gantt + @@ -517,7 +548,7 @@ ganttrify <- function(project, ) } - # X-axis labels -- just years? years + relative month number? month date? + # X-axis labels -- just years? years + relative month number? month date? As user specifies in function args if (month_number_label == TRUE & month_date_label == TRUE) { gg_gantt <- gg_gantt + ggplot2::scale_x_date( From 142184da6548cd5cd19ed37244be5ee59c53fb9e Mon Sep 17 00:00:00 2001 From: erstearns Date: Tue, 16 Jul 2024 16:21:01 -0400 Subject: [PATCH 5/6] added new arg to allow user to add borders to lines by creating new shape 1 width unit larger than the original line --- R/ganttrify.R | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/R/ganttrify.R b/R/ganttrify.R index b385b61..5b83685 100644 --- a/R/ganttrify.R +++ b/R/ganttrify.R @@ -49,6 +49,10 @@ #' @param size_text_relative Numeric, defaults to 1. Changes the size of all #' textual elements relative to their default size. If you set this to e.g. #' 1.5 all text elements will be 50\% bigger. +#' @param add_border Default set to FALSE, but if TRUE, adds a gray border +#' around each line by creating a gray line shape under the activity using +#' size_activity + 1 for setting size. Could eventually add more args here to +#' let user determine color and width. #' @param label_wrap Defaults to FALSE. If given, must be numeric, referring to #' the number of characters per line allowed in the labels of projects and #' activities, or logical (if set to TRUE, it will default to 32). To be used @@ -129,6 +133,7 @@ ganttrify <- function(project, wp_label_bold = TRUE, size_activity = 4, size_text_relative = 1, + add_border = FALSE, label_wrap = FALSE, month_number_label = TRUE, month_label_string = "M", @@ -514,7 +519,7 @@ ganttrify <- function(project, # adding lines for each project ------------------------NOTE: legend exists here, and shows values of hex codes, # also seems the order of projects is not corresponding to start date but are instead grouped by WP again - if (utils::packageVersion("ggplot2") > "3.3.6") { + if (utils::packageVersion("ggplot2") > "3.3.6" & add_border == FALSE) { gg_gantt <- gg_gantt + ### activities ggplot2::geom_segment( @@ -530,6 +535,55 @@ ganttrify <- function(project, linewidth = size_wp, alpha = df_yearmon_fct$wp_alpha ) + } else if (utils::packageVersion("ggplot2") > "3.3.6" & add_border == TRUE){ + gg_gantt <- gg_gantt + + ### background -- acts like an outline + ggplot2::geom_segment( + data = df_yearmon_fct, + lineend = line_end_activity, + linewidth = (size_activity + 1), + alpha = df_yearmon_fct$activity_alpha, + colour = "gray" + ) + + ### activities + ggplot2::geom_segment( + data = df_yearmon_fct, + lineend = line_end_activity, + linewidth = size_activity, + alpha = df_yearmon_fct$activity_alpha + ) + + ### wp + ggplot2::geom_segment( + data = df_yearmon_fct, + lineend = line_end_wp, + linewidth = size_wp, + alpha = df_yearmon_fct$wp_alpha + ) + + } else if (utils::packageVersion("ggplot2") <= "3.3.6" & add_border == TRUE){ + gg_gantt <- gg_gantt + + ### background -- acts like an outline + ggplot2::geom_segment( + data = df_yearmon_fct, + lineend = line_end_activity, + size = (size_activity + 1), + alpha = df_yearmon_fct$activity_alpha, + colour = "gray" + ) + + ### activities + ggplot2::geom_segment( + data = df_yearmon_fct, + lineend = line_end_activity, + size = size_activity, + alpha = df_yearmon_fct$activity_alpha + ) + + ### wp + ggplot2::geom_segment( + data = df_yearmon_fct, + lineend = line_end_wp, + size = size_wp, + alpha = df_yearmon_fct$wp_alpha + ) } else { gg_gantt <- gg_gantt + ### activities From 5fac2efba88202a29ab5e88258f8483d9f342b83 Mon Sep 17 00:00:00 2001 From: erstearns Date: Tue, 16 Jul 2024 16:33:12 -0400 Subject: [PATCH 6/6] found error in code to check number of colors in pal against number of unique wp- corrected --- R/ganttrify.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/ganttrify.R b/R/ganttrify.R index 5b83685..39118c5 100644 --- a/R/ganttrify.R +++ b/R/ganttrify.R @@ -171,7 +171,7 @@ ganttrify <- function(project, # repeat colours if not enough colours given ------------------- NOTE -- if trying to use colour to uniquely # identify groups, then repeating colour will not work - if(length(colour_palette != length(colour_field))){ + if(length(colour_palette) != length(colour_field)){ message("You do not have the same number of colours in your palette as unique values of your colour_by var. Repeating palette as needed to match number of unique colour_by values.") # repear colours if needed colour_palette <- rep(colour_palette, length(colour_field))[1:length(colour_field)]