我想将以下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
的尝试未成功。
我将给予正确答案赏金。
答案 0 :(得分:1)
正如@plannapus评论的那样,函数plot.modwt
已经调用了布局。所以你需要改变原来的功能。
plot.modwt
,您将获得完整的定义。 my.plot.modwt
。 设置新布局。这对我有用:
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)
调用您的函数(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>
}