2017-04-14 38 views
0

我有數據是每月,但它顯示爲兩年的時間間隔。我希望這個按月顯示。 Plot shown, see x axsis更改X axsis比例在R

我使用繪圖和GGfortify 2 ggplot使用下面的代碼:

library(ggplot2) 
library(ggfortify) 
spendingARIMA <- arima(spendingSaas, order = c(2, 1, 0)) 
fianlforecastSpending <- forecast(spendingARIMA, h= 6, level = 30) 
autoplot(fianlforecastSpending) 

回答

0

像這樣的東西應該工作

dates <- seq(as.POSIXct("2016-1-1"), as.POSIXct("2018-1-1"), by="month") # make dates 
df <- data.frame(dates = dates, value = rnorm(25)) # make data frame 

ggplot(df, aes(x = dates, y=value)) + 
    geom_point() + 
    scale_x_datetime(date_breaks = "month") + #This is the key line 
    theme(axis.text.x=element_text(angle = -90, hjust = 1, vjust=.3)) #rotate x-axis 90 deg.