зеркало из https://github.com/microsoft/wpa.git
fix: legend for hrvar_trend
Legend now shows "Number of employees" rather than "Hours". This adds a new argument to the function `create_trend()`.
This commit is contained in:
Родитель
08f92fe5f0
Коммит
30177dc8a6
|
@ -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") +
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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}.
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
Загрузка…
Ссылка в новой задаче