2017-07-13 52 views
0
Month <- as.yearmon("2013-02") + 0:37/12 
plot(Month, H, type = "l", col="blue", ylim=c(5, 7), ylab="") 
lines(Month,Z, type = "l", col = "red", ylim=c(5, 7)) 
legend("topright",legend=c(expression(Forcasted), expression(Acutal), 
    col = c('blue', 'red'), 
    lty = 1:1) 

私のデータは2013年2月から2016年3月までです。2013年2月から2016年3月までの月と年を「x軸」に表示したいだけです。私は複数のことを試みたが、何も働いていなかった。 plot (output of the above code)x軸のラベルをR

+0

推奨答えとして1以下で閉じるようにあなたのコード – RUser

+0

ヘルプの再現性の例を提供する - それはあなたの問題を解決するかどうか – RUser

答えて

1
df = ts(rnorm(50), frequency = 12, start = 2001) 
plot(df, xaxt = "n") 
tsp = attributes(df)$tsp 
dates = seq(as.Date("2015-01-01"), by = "month", along = df) 
axis(1, at = seq(tsp[1], tsp[2], along = df), labels = format(dates, "%m-%Y")) 

または

> df = data.frame(date = seq(as.POSIXct("2014-01-01"), by = "month", length.out = 50), pcp = rnorm(50)) 
    > library(ggplot2) 
    > library(scales) 
    > p = ggplot(data = df, aes(x = date, y = pcp)) + geom_line() 
    > p + scale_x_datetime(labels = date_format("%m-%Y"), breaks = date_breaks("months")) + theme(axis.text.x = element_text(angle = 90)) 
+0

ありがとうございました!それは助けて! –

+0

@AhmadTalafhaあなたの問題を解決した場合は、下記の推奨回答をお手伝いしてください – RUser