-1

I am new to R and I am trying to plot multiple CUSUM charts in one display. I have tried par(mfrow=c(2,1)), layout(), cowplot() and it did not work.

The function mentioned does makes the 1st CUSUM chart smaller and be plotted like normal plot(); successfully plotted 1st CUSUM at top half. However, the 2nd CUSUM chart just refreshes the display automatically instead of being plot below the 1st chart in the same display. Any solution or just possible solution is welcomed, many thanks in advance.

To be clear, I am not talking about plotting 'cumsum' data but CUSUM charts with the cusum() function like the following: cusum(data, std.dev = standard_deviation_of_data, center = center, add.stats=FALSE, xlab="Studies", title="CUSUM chart", labels=labels)

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Marco M
  • 1
  • 1

1 Answers1

0

The issue is most likely associated with the fact that a plot of class "cusum.qcc" is generated.

I do not know how to make this work as a base r plot.

I tried various ways to plot in base r including: par(mfrow...), layout(...), and par(... new = TRUE)

Also tried to convert the cusum plot into a grob so as to use gridExtra::grid.arrange()

None of these efforts worked, so resorted to saving the plots as images and combining images


library(qcc)
library(magick)

data

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

save as images

jpeg(file="q1.jpeg")
cusum(diameter[1:25,], decision.interval = 4, se.shift = 1)
dev.off()

jpeg(file="q2.jpeg")
cusum(diameter[1:25,], newdata=diameter[26:40,])
dev.off()

read and combine images

q1 <- image_read("q1.jpeg")
q2 <- image_read("q2.jpeg")

img <- c(q1, q2)

image_append(img)

Created on 2020-07-09 by the reprex package (v0.3.0)

Peter
  • 11,500
  • 5
  • 21
  • 31
  • Hi, thank you for your reply. I fully understood the method you showed me but unfortunately I did not mean plotting 'cumsum' data but CUSUM chart with the cusum() function computed like the following: cusum(data, std.dev = std.dev, center = center, add.stats=FALSE, xlab="Studies", title="CUSUM chart",labels=labels) – Marco M Jul 09 '20 at 12:12
  • Sorry I misread your question. I assume you mean `qcc::cusum`? I've had another go which may or may not be useful. – Peter Jul 09 '20 at 13:19
  • Hi, thanks for getting back to me. Yes, I meant qcc::cusum, sorry, it was my first time posting a question so I may not have made it clear enough as well. Also many thanks for your effort and solution, it was different from what I expected but at least now I have a backup option that works instead of having nothing. – Marco M Jul 10 '20 at 00:18
  • I'm not familiar with package qcc. I'd suggest raising an issue on the github site: https://github.com/luca-scr/qcc/issues or letting the authors be aware of this; there may be a simple solution. – Peter Jul 10 '20 at 06:38