1

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))
Hack-R
  • 22,422
  • 14
  • 75
  • 131
Yang Yang
  • 858
  • 3
  • 26
  • 49

1 Answers1

2

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!

Hack-R
  • 22,422
  • 14
  • 75
  • 131
  • 1
    @ZheyuanLi Maybe you can help me with this one. I found a comment by the author of the package in the source code that says that if you invoke the option `plot.cb` then that *must* be the last thing you do to the plot -- if you add anything else like `axis()` the plot breaks. I'm not sure how to add `plot.cb()` after `axis()`. – Hack-R Jul 09 '16 at 04:48
  • 1
    @ZheyuanLi I think I have an idea. Maybe we can manually add the color bar without using `plot.cb`. Thanks for the background on this. You are probably better with plots than I am, so feel free to add an answer but I will keep hacking on it to see if I can improve my answer. – Hack-R Jul 09 '16 at 04:54
  • 1
    @ZheyuanLi Thanks for your help. I updated it, but I only put in a generic `image.plot` legend without customizing it for his specific case. Hopefully that's good enough; if not I may try to work on it more tomorrow. – Hack-R Jul 09 '16 at 05:11
  • 1
    Thank you so much for your help. I do not know how to check the source code so I do not know that adding a color bar shold be the last thing to do. Thanks a lot. – Yang Yang Jul 10 '16 at 04:19