简体   繁体   中英

R: Plotting multiple qcc::cusum charts in one display

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)

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)

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