Plotting multiple time series on the same plot using ggplot()

后端 未结 6 1969
北恋
北恋 2020-12-02 07:09

I am fairly new to R and am attempting to plot two time series lines simultaneously (using different colors, of course) making use of ggplot2.

I have 2 data frames.

6条回答
  •  独厮守ぢ
    2020-12-02 07:42

    I prefer using the ggfortify library. It is a ggplot2 wrapper that recognizes the type of object inside the autoplot function and chooses the best ggplot methods to plot. At least I don't have to remember the syntax of ggplot2.

    library(ggfortify)
    ts1 <- 1:100
    ts2 <- 1:100*0.8
    autoplot(ts( cbind(ts1, ts2)  , start = c(2010,5), frequency = 12 ),
             facets = FALSE)
    

    Plot

提交回复
热议问题