anhoej / qicharts2

R package: Quality improvement charts
38 stars 12 forks source link

Format y as percentage automatically for p charts #6

Closed pwildenhain closed 6 years ago

pwildenhain commented 6 years ago

Great job on this package! We are going to start using this at my job as the standard for spc graphing in R.

We usually p-charts frequently, and it would be nice if when we have chart = 'p' or chart = 'pp', the y-axis was automatically formatted as a percentage.

pwildenhain commented 6 years ago

Here is a recreated example from a p-chart in your vignette

# Load my local changes and libs----
devtools::load_all()
library(dplyr)
# Recreate example from vignette----
# Link to vignette https://cran.r-project.org/web/packages/qicharts2/vignettes/qicharts2.html
cabg <- cabg %>% 
  mutate(month = as.Date(cut(date, 'month')))

cabg_by_month <- cabg %>% 
  group_by(month) %>% 
  summarise(deaths       = sum(death),
            readmissions = sum(readmission),
            n            = n())

qic(month, deaths, n,
    data      = cabg_by_month,
    chart     = 'p',
    y.percent = TRUE,
    title     = '30 days mortality (P chart)',
    ylab      = NULL,
    xlab      = 'Month')
# Test changes, remove y.percent----
# My change will automatically set y.percent to TRUE since p-chart was chosen
qic(month, deaths, n,
    data      = cabg_by_month,
    chart     = 'p',
    title     = '30 days mortality (P chart)',
    ylab      = NULL,
    xlab      = 'Month')

# Test changes, set y.percent FALSE----
# My change will leave y.percent alone since it's set to false
qic(month, deaths, n,
    data      = cabg_by_month,
    chart     = 'p',
    y.percent = FALSE,    
    title     = '30 days mortality (P chart)',
    ylab      = NULL,
    xlab      = 'Month')