0

我试图在一个窗口中比较多个 VSS 图。但是,通常的程序par(mfrow=c(x,y)似乎不起作用。也没有layout(matrix(c(1,2,3,4), 2, 2, byrow = TRUE))我以William Revelle 的网站为例。我不得不改变情节命令。它可能在某个阶段从plotVSS变为VSS.plot,而示例尚未更新。

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

有什么建议为什么我在一个窗口中没有得到多个情节?

4

1 回答 1

0

该函数VSS在没有plot参数的情况下被调用。因此,使用默认值 , TRUE。这将重置您生成的绘图VSS.plot。你必须打电话VSSplot = FALSE

第二个问题是函数VSS.plot本身。它调用par,因此所有图都出现在图框中的同一位置。

当您从函数中删除第一行和最后一行时VSS.plot,一切都会正常工作。修改版本的代码,VSS.plot2可以在我的答案末尾找到。

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

在此处输入图像描述


修改后的版本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)
}
于 2014-01-23T15:54:30.017 回答