r
  • date
  • plot
  • axis
  • 2017-05-09 4 views -1 likes 
    -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

    재현 예를 게시하시기 바랍니다. x 축 값이 어떤 구조인지 알지 못한다면 정말 도움이 안됩니다. –

    +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") 
    
    관련 문제