Search code examples
rplotaxis-labelsbiwavelet

biwavelet package: "axis" is not working


I am using biwavelet package to conduct wavelet coherence analysis. When I want to set my own x ticklabel, I find axisis not working. The following gives a reproducible example. Thanks.

require(biwavelet)
t1 <- cbind(1:100, rnorm(100))
t2 <- cbind(1:100, rnorm(100))
wtc.t1t2 <- wtc(t1,t2,nrands = 10) 
plot(wtc.t1t2, plot.cb = TRUE, plot.phase = TRUE,xaxt='n')
axis(1,at = seq(10,100,10),labels = seq(1,10,1))

Solution

  • The thing that was breaking your plot was plot.cb = TRUE.

    In the source code for plot.biwavelet the author notes the following about the plot.cb option:

    ## Add color bar: this must happen after everything, otherwise chaos ensues!

    So that was the problem -- you invoked axis() after plot.cb and chaos ensued. However, you can manually add back the color bar using image.plot from the fields package, after having run plot without plot.cb then having added your axis().

    pacman::p_load(biwavelet,fields)
    t1 <- cbind(1:100, rnorm(100))
    t2 <- cbind(1:100, rnorm(100))
    wtc.t1t2 <- wtc(t1,t2,nrands = 10) 
    plot(wtc.t1t2, plot.phase = TRUE,xaxt='n')
    axis(1,at = seq(10,100,10),labels = seq(1,20,2))
    image.plot( zlim=c(0,25), legend.only=TRUE)
    

    enter image description here

    You can customize the ticks and the color bar to your liking this way!