简体   繁体   English

多重控制图 EWMA RStudio

[英]Multiple control chart EWMA RStudio

I am trying plot multiples control chart type EWMA in just a plot in software RStudio, using the function par, but, there aren't output error and the each controlchart is plotted in the same local graph, not in the different position. I am trying plot multiples control chart type EWMA in just a plot in software RStudio, using the function par, but, there aren't output error and the each controlchart is plotted in the same local graph, not in the different position.

par(mfrow=c(2,2),new=TRUE) q2 <- ewma(x2,center = 0, lambda=0.4,std.dev=0.57, nsigmas=3,add.stats='False') par(new=TRUE) q3 <- ewma(x3,center = 0, lambda=0.4,std.dev=0.57, nsigmas=3,add.stats='False') #par(new=TRUE) q4 <- ewma(x4,center = 0, lambda=0.4,std.dev=0.57, nsigmas=3,add.stats='False') #par(new=TRUE) q5 <- ewma(x5,center = 0, lambda=0.4,std.dev=0.57, nsigmas=3,add.stats='False')

I would like to plot four control chart in this plot, but, actually, each control chart is insert in the same position:我想在这个 plot 中插入 plot 四个控制图,但实际上,每个控制图都插入同一个 position 中:

在此处输入图像描述

On further inspection, the problem is caused by the plot.ewma.qcc function from the qcc package not returning a grob.进一步检查,问题是由于来自plot.ewma.qcc package 的qcc function 未返回 grob 引起的。 So we need to convert these objects to grobs first.所以我们需要先将这些对象转换为 grobs。 cowplot gives us a way to do this: cowplot为我们提供了一种方法:

library(qcc)
library(gridExtra)
library(cowplot)

data(pistonrings)
attach(pistonrings)
diameter <- qcc.groups(diameter, sample)

q2 <-
  ~ ewma(
    diameter[1:25, ],
    center = 0,
    lambda = 0.4,
    std.dev = 0.57,
    nsigmas = 3,
    add.stats = FALSE
  ) 

q3 <-
  ~ ewma(
    diameter[15:40, ],
    center = 0,
    lambda = 0.4,
    std.dev = 0.57,
    nsigmas = 3,
    add.stats = 'False'
  ) 

plot_list <- list(p1 = as_grob(q2), p2 = as_grob(q3))
do.call("grid.arrange", c(plot_list, ncol = 2))

Note the tilde ~ formula operator in front of the calls to the ewma function calls.注意ewma function 调用前面的波浪号~公式运算符。 This is how cowplot wants it.这就是cowplot想要的方式。 We then call the cowplot::as_grob function when we compile the plots into a list.然后,当我们将绘图编译成列表时,我们调用cowplot::as_grob function。 do.call and grid.arrange do the rest. do.callgrid.arrange执行 rest。 Which generates this plot:生成此 plot:

在此处输入图像描述

Note: I am not very familiar with cowplot so it escaped me that this package has a method for grid plotting:注意:我对cowplot不是很熟悉,所以这个 package 有一种网格绘图方法让我不以为然:

plot_grid(q2, q3, labels = c('A', 'B'), label_size = 12)

Which would give you the same results as above.这会给你与上面相同的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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