在 R 的 qcc 包中使用 ewma 时隐藏点(控制图)

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

尝试了 q5[4]<-NULL 两次,因为它们保留了我想要删除的点的值,但随后我收到一条错误消息,指出 'x' 和 'y' 长度不同。

我想隐藏下图中的“+”点:

代码如下:

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")

查看 plot.ewma.qcc 的代码,要删除这些点,您必须通过注释行 points(indices, statistics, pch = 3, cex = 0.8) 来破解函数。然后将修改后的函数 source 到您的工作区中。最后,告诉 R 使用您刚刚创建的版本:

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

然后 运行 你的 plot 命令,q5 <- ewma(...) 你需要传递一个明确的 ylim 以及 plot.ewma.qcc 计算一个如果你不这样做,并且它们将这些点的值包括在它们的范围计算中(这会在您的图中留下很多空白)。

如何获取代码副本:转到这样的 CRAN 镜像 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