R中的月份图 - 如何更改默认轴,使其在6月而不是1月开始

时间:2018-06-19 04:32:23

标签: r timeserieschart

沿着R {stats}中的Monthplot的x轴从左到右阅读,我希望第一个月是6月(最后一个月是5月)。该轴默认为1月至12月。我该怎么做才能做出改变?

我的月度生产数据的时间序列中的第一个观察是6月,是相关农业生产年的开始。我已经将数据格式化为ts类的向量,从6月开始。

2 个答案:

答案 0 :(得分:2)

使用 WebElement ele= driver.findElement(By.id("sim-switch")); if(ele.isSelected()==true) { System.out.println("it is clicked"); //append your operations } else { ele.click(); System.out.println("it is now clicked"); //append your operations } 您可以使用ggplot2来调整x(日期)轴的scale_x_date

limits

enter image description here

答案 1 :(得分:0)

我发现答案是在monthplot参数的'phase'参数中。对于月度数据,“阶段”默认为1月-12月的周期。比较下面的默认monthplplot(使用从1949年1月到1960年12月的完整AirPassengers数据集)和紧随其后的1949年6月到1960年5月的11年窗口的monthplot。在第二个月图中,“阶段”由变量“ cycPar”。

###------------------------------------------------------------------------------
### 1. Import data
###------------------------------------------------------------------------------

AirPassengers <- structure(c(112, 118, 132, 129, 121, 135, 148, 148, 136, 119,                         
104, 118, 115, 126, 141, 135, 125, 149, 170, 170, 158, 133, 114,                          
140, 145, 150, 178, 163, 172, 178, 199, 199, 184, 162, 146, 166,                            
171, 180, 193, 181, 183, 218, 230, 242, 209, 191, 172, 194, 196,                            
196, 236, 235, 229, 243, 264, 272, 237, 211, 180, 201, 204, 188,                             
235, 227, 234, 264, 302, 293, 259, 229, 203, 229, 242, 233, 267,                             
269, 270, 315, 364, 347, 312, 274, 237, 278, 284, 277, 317, 313,                             
318, 374, 413, 405, 355, 306, 271, 306, 315, 301, 356, 348, 355,                             
422, 465, 467, 404, 347, 305, 336, 340, 318, 362, 348, 363, 435,                            
491, 505, 404, 359, 310, 337, 360, 342, 406, 396, 420, 472, 548,                            
559, 463, 407, 362, 405, 417, 391, 419, 461, 472, 535, 622, 606,                            
508, 461, 390, 432), .Tsp = c(1949, 1960.91666666667, 12), class = "ts")


###------------------------------------------------------------------------------
### 2. Plot the data using default monthplot - Jan-Dec cycle
###------------------------------------------------------------------------------

monthplot(AirPassengers, main = "Monthly International Air Passenger Numbers",
      xlab = "Monthly Pax Numbers Jan '49 - Dec '60",
      ylab = "")


###------------------------------------------------------------------------------
### 3. Extract the window from June 1949 to May 1960 and plot on a Jun-May cycle
###------------------------------------------------------------------------------

junMayYears <- window(AirPassengers, start = c(1949, 6), end = c(1960, 5), frequency 
= 12)
cycPar <- ts(rep(c("Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb",    
"Mar", "Apr", "May"), 11), start = c(1949, 6), frequency = 12)
monthplot(junMayYears, 
      phase = cycPar,
      main = "Monthly International Air Passenger Numbers",
      xlab = "Monthly Pax Numbers Jun '49 - May '60",
      ylab = "")


###------------------------------------------------------------------------------
### END
###------------------------------------------------------------------------------