I can create quality control charts with the qicharts2 package.
library(tidyverse) library(qicharts2) (plot1 <- qic(age, data = tail(cabg, 100), chart = 'i', ylab = 'Years', xlab = 'Patient #' ) ) p1 <- plot1$data Then I can customize the charts.
(plot2 <- ggplot(p1, aes(x, y)) + geom_ribbon(ymin = p1$lcl, ymax = p1$ucl, fill = "black", alpha = 0.05) + geom_line(color = "black", size = 1) + geom_line(aes(x, cl)) + geom_point(color = "black" , fill = "black", size = 2) + geom_point(data = p1 %>% filter(sigma.signal == TRUE), color = "red", size = 2) + ggtitle(label = NULL) + labs(x = NULL, y = NULL) + scale_y_continuous(breaks = seq(0, 100, by = 10)) + coord_cartesian(ylim = c(0, 100)) + theme_bw() + theme( text = element_text(size = 18), axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 0.6), axis.text.y = NULL, panel.grid.major = element_blank(), panel.grid.minor = element_blank(), strip.text.x = element_text(size = 14, color = "black", angle = 0)) ) Using the part argument, in my qichart, causes it to split at the specified part point(s).
(plot3 <- qic(age, data = tail(cabg, 100), chart = 'i', part = c(70, 85), ylab = 'Years', xlab = 'Patient #' ) ) p3 <- plot3$data What do I need to add to my customized ggplot2 syntax, below, to get it to part in the same manner? What I've got does everything, EXCEPT, it doesn't part like in the syntax directly above.
(plot4 <- ggplot(p3, aes(x, y)) + geom_ribbon(ymin = p3$lcl, ymax = p3$ucl, fill = "black", alpha = 0.05) + geom_line(color = "black", size = 1) + geom_line(aes(x, cl)) + geom_point(color = "black" , fill = "black", size = 2) + geom_point(data = p3 %>% filter(sigma.signal == TRUE), color = "red", size = 2) + ggtitle(label = NULL) + labs(x = NULL, y = NULL) + scale_y_continuous(breaks = seq(0, 100, by = 10)) + coord_cartesian(ylim = c(0, 100)) + theme_bw() + theme( text = element_text(size = 18), axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 0.6), axis.text.y = NULL, panel.grid.major = element_blank(), panel.grid.minor = element_blank(), strip.text.x = element_text(size = 14, color = "black", angle = 0)) ) 