Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 修复plot(fevd())函数的布局/打印选项_R_Variables_Plot - Fatal编程技术网

R 修复plot(fevd())函数的布局/打印选项

R 修复plot(fevd())函数的布局/打印选项,r,variables,plot,R,Variables,Plot,我目前正忙于使用vars包在R中进行向量自回归分析。我想知道以下事情是否可能: 1) 以前的解决方案可以更好地适应页面,但是现在有了更多的变量,我们有了更多的绘图,布局又被扭曲了。我已经使用了一些win.graph()参数,但没有提供一个合适的可读性解决方案 2) vars包的plot(irf(…)函数提供了每页一个图形的输出。我想知道plot(fevd()函数是否也可以通过添加一些额外的(我不知道)参数选项来实现这一点 3) 另外,为了可读性,我想给图表上色,plot(fevd()提供各种灰色

我目前正忙于使用vars包在R中进行向量自回归分析。我想知道以下事情是否可能:

1) 以前的解决方案可以更好地适应页面,但是现在有了更多的变量,我们有了更多的绘图,布局又被扭曲了。我已经使用了一些win.graph()参数,但没有提供一个合适的可读性解决方案

2) vars包的plot(irf(…)函数提供了每页一个图形的输出。我想知道plot(fevd()函数是否也可以通过添加一些额外的(我不知道)参数选项来实现这一点

3) 另外,为了可读性,我想给图表上色,plot(fevd()提供各种灰色输出,可以改变这些颜色吗

先谢谢你


Olivier

您必须修改fevd的plot函数才能执行您想要的操作。这里有一个修改后的
plot.varfevd
函数,它删除对
par()
的所有调用。这允许正确使用
布局
。已删除的行已被注释掉(#)。我还删除了在“单个”绘图中要求确认的参数

plot.varfevd  <-function (x, plot.type = c("multiple", "single"), names = NULL,
    main = NULL, col = NULL, ylim = NULL, ylab = NULL, xlab = NULL,
    legend = NULL, names.arg = NULL, nc, mar = par("mar"), oma = par("oma"),
    addbars = 1, ...)
{
    K <- length(x)
    ynames <- names(x)
    plot.type <- match.arg(plot.type)
    if (is.null(names)) {
        names <- ynames
    }
    else {
        names <- as.character(names)
        if (!(all(names %in% ynames))) {
            warning("\nInvalid variable name(s) supplied, using first variable.\n")
            names <- ynames[1]
        }
    }
    nv <- length(names)
#    op <- par(no.readonly = TRUE)
    ifelse(is.null(main), main <- paste("FEVD for", names), main <- rep(main,
        nv)[1:nv])
    ifelse(is.null(col), col <- gray.colors(K), col <- rep(col,
        K)[1:K])
    ifelse(is.null(ylab), ylab <- rep("Percentage", nv), ylab <- rep(ylab,
        nv)[1:nv])
    ifelse(is.null(xlab), xlab <- rep("Horizon", nv), xlab <- rep(xlab,
        nv)[1:nv])
    ifelse(is.null(ylim), ylim <- c(0, 1), ylim <- ylim)
    ifelse(is.null(legend), legend <- ynames, legend <- legend)
    if (is.null(names.arg))
        names.arg <- c(paste(1:nrow(x[[1]])), rep(NA, addbars))
    plotfevd <- function(x, main, col, ylab, xlab, names.arg,
        ylim, ...) {
        addbars <- as.integer(addbars)
        if (addbars > 0) {
            hmat <- matrix(0, nrow = K, ncol = addbars)
            xvalue <- cbind(t(x), hmat)
            barplot(xvalue, main = main, col = col, ylab = ylab,
                xlab = xlab, names.arg = names.arg, ylim = ylim,
                legend.text = legend, ...)
            abline(h = 0)
        }
        else {
            xvalue <- t(x)
            barplot(xvalue, main = main, col = col, ylab = ylab,
                xlab = xlab, names.arg = names.arg, ylim = ylim,
                ...)
            abline(h = 0)
        }
    }
    if (plot.type == "single") {
#        par(mar = mar, oma = oma)
#        if (nv > 1)
#            par(ask = TRUE)
        for (i in 1:nv) {
            plotfevd(x = x[[names[i]]], main = main[i], col = col,
                ylab = ylab[i], xlab = xlab[i], names.arg = names.arg,
                ylim = ylim, ...)
        }
    }
    else if (plot.type == "multiple") {
        if (missing(nc)) {
            nc <- ifelse(nv > 4, 2, 1)
        }
        nr <- ceiling(nv/nc)
        par(mfcol = c(nr, nc), mar = mar, oma = oma)
        for (i in 1:nv) {
            plotfevd(x = x[[names[i]]], main = main[i], col = col,
                ylab = ylab[i], xlab = xlab[i], names.arg = names.arg,
                ylim = ylim, ...)
        }
    }
#    on.exit(par(op))
}
library(vars)
data(Canada)
colnames(Canada) <-c("name1","name2","name3","name4")
var <- VAR(Canada , p=4 , type = "both")
win.graph(width=15,height=8)
layout(matrix(1:8,ncol=2))
plot.varfevd(fevd(var, n.ahead = 10 ),plot.type = "single", col=1:4)
plot.varfevd(fevd(var, n.ahead = 10 ),plot.type = "single", col=1:4)