Question

I tried to compare multiple VSS plots in one window. However the usual procedure with par(mfrow=c(x,y) doesn't seem to work. Neither does layout(matrix(c(1,2,3,4), 2, 2, byrow = TRUE)). I took the following example of William Revelle's website. I had to alter the plot command. It may have changed from plotVSS to VSS.plot at some stage, whilst the example has not been update.

require(psych)
meanloading=.7
ncases=400
par(mfrow=c(2,4))

for (i in 1:4) 
{ x=VSS(VSS.simulate(ncases,36,i,meanloading),rotate="none")
VSS.plot(x,paste(i, " factor no rotation")) }

for (i in 1:4) 
{ x=VSS(VSS.simulate(ncases,36,i,meanloading),rotate="varimax")
VSS.plot(x,paste(i, " factor varimax rotation")) }

Any suggestions why I don't get more than one plot in a window?

Was it helpful?

Solution

The function VSS is called without the plot argument. Hence, the default, TRUE, is used. This resets your plot generated with VSS.plot. You have to call VSS with plot = FALSE.

The second problem is the function VSS.plot itself. It calls par and therefore all plots appear at the same location in the plot frame.

When you remove the first and last line from the VSS.plot function, everything will work fine. The code for the modified version, VSS.plot2 can be found at the end of my answer.

require(psych)
meanloading <- .7
ncases <- 400
par(mfrow=c(2,4))

for (i in 1:4) { 
  x <-VSS(VSS.simulate(ncases,36,i,meanloading),rotate="none", plot = FALSE)
  VSS.plot2(x,paste(i, " factor no rotation"))
}

for (i in 1:4) { 
  x <- VSS(VSS.simulate(ncases,36,i,meanloading),rotate="varimax", plot = FALSE)
  VSS.plot2(x,paste(i, " factor varimax rotation")) 
}

enter image description here


The modified version of VSS.plot:

VSS.plot2 <- function (x, title = "Very Simple Structure", line = FALSE) 
{
    #op <- par(no.readonly = TRUE)
    n = dim(x)
    symb = c(49, 50, 51, 52)
    plot(x$cfit.1, ylim = c(0, 1), type = "b", 
         ylab = "Very Simple Structure Fit", 
         xlab = "Number of Factors", pch = 49)
    if (line) 
        lines(x$fit)
    title(main = title)
    x$cfit.2[1] <- NA
    x$cfit.3[1] <- NA
    x$cfit.3[2] <- NA
    x$cfit.4[1] <- NA
    x$cfit.4[2] <- NA
    x$cfit.4[3] <- NA
    lines(x$cfit.2)
    points(x$cfit.2, pch = 50)
    lines(x$cfit.3)
    points(x$cfit.3, pch = symb[3])
    lines(x$cfit.4)
    points(x$cfit.4, pch = symb[4])
    #par(op)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top