0

我正在使用biwavelet包进行小波分析。但是,当我想使用 调整轴cex.axis的标签大小时,标签大小不会改变。另一方面,cex.labcex.main​​且运作良好。这是一个错误吗?下面给出了一个可重现的例子。

library(biwavelet)
t1 <- cbind(1:100, rnorm(100))
t2 <- cbind(1:100, rnorm(100))
# Continuous wavelet transform
wt.t1 <- wt(t1)
par(oma = c(0, 0.5, 0, 0), mar = c(4, 2, 2, 4))
plot(wt.t1,plot.cb = T,plot.phase = T,type = 'power.norm',
 xlab = 'Time(year)',ylab = 'Period(year)',mgp=c(2,1,0),
 main='Winter station 1',cex.main=0.8,cex.lab=0.8,cex.axis=0.8)

编辑

一个月前在这个网站上有一个问题:Wavelets plot: changed x-, y-axis, and color plot,但没有解决。这次有救吗?谢谢!

4

2 回答 2

4

是的,这是一个错误。这是修补版本:my.plot.biwavelet()

此版本接受参数cex.axis(默认为 1),您可以在需要时更改它。我将在最后的“解释”部分向您简要解释问题所在。

my.plot.biwavelet <- function (x, ncol = 64, fill.cols = NULL, xlab = "Time", ylab = "Period", 
    tol = 1, plot.cb = FALSE, plot.phase = FALSE, type = "power.corr.norm", 
    plot.coi = TRUE, lwd.coi = 1, col.coi = "white", lty.coi = 1, 
    alpha.coi = 0.5, plot.sig = TRUE, lwd.sig = 4, col.sig = "black", 
    lty.sig = 1, bw = FALSE, legend.loc = NULL, legend.horiz = FALSE, 
    arrow.len = min(par()$pin[2]/30, par()$pin[1]/40), arrow.lwd = arrow.len * 
        0.3, arrow.cutoff = 0.9, arrow.col = "black", xlim = NULL, 
    ylim = NULL, zlim = NULL, xaxt = "s", yaxt = "s", form = "%Y", cex.axis = 1,
    ...)  {
         if (is.null(fill.cols)) {
             if (bw) {
                fill.cols <- c("black", "white")
            }
            else {
                fill.cols <- c("#00007F", "blue", "#007FFF", 
                  "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", 
                  "#7F0000")
            }
        }
        col.pal <- colorRampPalette(fill.cols)
        fill.colors <- col.pal(ncol)
        types <- c("power.corr.norm", "power.corr", "power.norm", 
            "power", "wavelet", "phase")
        type <- match.arg(tolower(type), types)
        if (type == "power.corr" | type == "power.corr.norm") {
            if (x$type == "wtc" | x$type == "xwt") {
                x$power <- x$power.corr
                x$wave <- x$wave.corr
            }
            else {
                x$power <- x$power.corr
            }
        }
         if (type == "power.norm" | type == "power.corr.norm") {
            if (x$type == "xwt") {
                zvals <- log2(x$power)/(x$d1.sigma * x$d2.sigma)
                if (is.null(zlim)) {
                   zlim <- range(c(-1, 1) * max(zvals))
                }
                zvals[zvals < zlim[1]] <- zlim[1]
                locs <- pretty(range(zlim), n = 5)
                leg.lab <- 2^locs
            }
            else if (x$type == "wtc" | x$type == "pwtc") {
                zvals <- x$rsq
                zvals[!is.finite(zvals)] <- NA
                if (is.null(zlim)) {
                  zlim <- range(zvals, na.rm = TRUE)
                }
                zvals[zvals < zlim[1]] <- zlim[1]
                locs <- pretty(range(zlim), n = 5)
                leg.lab <- locs
            }
            else {
                zvals <- log2(abs(x$power/x$sigma2))
                if (is.null(zlim)) {
                  zlim <- range(c(-1, 1) * max(zvals))
                }
                zvals[zvals < zlim[1]] <- zlim[1]
                locs <- pretty(range(zlim), n = 5)
                leg.lab <- 2^locs
            }
        }
        else if (type == "power" | type == "power.corr") {
            zvals <- log2(x$power)
            if (is.null(zlim)) {
                zlim <- range(c(-1, 1) * max(zvals))
            }
            zvals[zvals < zlim[1]] <- zlim[1]
            locs <- pretty(range(zlim), n = 5)
            leg.lab <- 2^locs
        }
        else if (type == "wavelet") {
            zvals <- (Re(x$wave))
            if (is.null(zlim)) {
                zlim <- range(zvals)
            }
            locs <- pretty(range(zlim), n = 5)
            leg.lab <- locs
        }
        else if (type == "phase") {
            zvals <- x$phase
            if (is.null(zlim)) {
                zlim <- c(-pi, pi)
            }
            locs <- pretty(range(zlim), n = 5)
            leg.lab <- locs
        }
        if (is.null(xlim)) {
            xlim <- range(x$t)
        }
        yvals <- log2(x$period)
        if (is.null(ylim)) {
            ylim <- range(yvals)
        }
        else {
             ylim <- log2(ylim)
        }
        image(x$t, yvals, t(zvals), zlim = zlim, xlim = xlim, 
             ylim = rev(ylim), xlab = xlab, ylab = ylab, yaxt = "n", 
             xaxt = "n", col = fill.colors, ...)
        box()
         if (class(x$xaxis)[1] == "Date" | class(x$xaxis)[1] == 
              "POSIXct") {
             if (xaxt != "n") {
                  xlocs <- pretty(x$t) + 1
                 axis(side = 1, at = xlocs, labels = format(x$xaxis[xlocs], 
                   form))
             }
          }
         else {
              if (xaxt != "n") {
                xlocs <- axTicks(1)
                axis(side = 1, at = xlocs, cex.axis = cex.axis)
             }
        }
        if (yaxt != "n") {
            axis.locs <- axTicks(2)
            yticklab <- format(2^axis.locs, dig = 1)
            axis(2, at = axis.locs, labels = yticklab, cex.axis = cex.axis)
         }
         if (plot.coi) {
             polygon(x = c(x$t, rev(x$t)), lty = lty.coi, lwd = lwd.coi, 
                  y = c(log2(x$coi), rep(max(log2(x$coi), na.rm = TRUE), 
                  length(x$coi))), col = adjustcolor(col.coi, 
                  alpha.f = alpha.coi), border = col.coi)
         }
         if (plot.sig & length(x$signif) > 1) {
             if (x$type %in% c("wt", "xwt")) {
                 contour(x$t, yvals, t(x$signif), level = tol, 
                  col = col.sig, lwd = lwd.sig, add = TRUE, drawlabels = FALSE)
              }
             else {
                 tmp <- x$rsq/x$signif
                 contour(x$t, yvals, t(tmp), level = tol, col = col.sig, 
                   lwd = lwd.sig, add = TRUE, drawlabels = FALSE)
             }
         }
         if (plot.phase) {
             a <- x$phase
             locs.phases <- which(zvals < quantile(zvals, arrow.cutoff))
             a[locs.phases] <- NA
              phase.plot(x$t, log2(x$period), a, arrow.len = arrow.len, 
                 arrow.lwd = arrow.lwd, arrow.col = arrow.col)
         }
          box()
          if (plot.cb) {
              fields::image.plot(x$t, yvals, t(zvals), zlim = zlim, ylim = rev(range(yvals)), 
                  xlab = xlab, ylab = ylab, col = fill.colors, 
                 smallplot = legend.loc, horizontal = legend.horiz, 
                legend.only = TRUE, axis.args = list(at = locs, 
                    labels = format(leg.lab, dig = 2)), xpd = NA)
        }
    }

