Produce QC charts with ggplot framework. Support for faceting and layering of multiple QC chart lines on a single plot. Charts supported (see method argument for call):
To label chart lines see stat_QC_labels
stat_QC(mapping = NULL, data = NULL, geom = "hline",
position = "identity", na.rm = FALSE, show.legend = NA,
inherit.aes = TRUE, n = NULL, method = "xBar.rBar",
color.qc_limits = "red", color.qc_center = "green", ...)
n: number, for
method : string, calling the following methods:
…: other arguments passed on to layer. These are often aesthetics, used to set an aesthetic to a fixed value, like color = “red” or size = 3. They may also be parameters to the paired geom/stat.
# Setup Data --------------------------------------------------------------
set.seed(5555)
Process1 <- data.frame(processID = as.factor(rep(1,100)),
metric_value = rnorm(100,0,1),
subgroup_sample=rep(1:20, each=5),
Process_run_id = 1:100)
#INDV
INDV <- ggplot(Process1, aes(x=Process_run_id, y = metric_value)) +
geom_point() + geom_line() +
ggtitle("XmR", "geom_point() and geom_line() required") +
ylim(-3,3) + #make scales same
scale_x_continuous(expand = expand_scale(mult = .15)) #pad x-axis
#xBar
xBar <- ggplot(Process1, aes(x=subgroup_sample, y = metric_value)) +
ggtitle("xBar.rBar", subtitle = "Yes, it's blank, go to next section") +
ylim(-3,3) + #make scales same
scale_x_continuous(expand = expand_scale(mult = .15)) #pad x-axis
#put both plots side by side for comparison
gridExtra::grid.arrange(INDV, xBar, nrow=1)
#XmR
INDV2 <- INDV + stat_QC(method="XmR") +
ggtitle("XmR", subtitle = "Default QC lines")
#xBar.rBar
xBar2 <- xBar + stat_QC(method="xBar.rBar") +
ggtitle("xBar.rBar", subtitle = "Default QC lines")
#put both plots side by side for comparison
gridExtra::grid.arrange(INDV2, xBar2, nrow=1)
#XmR
INDV2 <- INDV + stat_QC(method="XmR", auto.label = T) +
ggtitle("XmR", subtitle = "Auto Label QC lines")
#xBar.rBar
xBar2 <- xBar + stat_QC(method="xBar.rBar", auto.label = T) +
ggtitle("xBar.rBar", subtitle = "Auto Label QC lines")
#put both plots side by side for comparison
gridExtra::grid.arrange(INDV2, xBar2, nrow=1)
#XmR
INDV2 <- INDV + stat_QC(method="XmR", auto.label = T , show.1n2.sigma = T) +
ggtitle("XmR", subtitle = "show.1n2.sigma = T")
#xBar.rBar
xBar2 <- xBar + stat_QC(method="xBar.rBar", auto.label = T, show.1n2.sigma = T) +
ggtitle("xBar.rBar", subtitle = "show.1n2.sigma = T")
#put both plots side by side for comparison
gridExtra::grid.arrange(INDV2, xBar2, nrow=1)
#XmR
INDV2 <- INDV + stat_QC(method="XmR", auto.label = T , show.1n2.sigma = T,
label.digits = 3) +
ggtitle("XmR", subtitle = "label.digits = 3")
#xBar.rBar
xBar2 <- xBar + stat_QC(method="xBar.rBar", auto.label = T, show.1n2.sigma = T,
label.digits = 3) +
ggtitle("xBar.rBar", subtitle = "abel.digits = 3")
#put both plots side by side for comparison
gridExtra::grid.arrange(INDV2, xBar2, nrow=1)
#XmR
INDV2 <- INDV + stat_QC(method="XmR", auto.label = T , show.1n2.sigma = T,
color.qc_center = "purple") +
ggtitle("XmR", subtitle = "color.qc_center = 'purple'")
#xBar.rBar
xBar2 <- xBar + stat_QC(method="xBar.rBar", auto.label = T, show.1n2.sigma = T,
color.qc_center = "purple") +
ggtitle("xBar.rBar", subtitle = "color.qc_center = 'purple'")
#put both plots side by side for comparison
gridExtra::grid.arrange(INDV2, xBar2, nrow=1)
#XmR
INDV2 <- INDV + stat_QC(method="XmR", auto.label = T , show.1n2.sigma = T,
color.qc_center = "purple", color.qc_limits = "darkgreen") +
ggtitle("XmR", subtitle = "color.qc_limits = 'darkgreen'")
#xBar.rBar
xBar2 <- xBar + stat_QC(method="xBar.rBar", auto.label = T, show.1n2.sigma = T,
color.qc_center = "purple", color.qc_limits = "darkgreen") +
ggtitle("xBar.rBar", subtitle = "color.qc_limits = 'darkgreen'")
#put both plots side by side for comparison
gridExtra::grid.arrange(INDV2, xBar2, nrow=1)
#XmR
INDV3 <- ggplot(Process1, aes(x=Process_run_id, y = metric_value)) +
geom_point(color="red") + geom_line(color="orange") +
stat_QC(method="XmR", auto.label = T , show.1n2.sigma = T,
color.qc_center = "purple", color.qc_limits = "darkgreen") +
ggtitle("XmR", "change color in geom_point() and geom_line()") +
ylim(-3,3) +
scale_x_continuous(expand = expand_scale(mult = .15))
#xBar.rBar
xBar3 <- xBar + stat_QC(method="xBar.rBar", auto.label = T, show.1n2.sigma = T,
color.qc_center = "purple", color.qc_limits = "darkgreen",
color.point = "red", color.line = "orange") +
ggtitle("xBar.rBar", subtitle = "use color.point and color.line args in stat_QC()")
#put both plots side by side for comparison
gridExtra::grid.arrange(INDV3, xBar3, nrow=1)