简体   繁体   中英

Hide Points When Using ewma in the qcc Package in R (Control Charts)

Tried q5[4]<-NULL twice since they hold the values for the points I want to get rid of but then I get an error saying that the 'x' and 'y' lengths differ.

I want to hide the "+" points in the following chart: 在此处输入图片说明

Here's the code:

q5data<-structure(list(x = c(1045L, 1055L, 1037L, 1064L, 1095L, 1008L, 
1050L, 1087L, 1125L, 1146L, 1139L, 1169L, 1151L, 1128L, 1238L, 
1125L, 1163L, 1188L, 1146L, 1167L)), .Names = "x", class = "data.frame",row.names = c(NA, 
-20L))

library(qcc)
qcc.options(bg.margin = "transparent")
q5<-ewma(q5data, center=1050,nsigmas=2.7,lambda=0.1,ylab="Molecular Weight",xlab="Observation",title="EWMA Chart for Molecular Weight")

Looking at the code for plot.ewma.qcc , to remove those points you would have to hack the function by commenting out the line points(indices, statistics, pch = 3, cex = 0.8) . Then source the modified function into your workspace. Finally, tell R to use the version you just created with:

assignInNamespace("plot.ewma.qcc", plot.ewma.qcc, pos = "package:qcc")

and then run your plot command, q5 <- ewma(...) You will need to pass an explicit ylim as well as plot.ewma.qcc computes one if you don't, and they include the value of those points in their range computation (which leaves a lot of whitespace in your plot).

How to get a copy of the code: Go to a CRAN mirror like this one . On the left side, choose "packages", then choose the 2nd link "table of available packages, sorted by name". Scroll down to "qcc" and click on that link. Click the link for "package source", currently "qcc_2.6.tar.gz" and download to your computer. Unpack it, it should give you a folder. Look for the R folder within that folder, then look for ewma.R. Open this in a text editor, search for plot.ewma.qcc You might want to copy this entire function out to a new folder if you will use this regularly. Then edit it as described above. Be sure you get the whole function, all the way to the closing brace. Looks like lines 221 - 353. While that's the process to access code for any package, you can also go directly to the package page like this: http://cloud.r-project.org/package=qcc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM