【问题标题】:Multiple VSS plots in one window一个窗口中的多个 VSS 图
【发布时间】:2014-01-23 15:25:15
【问题描述】:

我试图在一个窗口中比较多个 VSS 图。但是,par(mfrow=c(x,y) 的常规程序似乎不起作用。 layout(matrix(c(1,2,3,4), 2, 2, byrow = TRUE)) 也没有。我以William Revelle's website 为例。我不得不改变情节命令。它可能在某个阶段从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")) }

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

【问题讨论】:

    标签: r plot statistics psych


    【解决方案1】:

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

    第二个问题是函数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)
    }
    

    【讨论】:

    • 非常令人印象深刻。谢谢。 (我会给 +1,但我没有足够的“声誉”)。
    猜你喜欢
    • 1970-01-01
    • 2011-02-02
    • 1970-01-01
    • 2017-01-29
    • 2012-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多