stat_QC_cap_vlabels: Vertical Label Capability Stat

Description Usage Arguments Value Examples

View source: R/04_stat_qc_capability.R

Description

Draws Vertical Lables on Vertical Capability lines

Usage

1
2
stat_QC_cap_vlabels(LSL, USL, method = "xBar.rBar", show = c("LSL",
  "USL"), mapping = NULL, data = NULL, inherit.aes = TRUE, ...)

Arguments

LSL

numeric, Customer's lower specification limit

USL

numeric, Customer's Upper specification limit

method

string, calling the following methods:

  • Individuals Charts: XmR,

  • Studentized Charts: xBar.rBar, xBar.rMedian, xBar.sBar, xMedian.rBar, xMedian.rMedian

show

vector, indicating which lines to draw ie., c("LCL", "LSL", "X", "USL", "UCL")

  • LCL: Lower Control Limit

  • LSL: Lower Specification Limit

  • X: Process Center

  • USL: Upper Specification Limit

  • UCL: Upper Control Limit

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

...

Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red" or size = 3. They may also be parameters to the paired geom/stat.

Value

vertical lines for histogram and density plots.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Load Libraries ----------------------------------------------------------
require(ggQC)
require(ggplot2)


# Setup Data --------------------------------------------------------------
set.seed(5555)
Process1 <- data.frame(ProcessID = as.factor(rep(1,100)),
                       Value = rnorm(100,10,1),
                       Subgroup = rep(1:20, each=5),
                       Process_run_id = 1:100)
set.seed(5556)
Process2 <- data.frame(ProcessID = as.factor(rep(2,100)),
                       Value = rnorm(100,20, 1),
                       Subgroup = rep(1:10, each=10),
                       Process_run_id = 101:200)

df <- rbind(Process1, Process2)

######################
## Example 1 XmR    ##
######################
##You may need to use the r-studio Zoom for these plots or make the size of the
##stat_QC_cap_summary smaller with size = some number"

method <- "XmR"

# Normal Histogram XmR --------------------------------------------------------

EX1.1 <-  ggplot(df[df$ProcessID == 1,], aes(x=Value, QC.Subgroup=Subgroup)) +
  geom_histogram(binwidth = 1, color="purple") +
  geom_hline(yintercept=0, color="grey") +
  stat_QC_cap_vlines(LSL = 5, USL = 15, show=c("X", "LSL", "USL"), method=method) +
  stat_QC_cap_vlabels(LSL = 5, USL = 15, show=c("X", "LSL", "USL"), method=method) +
  stat_QC_cap_summary(LSL = 5, USL = 15, method=method,
                      #show="ALL",
                      #show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk",
                      #       "LCL", "X", "UCL", "Sig"),
                      #show=c("Sig","TOL", "DNS"),
                      show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk"),
                      color="black", digits=2, size=4) +
  scale_x_continuous(expand =  expand_scale(mult = c(0.15,.8))) +
  ylim(0,45)
#Ex1.1

# Facet Histogram XmR -----------------------------------------------------

