From 127b41bad032e26a20ff0149a3290ea3f7abdf5a Mon Sep 17 00:00:00 2001 From: Martin Chan Date: Fri, 8 Apr 2022 11:30:33 +0100 Subject: [PATCH] feat: palette argument for `create_trend()` (#188) --- R/create_trend.R | 27 ++++++++++++++++++++++----- man/create_trend.Rd | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/R/create_trend.R b/R/create_trend.R index 10711aeb..fed2a39a 100644 --- a/R/create_trend.R +++ b/R/create_trend.R @@ -14,6 +14,9 @@ #' @template spq-params #' @param metric Character string containing the name of the metric, #' e.g. "Collaboration_hours" +#' @param palette Character vector containing colour codes, ranked from the +#' lowest value to the highest value. This is passed directly to +#' `ggplot2::scale_fill_gradientn()`. #' @param return Character vector specifying what to return, defaults to #' `"plot"`. #' Valid inputs are "plot" and "table". @@ -32,6 +35,19 @@ #' @examples #' create_trend(sq_data, metric = "Collaboration_hours", hrvar = "LevelDesignation") #' +#' # custom colours +#' create_trend( +#' sq_data, +#' metric = "Collaboration_hours", +#' hrvar = "LevelDesignation", +#' palette = c( +#' "#FB6107", +#' "#F3DE2C", +#' "#7CB518", +#' "#5C8001" +#' ) +#' ) +#' #' @return #' Returns a 'ggplot' object by default, where 'plot' is passed in `return`. #' When 'table' is passed, a summary table is returned as a data frame. @@ -42,6 +58,11 @@ create_trend <- function(data, metric, hrvar = "Organization", mingroup = 5, + palette = c("steelblue4", + "aliceblue", + "white", + "mistyrose1", + "tomato1"), return = "plot", legend_title = "Hours"){ @@ -89,11 +110,7 @@ create_trend <- function(data, geom_tile(height=.5) + scale_x_date(position = "top") + scale_fill_gradientn(name = legend_title, - colours = c("steelblue4", - "aliceblue", - "white", - "mistyrose1", - "tomato1")) + + colours = palette) + theme_wpa_basic() + theme(axis.line.y = element_blank(), axis.title.y = element_blank()) + labs(title = clean_nm, diff --git a/man/create_trend.Rd b/man/create_trend.Rd index c05612b5..d1c0a5a9 100644 --- a/man/create_trend.Rd +++ b/man/create_trend.Rd @@ -9,6 +9,7 @@ create_trend( metric, hrvar = "Organization", mingroup = 5, + palette = c("steelblue4", "aliceblue", "white", "mistyrose1", "tomato1"), return = "plot", legend_title = "Hours" ) @@ -26,6 +27,10 @@ instead of splitting by an HR attribute, supply \code{NULL} (without quotes).} \item{mingroup}{Numeric value setting the privacy threshold / minimum group size. Defaults to 5.} +\item{palette}{Character vector containing colour codes, ranked from the +lowest value to the highest value. This is passed directly to +\code{ggplot2::scale_fill_gradientn()}.} + \item{return}{Character vector specifying what to return, defaults to \code{"plot"}. Valid inputs are "plot" and "table".} @@ -46,6 +51,19 @@ table. \examples{ create_trend(sq_data, metric = "Collaboration_hours", hrvar = "LevelDesignation") +# custom colours +create_trend( + sq_data, + metric = "Collaboration_hours", + hrvar = "LevelDesignation", + palette = c( + "#FB6107", + "#F3DE2C", + "#7CB518", + "#5C8001" + ) + ) + } \seealso{ Other Visualization: