如何一次绘制多个变量而不需要更长的时间

问题描述 投票:0回答:1

我有一个数据框,其中包含一个时间列和其他列上的 3 个时间序列,是使用

ts()
函数创建的。这是一个例子:

data.frame(time = 1:10, ts1 = rnorm(10), ts2 = rnorm(10,2,50), ts3 = rpois(10, 20)) %>% mutate(across(2:4, ts))

我想制作3个单独的线图,其中x轴上的时间列和y轴上的时间序列,但是

pivot_longer()
似乎不适用于
TS
对象,给出错误:

Error in `pivot_longer()`:
! Can't convert `ts3` <ts> to <double>.

据我所知,这意味着

facet_wrap()
不是一个选项。

我需要将列作为时间序列对象以进行进一步分析,有没有办法在单个函数中制作这些图,或者我是否必须创建 3 个单独的图?

r ggplot2 time-series
1个回答
0
投票

使用

matplot

> matplot(df[-1], type='l')

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.