Building Control Charts in R for Process Monitoring
- Bernard Kilonzo
- 3 days ago
- 2 min read

What is a Control Chart?
A control chart is a graphical tool used in statistical process control (SPC) to monitor the performance and stability of a process over time. It helps distinguish between normal process variation (common causes) and unusual variation (special causes), enabling timely interventions and continuous improvement.
A control chart is a time-series plot that displays process data points in chronological order, along with three key reference lines:
Center Line (CL): Represents the process average or expected value.
Upper Control Limit (UCL): The threshold above which variation is considered statistically unlikely (typically set at +3 standard deviations from the mean).
Lower Control Limit (LCL): The threshold below which variation is considered statistically unlikely (typically set at −3 standard deviations from the mean).
Example of a Control Chart

Step-by-Step Guide
Load the required libraries.
# load libraries
library(tidyverse)
library(qicharts2)
Load data.
# load data
superstore<-read.csv("https://raw.githubusercontent.com/bernardkilonzo-rigor/dataviz/main/data/Sample%20-%20Superstore.csv")
Extracting week date part from Order Date.
# extracting week date part from order date
superstore<-superstore%>%mutate(Order.Date = dmy(Order.Date))%>%
mutate(week = week(Order.Date))
Computing sales by week, control line (cl), upper control limit (ucl), and lower control limit (lcl).
# computing sales by week, cl, ucl and lcl
super_cal<-superstore%>%group_by(week)%>%
summarise(sales =sum(Sales))%>%
mutate(cl = mean(sales),
sd = sd(sales),
ucl = mean(sales)+2*sd,
lcl = mean(sales)-2*sd)
Creating a basic control chart.
# creating control chart
q<-qic(sales,data = super_cal, chart="xbar")
Executing the above code generates the view below.

Formatting the control chart.
qc<-q+
geom_hline(yintercept = super_cal$ucl, linetype = "dashed", color = "red") +
geom_hline(yintercept = super_cal$lcl, linetype = "dashed", color = "blue")+
geom_hline(yintercept = super_cal$cl, linetype = "solid", color = "black") +
labs(title = "Control Chart with Manual Limits",x = "weeks", y = "Sales", caption = "Viz by: Bernard Kilonzo")+
theme(axis.title = element_text(family = "serif", face = "bold", size = 10, color = "gray30"),
axis.text = element_text(family = "serif", size = 9, color = "gray30"),
plot.title = element_text(family = "serif", face = "bold", size = 13, color = "gray20"),
plot.caption = element_text(family = "serif", face = "italic", size = 9, color = "gray40"))
Executing the above code generates the view below.

Conclusion
Mastering control charts with qicharts2 equips you with a powerful toolkit for tracking process stability and driving data-informed decisions. Its streamlined syntax and thoughtful defaults make it ideal for healthcare, manufacturing, and service industries alike. By integrating statistical rules and visual cues, you can detect meaningful variation and respond proactively. Whether you're building dashboards or conducting quality improvement audits, qicharts2 helps transform routine data into strategic insight - one chart at a time.
If you like the work we do and would like to work with us, drop us an email on our contacts page and we’ll reach out!
Thank you for reading!!