2017-05-09 2 views
-1

x軸の日付を示すプロット(Base R)を作成したいとします。プロットのあるx軸の日付を設定する

これは、これまでの私のコードです:

plot(dr[[ncol(dr)]][-(length(dr[[ncol(dr)]]))], type = 'l', main = 
paste("Title - ", colnames(dr[ncol(dr)])), xlab = "", ylab = "", 
xaxt = 'n', col = "red", lwd = 2, cex.main = 2, ylim = c(0,0.5)) 
title(xlab = "Period", line=0.5, cex.lab = 1.5) 

私はx軸に日付を入れるにはどうすればよいですか?ここで

はプロットである:

enter image description here

これは私の変数の日付です:あなたはy変数を逃したので

[1] "2008-11-28" "2008-12-31" "2009-01-30" "2009-02-27" "2009-03-31" "2009-04-30" "2009-05-29" "2009-06-30" "2009-07-31" 
[10] "2009-08-31" "2009-09-30" "2009-10-30" "2009-11-30" "2009-12-31" "2010-01-29" "2010-02-26" "2010-03-31" "2010-04-30" 
[19] "2010-05-31" "2010-06-30" "2010-07-30" "2010-08-31" "2010-09-30" "2010-10-29" "2010-11-30" "2010-12-31" "2011-01-31" 
[28] "2011-02-28" "2011-03-31" "2011-04-29" "2011-05-31" "2011-06-30" "2011-07-29" "2011-08-31" "2011-09-30" "2011-10-31" 
[37] "2011-11-30" "2011-12-30" "2012-01-31" "2012-02-29" "2012-03-30" "2012-04-30" "2012-05-31" "2012-06-29" "2012-07-31" 
[46] "2012-08-31" "2012-09-28" "2012-10-31" "2012-11-30" "2012-12-31" "2013-01-31" "2013-02-28" "2013-03-29" "2013-04-30" 
[55] "2013-05-31" "2013-06-28" "2013-07-31" "2013-08-30" "2013-09-30" "2013-10-31" "2013-11-29" "2013-12-31" "2014-01-31" 
[64] "2014-02-28" "2014-03-31" "2014-04-30" "2014-05-30" "2014-06-30" "2014-07-31" "2014-08-29" "2014-09-30" "2014-10-31" 
[73] "2014-11-28" "2014-12-31" "2015-01-30" "2015-02-27" "2015-03-31" "2015-04-30" "2015-05-29" "2015-06-30" "2015-07-31" 
[82] "2015-08-31" "2015-09-30" "2015-10-30" "2015-11-30" "2015-12-31" 
+1

再現性の例を投稿してください。 –

+0

私は自分のコメントを編集しました – Luka

+0

あなたの画像のリンクを修正してください。また、[再現性の高いサンプルを作成する方法](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)を参照してください。 –

答えて

0

私はあなたの変数の日付を使用した例を配置します。

data <- as.Date(data, format= "%Y-%m-%d", tz = "UTC", origin="1970-01-01") 
ats = seq(1, length(runif(length(data))),2) # this is the position 
labs = seq.Date(min(data), max(data), length.out = length(ats)) # these are the labels to plot in the x axis 
plot(runif(length(ats)) ~ ats , type = 'l', main = "Title ", xlab = "", ylab = "", 
    xaxt = 'n', col = "red", lwd = 2, cex.main = 2, ylim = c(0,1)) # note here that the values are randomly generated using `runif`. 
axis(1, at = ats, labels = labs, las= 2) 

出力: enter image description here

データ:

data <- c("2008-11-28", "2008-12-31", "2009-01-30", "2009-02-27", "2009-03-31", "2009-04-30", "2009-05-29", "2009-06-30", "2009-07-31", 
"2009-08-31", "2009-09-30", "2009-10-30", "2009-11-30", "2009-12-31", "2010-01-29", "2010-02-26", "2010-03-31", "2010-04-30", 
"2010-05-31", "2010-06-30", "2010-07-30", "2010-08-31", "2010-09-30", "2010-10-29", "2010-11-30", "2010-12-31", "2011-01-31", 
"2011-02-28", "2011-03-31", "2011-04-29", "2011-05-31", "2011-06-30", "2011-07-29", "2011-08-31", "2011-09-30", "2011-10-31", 
"2011-11-30", "2011-12-30", "2012-01-31", "2012-02-29", "2012-03-30", "2012-04-30", "2012-05-31", "2012-06-29", "2012-07-31", 
"2012-08-31", "2012-09-28", "2012-10-31", "2012-11-30", "2012-12-31", "2013-01-31", "2013-02-28", "2013-03-29", "2013-04-30", 
"2013-05-31", "2013-06-28", "2013-07-31", "2013-08-30", "2013-09-30", "2013-10-31", "2013-11-29", "2013-12-31", "2014-01-31", 
"2014-02-28", "2014-03-31", "2014-04-30", "2014-05-30", "2014-06-30", "2014-07-31", "2014-08-29", "2014-09-30", "2014-10-31", 
"2014-11-28", "2014-12-31", "2015-01-30", "2015-02-27", "2015-03-31", "2015-04-30", "2015-05-29", "2015-06-30", "2015-07-31", 
"2015-08-31", "2015-09-30", "2015-10-30", "2015-11-30", "2015-12-31") 
関連する問題