diff --git a/R/create_trend.R b/R/create_trend.R index 20c96501..233d3d39 100644 --- a/R/create_trend.R +++ b/R/create_trend.R @@ -14,8 +14,11 @@ #' @template spq-params #' @param metric Character string containing the name of the metric, #' e.g. "Collaboration_hours" -#' @param return Character vector specifying what to return, defaults to "plot". +#' @param return Character vector specifying what to return, defaults to +#' `"plot"`. #' Valid inputs are "plot" and "table". +#' @param legend_title String to be used as the title of the legend. Defaults to +#' `"Hours"`. #' #' @import dplyr #' @import ggplot2 @@ -39,7 +42,8 @@ create_trend <- function(data, metric, hrvar = "Organization", mingroup = 5, - return = "plot"){ + return = "plot", + legend_title = "Hours"){ ## Check inputs required_variables <- c("Date", @@ -83,10 +87,15 @@ create_trend <- function(data, myTable_plot %>% ggplot(aes(x = Date , y = group , fill = !!sym(metric))) + geom_tile(height=.5) + - scale_x_date(position = "top") + - scale_fill_gradientn(name = "Hours", colours = c("steelblue4","aliceblue","white","mistyrose1","tomato1")) + + scale_x_date(position = "top") + + scale_fill_gradientn(name = legend_title, + colours = c("steelblue4", + "aliceblue", + "white", + "mistyrose1", + "tomato1")) + theme_wpa_basic() + - theme(axis.line.y = element_blank(), axis.title.y = element_blank()) + + theme(axis.line.y = element_blank(), axis.title.y = element_blank()) + labs(title = clean_nm, subtitle = paste("Hotspots by", tolower(camel_clean(hrvar)))) + xlab("Date") + diff --git a/R/hrvar_trend.R b/R/hrvar_trend.R index f3b6c010..03c43d4d 100644 --- a/R/hrvar_trend.R +++ b/R/hrvar_trend.R @@ -6,8 +6,8 @@ #' @title Track count of distinct people over time in a specified HR variable #' #' @description -#' This function provides a week by week view of the count of the distinct people -#' by the specified HR attribute.The default behaviour is to return a +#' This function provides a week by week view of the count of the distinct +#' people by the specified HR attribute.The default behaviour is to return a #' week by week heatmap bar plot. #' #' @param data A Standard Person Query dataset in the form of a data frame. @@ -79,12 +79,25 @@ hrvar_trend <- function(data, if(return == "table"){ - summary_table %>% mutate(PersonId="") %>% create_trend(metric = "n", hrvar = hrvar, mingroup = 0, return = "table") + summary_table %>% + mutate(PersonId = "") %>% + create_trend(metric = "n", + hrvar = hrvar, + mingroup = 0, + return = "table") } else if(return == "plot"){ ## This is re-run to enable multi-attribute grouping without concatenation - summary_table %>% mutate(PersonId="") %>% create_trend(metric = "n", hrvar = hrvar, mingroup = 0, return = "plot") + labs(title = "Employees over time", subtitle = paste("Dynamics by ", tolower(camel_clean(hrvar)))) + summary_table %>% + mutate(PersonId="") %>% + create_trend(metric = "n", + hrvar = hrvar, + mingroup = 0, + return = "plot", + legend_title = "Number of employees") + + labs(title = "Employees over time", + subtitle = paste0("Dynamics by ", tolower(camel_clean(hrvar)))) } else { diff --git a/man/afterhours_trend.Rd b/man/afterhours_trend.Rd index ad7f3c24..48fd1173 100644 --- a/man/afterhours_trend.Rd +++ b/man/afterhours_trend.Rd @@ -16,7 +16,8 @@ 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{return}{Character vector specifying what to return, defaults to "plot". +\item{return}{Character vector specifying what to return, defaults to +\code{"plot"}. Valid inputs are "plot" and "table".} } \value{ diff --git a/man/collaboration_trend.Rd b/man/collaboration_trend.Rd index e5164a58..5eca4a52 100644 --- a/man/collaboration_trend.Rd +++ b/man/collaboration_trend.Rd @@ -21,7 +21,8 @@ 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{return}{Character vector specifying what to return, defaults to "plot". +\item{return}{Character vector specifying what to return, defaults to +\code{"plot"}. Valid inputs are "plot" and "table".} } \value{ diff --git a/man/create_trend.Rd b/man/create_trend.Rd index f38c9a40..634c9fec 100644 --- a/man/create_trend.Rd +++ b/man/create_trend.Rd @@ -9,7 +9,8 @@ create_trend( metric, hrvar = "Organization", mingroup = 5, - return = "plot" + return = "plot", + legend_title = "Hours" ) } \arguments{ @@ -25,8 +26,12 @@ 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{return}{Character vector specifying what to return, defaults to "plot". +\item{return}{Character vector specifying what to return, defaults to +\code{"plot"}. Valid inputs are "plot" and "table".} + +\item{legend_title}{String to be used as the title of the legend. Defaults to +\code{"Hours"}.} } \value{ Returns a 'ggplot' object by default, where 'plot' is passed in \code{return}. diff --git a/man/email_trend.Rd b/man/email_trend.Rd index 1a59aad9..7aabfa60 100644 --- a/man/email_trend.Rd +++ b/man/email_trend.Rd @@ -16,7 +16,8 @@ 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{return}{Character vector specifying what to return, defaults to "plot". +\item{return}{Character vector specifying what to return, defaults to +\code{"plot"}. Valid inputs are "plot" and "table".} } \value{ diff --git a/man/hrvar_trend.Rd b/man/hrvar_trend.Rd index a344414f..4ec1dd4e 100644 --- a/man/hrvar_trend.Rd +++ b/man/hrvar_trend.Rd @@ -32,8 +32,8 @@ argument: } } \description{ -This function provides a week by week view of the count of the distinct people -by the specified HR attribute.The default behaviour is to return a +This function provides a week by week view of the count of the distinct +people by the specified HR attribute.The default behaviour is to return a week by week heatmap bar plot. } \examples{ diff --git a/man/meeting_trend.Rd b/man/meeting_trend.Rd index affb093d..abdc6559 100644 --- a/man/meeting_trend.Rd +++ b/man/meeting_trend.Rd @@ -16,7 +16,8 @@ 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{return}{Character vector specifying what to return, defaults to "plot". +\item{return}{Character vector specifying what to return, defaults to +\code{"plot"}. Valid inputs are "plot" and "table".} } \value{ diff --git a/man/one2one_trend.Rd b/man/one2one_trend.Rd index b8483291..61cd3e45 100644 --- a/man/one2one_trend.Rd +++ b/man/one2one_trend.Rd @@ -16,7 +16,8 @@ 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{return}{Character vector specifying what to return, defaults to "plot". +\item{return}{Character vector specifying what to return, defaults to +\code{"plot"}. Valid inputs are "plot" and "table".} } \value{ diff --git a/man/workloads_trend.Rd b/man/workloads_trend.Rd index 4ed54a7b..1fa1bd92 100644 --- a/man/workloads_trend.Rd +++ b/man/workloads_trend.Rd @@ -16,7 +16,8 @@ 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{return}{Character vector specifying what to return, defaults to "plot". +\item{return}{Character vector specifying what to return, defaults to +\code{"plot"}. Valid inputs are "plot" and "table".} } \value{