测试

library(biwavelet)
t1 <- cbind(1:100, rnorm(100))
t2 <- cbind(1:100, rnorm(100))
# Continuous wavelet transform
wt.t1 <- wt(t1)
par(oma = c(0, 0.5, 0, 0), mar = c(4, 2, 2, 4))
my.plot.biwavelet(wt.t1,plot.cb = T,plot.phase = T,type = 'power.norm',
   xlab = 'Time(year)',ylab = 'Period(year)',mgp=c(2,1,0),
   main='Winter station 1',cex.main=0.8,cex.lab=0.8,cex.axis=0.8)

正如预期的那样,它正在工作。

好的


解释

plot.biwavelet(),为什么cex.axis通过...不工作?

plot.biwavelet()主要分三个阶段生成您的最终情节:

  1. image(..., xaxt = "n", yaxt = "n")用于生成基本情节;
  2. axis(1, at = atTicks(1)); axis(2, at = atTicks(2))用于添加轴;
  3. fields::image.plot() 用于显示颜色图例条。

现在,虽然这个函数需要...,但它们只被提供给第一个image()调用,而后面的axis(), (包括polygon(), contour(), phase.plot()并且image.plot()不从.... 稍后调用axis()时,不支持关于轴控制的灵活规范。

我猜在包开发期间,问题描述为:将“...”参数的参数传递给 R 中的正确函数。也许作者没有意识到这个潜在的问题,在这里留下了一个错误。我对那篇文章的回答以及 Roland 的评论都指向了一个强有力的解决方案。

我不是包作者,所以无法决定他将如何解决这个问题。我的修复是残酷的,但可以满足您的临时需求:只需添加cex.axis参数即可axis()调用。我已经通过电子邮件联系了 Tarik(包作者),我相信他会给你一个更好的解释和解决方案。

于 2016-06-25T04:47:33.607 回答
1

我通过将...参数传递给axisin解决了这个问题plot.biwavelet。您的代码现在应该可以正常工作了。请注意,更改cex.axis和其他axis参数将影响所有三个轴(x、y、z)。

biwavelet您可以通过在控制台发出以下命令从 GitHub下载新版本 (0.20.8) R(假设您devtools已经安装了该软件包):devtools::install_github("tgouhier/biwavelet")

感谢指出错误!

于 2016-06-25T18:56:58.513 回答