зеркало из https://github.com/microsoft/wpa.git
feat: make create_dist dynamic
Changes to underlying cut_hour()
This commit is contained in:
Родитель
c576738995
Коммит
31d0165c0c
|
@ -81,23 +81,22 @@ create_dist <- function(data,
|
|||
## Create buckets of collaboration hours
|
||||
plot_data <-
|
||||
plot_data %>%
|
||||
mutate(bucket_hours = cut_hour(!!sym(metric),
|
||||
cuts = cut))
|
||||
mutate(bucket_hours = cut_hour(!!sym(metric), cuts = cut))
|
||||
|
||||
## Employee count / base size table
|
||||
plot_legend <-
|
||||
plot_data %>%
|
||||
group_by(group) %>%
|
||||
summarize(Employee_Count=first(Employee_Count)) %>%
|
||||
summarize(Employee_Count = first(Employee_Count)) %>%
|
||||
mutate(Employee_Count = paste("n=",Employee_Count))
|
||||
|
||||
## Data for bar plot
|
||||
plot_table <-
|
||||
plot_data %>%
|
||||
group_by(group, bucket_hours) %>%
|
||||
summarize(Employees=n(),
|
||||
Employee_Count=first(Employee_Count),
|
||||
percent= Employees / Employee_Count ) %>%
|
||||
summarize(Employees = n(),
|
||||
Employee_Count = first(Employee_Count),
|
||||
percent = Employees / Employee_Count ) %>%
|
||||
arrange(group, desc(bucket_hours))
|
||||
|
||||
## Table for annotation
|
||||
|
|
41
R/cut_hour.R
41
R/cut_hour.R
|
@ -10,7 +10,7 @@
|
|||
#' and the function returns a character vector
|
||||
#'
|
||||
#' @param metric A numeric variable representing hours.
|
||||
#' @param cuts A numeric variable of length 3 to represent the
|
||||
#' @param cuts A numeric variable of minimum length 3 to represent the
|
||||
#' cut points required.
|
||||
#'
|
||||
#' @family General
|
||||
|
@ -27,22 +27,33 @@
|
|||
cut_hour <- function(metric, cuts){
|
||||
|
||||
|
||||
label1 <- paste0("< ", cuts[1], " hours")
|
||||
label2 <- paste0(cuts[1], " - ", cuts[2], " hours")
|
||||
label3 <- paste0(cuts[2], " - ", cuts[3], " hours")
|
||||
label4 <- paste0(cuts[3], "+ hours")
|
||||
cuts <- unique(cuts) # No duplicates allowed
|
||||
ncuts <- length(cuts)
|
||||
|
||||
out <-
|
||||
cut(metric,
|
||||
breaks = c(0, cuts, 100),
|
||||
include.lowest = TRUE,
|
||||
labels = c(label1,
|
||||
label2,
|
||||
label3,
|
||||
label4))
|
||||
if(ncuts < 3){
|
||||
stop("Please provide a numeric vector of at least length 3 to `cuts`")
|
||||
}
|
||||
|
||||
# out <- as.character(out)
|
||||
return(out)
|
||||
|
||||
# Extract min, max, and middle values
|
||||
mincut <- min(cuts, na.rm = TRUE)
|
||||
maxcut <- max(cuts, na.rm = TRUE)
|
||||
midcut <- cuts[!cuts %in% mincut] # Excludes mincut only
|
||||
midcut_min_1 <- cuts[match(midcut, cuts) - 1] # one value smaller
|
||||
|
||||
# Individual labels
|
||||
label_mincut <- paste0("< ", mincut, " hours")
|
||||
label_maxcut <- paste0(maxcut, "+ hours")
|
||||
label_midcut <- paste0(midcut_min_1, " - ", midcut, " hours")
|
||||
|
||||
# All labels
|
||||
all_labels <- c(label_mincut, label_midcut, label_maxcut)
|
||||
|
||||
|
||||
cut(metric,
|
||||
breaks = c(0, cuts, 100),
|
||||
include.lowest = TRUE,
|
||||
labels = all_labels)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ cut_hour(metric, cuts)
|
|||
\arguments{
|
||||
\item{metric}{A numeric variable representing hours.}
|
||||
|
||||
\item{cuts}{A numeric variable of length 3 to represent the
|
||||
\item{cuts}{A numeric variable of minimum length 3 to represent the
|
||||
cut points required.}
|
||||
}
|
||||
\description{
|
||||
|
|
|
@ -34,6 +34,15 @@ for the Analyst pre-analysis.
|
|||
For your input data or meeting_data, please use the function wpa::import_wpa()'
|
||||
to import your csv query files into R. This function will standardize format
|
||||
and prepare the data as input for this report.
|
||||
}
|
||||
\examples{
|
||||
\dontrun{
|
||||
validation_report(dv_data,
|
||||
meeting_data = mt_data,
|
||||
hrvar = "Organization")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
\seealso{
|
||||
Other Reports:
|
||||
|
|
Загрузка…
Ссылка в новой задаче