0

我想绘制以下图中的 4 个作为par(mfrow=c(2,2))类型排列。

install.packages("wavelets")
require(wavelets)
dat <- rnorm(100)
plot.modwt(modwt(dat)) #4 of these in a 2x2 grid is desired

然而,layout基于mfrow的尝试并没有成功。

我会给正确答案一个赏金。

4

1 回答 1

1

正如@plannapus 评论的那样,该函数plot.modwt已经调用了布局。因此,您将需要更改原始功能。

  1. 如果您plot.modwt在 R 控制台中键入,您将获得完整的定义。
  2. 复制此函数并将其另存为新函数,例如my.plot.modwt.
  3. 注释掉这个函数中的布局行
  4. 设置您的新布局。这对我有用:

    nf = layout(matrix(c(3, 1, 4, 2, 7, 5,8, 6), 4, 2, byrow = TRUE), 
         c(2,2), c(2,1, 2, 1), TRUE)
    layout.show(nf)
    
  5. 调用您的函数(4 次)来创建绘图:

    my.plot.modwt(modwt(dat1))
    my.plot.modwt(modwt(dat2))
    my.plot.modwt(modwt(dat3))
    my.plot.modwt(modwt(dat4))
    

请注意,可能需要对布局进行一些其他更改。


我的代码:

y.plot.modwt = function (x, levels = NULL, draw.boundary = FALSE, type = "stack", 
          col.plot = "black", col.boundary = "red", X.xtick.at = NULL, 
          X.ytick.at = NULL, Stack.xtick.at = NULL, Stack.ytick.at = NULL, 
          X.xlab = "t", y.rlabs = TRUE, plot.X = TRUE, plot.W = TRUE, 
          plot.V = TRUE, ...) 
{
  stackplot.modwt <- function(x, w.range, v.range, col.plot, 
                              col.boundary, draw.boundary, X.xtick.at, X.ytick.at, 
                              Stack.xtick.at, Stack.ytick.at, X.xlab = "t", plot.X = TRUE) {
    innerplot <- function(x, y, type = "l", xtick.at, ytick.at) {
      if (is.null(xtick.at) == FALSE || is.null(ytick.at) == 
            FALSE) {
        plot(x, y, type = "l", axes = FALSE, frame.plot = TRUE)
        <snip>

if (plot.X) {
      #nf <- layout(matrix(c(2, 2, 1, 1), 2, 2, byrow = TRUE), 
      #             c(1, 2), c(2, 1), TRUE)
      par(mai = c(0.6, 0.4, 0.1, 0.6))

<snip>
}
于 2013-10-18T11:58:36.673 回答