Tools for creating key performance indicator (KPI) reports.
The package can be installed from the CTU Bern universe via
install.packages('kpitools', repos = c('https://ctu-bern.r-universe.dev', 'https://cloud.r-project.org'))The package can also be installed from github via the remotes package
# install.packages("remotes")
remotes::install_github("CTU-Bern/kpitools")Note that remotes treats any warnings (e.g. that a certain package was built under a different version of R) as errors. If you see such an error, run the following line and try again:
Sys.setenv(R_REMOTES_NO_ERRORS_FROM_WARNINGS = "true")The package is loaded, as usual, via
library(kpitools)The main function is the kpi function. A dataframe is passed to it together with the variable that is of interest for the current KPI. A summary function also needs to be passed which determines how the KPI is calculated.
data(mtcars)
mtcars$highmpg <- mtcars$mpg > 20
kpis <- (mtcars %>%
kpi(var = "highmpg", # variable to be summarized (focus of the KPI)
kpi_fn = kpi_fn_perc, # summary function
txt = "Percentage MPG > 20", # (optional) nicer text to add to tables
by = "cyl", # (optional) stratifying variable
breakpoints = c(0,33.3,66.6,100), # (optional) cutoff points
risklabels = c("Low", "Medium", "High"))) # (optional) labels for the cutoff pointsThere is a plot method for the output from kpi which returns a list of ggplot2 objects.
plot <- plot(kpis)
plot$cyl +
theme_kpitools()
For further details, see the vignette:
vignette("kpitools")Acknowledgements
The package logo was created with ggplot2 and hexSticker.
