knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "plots/README-" )
Control Charts made easy. ccharter focus on calculating control systems in a series and plotting them as an overlay to it.
You can install from github with:
R
if ( !("devtools" %in% installed.packages()) ) {
install.packages("devtools")
}
devtools::install_github("jbaxx/ccharter")
The ccharter package comes with two main functions:
ccpoints
to calculate Control Systems points from a series data framecc2plot
to plot the Control Systems points (Control Chart)Loading the package
library(ccharter)
Calculating the Control Systems points
ccpoints
:# Create a random time series set.seed(154) time.series <- data.frame(t.dates = seq.Date(as.Date("2014-02-01"), as.Date("2016-08-01"), "month"), t.values = c( seq(0.1, 0.8, by = 0.1) * runif(8) + 3, seq(0.1, 0.7, by = 0.1) * runif(7) + 4, seq(0.1, 0.7, by = 0.1) * runif(7) + 5, seq(0.1, 0.4, by = 0.1) * runif(4) + 4, seq(0.1, 0.5, by = 0.1) * runif(5) + 4) ) # Execute function control.chart.data <- ccpoints(time.series, "t.dates", "t.values")
If we inspect the object we may find it's a list consisting in the following elements:
# Inspecting cchart object content lapply(control.chart.data, head)
To extract the data frame, we can access it from the list in the following way:
control.chart.data[["data"]]
Plotting the Control Systems points
This is how the example series looks like:
g <- ggplot2::ggplot(control.chart.data[["data"]], ggplot2::aes(x = t.dates)) #g <- g + ggplot2::geom_line(ggplot2::aes(y = data.mean), size = 1.2, color = "darkorange") #g <- g + ggplot2::geom_line(ggplot2::aes(y = data.ll), size = 1.2, color = "steelblue") #g <- g + ggplot2::geom_line(ggplot2::aes(y = data.ul), size = 1.2, color = "steelblue") g <- g + ggplot2::geom_line(ggplot2::aes(y = t.values), size=0.7, color = "gray44") g <- g + ggplot2::geom_point(ggplot2::aes(y = t.values), color = "midnightblue") g <- g + ggplot2::theme_bw() g <- g + ggplot2::scale_x_date(labels = scales::date_format("%b/%y"), minor_breaks = NULL, breaks = scales::date_breaks("month")) g <- g + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, hjust = 1)) g <- g + ggplot2::labs(x = "Month") g <- g + ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0)) print(g)
cc2plot
:# Passing the cchart object to the cc2plot function cc2plot(control.chart.data)
For detailed functions documentation you can access the help files in R with ?ccpoints
and ?cc2plot
.
Here you may find a brief guide on how to integrate the package in a KNIME workflow.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.