Wavelets plot: changing x-, y- axis, and color plot

寵の児 提交于 2020-01-17 13:15:11

问题


I have a code that I am working on for hourly dataset and want to display a proper wavelet plot but I am having trouble adjusting it to my liking. I want to change the x-, y- axis and put up a color bar. I have successfully changed the x-axis, however, that is only when color bar is not activated. If it is, then I cannot change the x-axis. In addition, I haven't found a successful way to change the y-axis to have more values in between then what is automatically generated. Thank you in advance for your help

    library(biwavelet) # used for wavelets

    n <- 141696
    d <- data.frame(1:n, round(runif(n, 38, 100),2))

    # X-Axis for plotting
    TIME1 <- as.POSIXlt("2000-01-01 00:00:00 PST", format = '%Y-%m-%d %H:%M:%S')
    TIME2 <- as.POSIXlt("2016-02-29 23:00:00 PST", format = '%Y-%m-%d %H:%M:%S')
    LABELS <- seq(from = TIME1, to = TIME2, by = "3 months")
    xAxis <- seq(from = TIME1, to = TIME2, by = "hour")
    Location <-NA
    for (i in 1:length(LABELS)) { Location[i] <- which(LABELS[i] == xAxis) }
    LABELS <- format(LABELS, "%b %Y")

    # Wavelet
    WAV <- wt(d)

This has the correct x-axis but does not display the color bar since I did not put plot.cb = TRUE in the plot as an argument.

    # PLOT (Has no legend but correct x-axis)
    par(oma=c(0, 0, 0, 1), mar=c(5, 4, 4, 5) + 0.1)
    plot(WAV, type="power.corr.norm", main="Bias-corrected wavelet power ", ylab="Period(hourly)", xlab="Time", lwd.sig=1, xaxt='n')
    axis(side = 1, at = Location, labels = LABELS, tick = TRUE, las = 2)

No Color Bar, correct x-axis

This displays the color bar but does not have the proper x-axis labeled.

    # PLOT (Has legend but no x-axis)
    par(oma=c(0, 0, 0, 1), mar=c(5, 4, 4, 5) + 0.1)
    plot(WAV, type="power.corr.norm", main="Bias-corrected wavelet power ", ylab="Period(hourly)", xlab="Time", lwd.sig=1, xaxt='n', plot.cb=TRUE)
    axis(side = 1, at = Location, labels = LABELS, tick = TRUE, las = 2)

No x-axis, but color bar present


回答1:


Get into the function itself by typing plot.biwavelet, copy it to your script editor and edit the function, give it a new name such as myplot, edit it then run myplot instead of plot.biwavelet. You can change whatever you want within the plot.biwavelet function. For example, to increase the number of xlim labels, just do: locs <- pretty(range(xlim), n = 10). Currently, n=5.



来源:https://stackoverflow.com/questions/37305790/wavelets-plot-changing-x-y-axis-and-color-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!