Plot multiples (time) series in R with legend

后端 未结 4 1743
南旧
南旧 2021-02-06 05:30

\"enter

According to my datas (cf. picture) called GDP. I would like to know how to plot a

4条回答
  •  自闭症患者
    2021-02-06 06:27

    If you use xts to create timeseries data, you can use plot.xts from xtsExtra package to get desired result

    #Uncomment below lines to install required packages
    #install.packages("xts")
    #install.packages("xtsExtra", repos="http://R-Forge.R-project.org")
    
    library(xts)
    library(xtsExtra)
    
    head(data)
    ##              ABC    DEF
    ## 2007-01-03 83.80 467.59
    ## 2007-01-04 85.66 483.26
    ## 2007-01-05 85.05 487.19
    ## 2007-01-08 85.47 483.58
    ## 2007-01-09 92.57 485.50
    ## 2007-01-10 97.00 489.46
    
    
    plot.xts(data, screens = factor(1, 1), auto.legend = TRUE)
    

    You will get something like this enter image description here

    In case you want data in seperate panels:

    plot.xts(data, auto.legend = TRUE)
    

    enter image description here

提交回复
热议问题