time series plot with x axis ticks in month-year format in R

后端 未结 1 970
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 12:46

I am unable to get the x axis to show ticks in format as \'Jan-99\' .....

Ny data is as below:

head(rates,10)
    Month Repo_Rate
1  Apr-01      9.00
2           


        
相关标签:
1条回答
  • 2021-01-23 13:03

    Try

    library(xts)
    
    xt1 <- xts(rates$Repo_Rate, order.by = as.yearmon(rates$Month, '%b-%y'))
    plot(xt1)
    

    Or using zoo

    library(zoo)
    
    z1 <- with(rates, zoo(Repo_Rate, order.by= as.yearmon(Month, '%b-%y')))
    plot(z1, xaxt = 'n')
    tt <- time(z1)[seq(1, length(z1), by = 2)]
    axis(1, tt, format(tt, '%b-%y'), las = 1)
    

    or

    library(zoo)
    library(ggplot2)
    
    fmt <- "%b-%y"
    z <- read.zoo(rates, FUN = as.yearmon, format = fmt)
    autoplot(z) + scale_x_yearmon(format = fmt)
    
    0 讨论(0)
提交回复
热议问题