EX1.2 <- ggplot(df[order(df$Process_run_id),],
                aes(x=Value, QC.Subgroup=Subgroup, color=ProcessID)) +
  geom_histogram(binwidth = 1) +
  geom_hline(yintercept=0, color="grey") +
  stat_QC_cap_vlines(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_vlabels(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_summary(LSL = 5, USL = 15, method=method,
                      #show="ALL",
                      #show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk",
                      #       "LCL", "X", "UCL", "Sig"),#show=c("Sig","TOL", "DNS"),
                      show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk"),
                      color="black", digits=4, size=4) +
  scale_x_continuous(expand =  ggplot2::expand_scale(mult = c(0.15,.8))) +
  facet_grid(.~ProcessID) + ylim(0,45)
#EX1.2

# Facet Density Plot XmR -------------------------------------------------

EX1.3 <- ggplot(df[df$ProcessID == 1,], aes(x=Value, QC.Subgroup=Subgroup)) +
  geom_density(bw = .4, fill="purple", trim=TRUE) +
  geom_hline(yintercept=0, color="grey") +
  stat_QC_cap_vlines(LSL = 5, USL = 15, show=c("X", "LSL", "USL"), method=method) +
  stat_QC_cap_vlabels(LSL = 5, USL = 15, show=c("X", "LSL", "USL"), method=method) +
  stat_QC_cap_summary(LSL = 5, USL = 15, method=method,
                      #show="ALL",
                      #show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk",
                      #       "LCL", "X", "UCL", "Sig"),
                      #show=c("Sig","TOL", "DNS"),
                      show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk"),
                      color="black", digits=2, size=4) +

  scale_x_continuous(expand =  expand_scale(mult = c(0.15,.8)))  + ylim(0,.5)
#EX1.3

# Facet Density Plot XmR --------------------------------------------------

EX1.4 <- ggplot(df[order(df$Process_run_id),],
                aes(x=Value, QC.Subgroup=Subgroup, color=ProcessID)) +
  geom_density(bw = .4, fill="grey", trim=TRUE ) +
  stat_QC_cap_vlines(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_vlabels(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_summary(LSL = 5, USL = 15, method=method, #py=.3,
                      #show="ALL",
                      #show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk",
                      #       "LCL", "X", "UCL", "Sig"),
                      #show=c("Sig","TOL", "DNS"),
                      show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk"),
                      color="black", digits=4, size=4) +
  scale_x_continuous(expand =  ggplot2::expand_scale(mult = c(0.15,.8))) +
  # geom_hline(yintercept=0, color="black") +
  facet_grid(.~ProcessID) + ylim(0,.5)
#EX1.4


########################################
##  Example 2: xBar.rBar or xBar.sBar ##
########################################

method <- "xBar.rBar" #Alternativly Use "xBar.sBar" if desired


# Single Histogram xBar.rBar ----------------------------------------------

EX2.1 <- ggplot(df[df$ProcessID==1,], aes(x=Value, QC.Subgroup=Subgroup)) +
  geom_histogram(binwidth = 1) +
  stat_QC_cap_vlines(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_vlabels(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_summary(LSL = 5, USL = 15, method=method, #py=.3,
                      #show="ALL",
                      #show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk",
                      #       "LCL", "X", "UCL", "Sig"),
                      #show=c("Sig","TOL", "DNS"),
                      show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk"),
                      color="black", digits=4, size=4) +
  scale_x_continuous(expand =  ggplot2::expand_scale(mult = c(0.15,.8))) #+
#EX2.1


# Faceted Histogram xBar.rBar ---------------------------------------------

EX2.2 <- ggplot(df, aes(x=Value, QC.Subgroup=Subgroup)) +
  geom_histogram(binwidth = 1) +
  stat_QC_cap_vlines(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_vlabels(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_summary(LSL = 5, USL = 15, method=method, #py=.3,
                      #show="ALL",
                      #show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk",
                      #       "LCL", "X", "UCL", "Sig"),
                      #show=c("Sig","TOL", "DNS"),
                      show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk"),
                      color="black", digits=4, size=4) +
  scale_x_continuous(expand =  ggplot2::expand_scale(mult = c(0.15,.8)))+
  facet_grid(.~ProcessID, scales="free_x")
#EX2.2

# Single Density xBar.rBar ----------------------------------------------

EX2.3 <- ggplot(df[df$ProcessID==1,], aes(x=Value, QC.Subgroup=Subgroup)) +
  geom_density(bw = .4, fill="grey", alpha=.4) +
  stat_QC_cap_vlines(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_vlabels(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_summary(LSL = 5, USL = 15, method=method, #py=.3,
                      #show="ALL",
                      #show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk",
                      #       "LCL", "X", "UCL", "Sig"),
                      #show=c("Sig","TOL", "DNS"),
                      show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk"),
                      color="black", digits=4, size=4) +
  scale_x_continuous(expand =  ggplot2::expand_scale(mult = c(0.15,.8))) #+
#EX2.3

# Faceted Density xBar.rBar ---------------------------------------------

EX2.4 <-  ggplot(df, aes(x=Value, QC.Subgroup=Subgroup)) +
  geom_density(bw = .4, fill="grey", alpha=.4) +
  stat_QC_cap_vlines(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_vlabels(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_summary(LSL = 5, USL = 15, method=method, #py=.3,
                      #show="ALL",
                      #show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk",
                      #       "LCL", "X", "UCL", "Sig"),
                      #show=c("Sig","TOL", "DNS"),
                      show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk"),
                      color="black", digits=4, size=4) +
  scale_x_continuous(expand =  ggplot2::expand_scale(mult = c(0.15,.8)))+
  facet_grid(.~ProcessID, scales="free_x")
#EX2.4


###############################
##  Example 3: xBar.rMedian  ##
###############################

## Plots involving medians should give warning: "median based QC methods represent
## at best *potential* process capability"

##These plot work the same as in examples 2.X; below is an example.

method <- "xBar.rMedian"
EX3.1 <- ggplot(df[order(df$Process_run_id),], aes(x=Value, QC.Subgroup=Run)) +
  geom_histogram(binwidth = 1) +
  stat_QC_cap_vlines(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_vlabels(LSL = 5, USL = 15, method=method) +
  stat_QC_cap_summary(LSL = 5, USL = 15, method=method, #py=.3,
                      #show="ALL",
                      #show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk",
                      #       "LCL", "X", "UCL", "Sig"),
                      #show=c("Sig","TOL", "DNS"),
                      show=c("TOL","DNS", "Cp", "Cpk", "Pp", "Ppk"),
                      color="black", digits=4, size=4) +
  scale_x_continuous(expand =  ggplot2::expand_scale(mult = c(0.15,.8)))
#EX3.1

kenithgrey/rQC documentation built on May 20, 2019, 9:04 a.m.