Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用ggplot辅助在彼此上方绘制多个时间序列_R_Plot_Ggplot2 - Fatal编程技术网

R 使用ggplot辅助在彼此上方绘制多个时间序列

R 使用ggplot辅助在彼此上方绘制多个时间序列,r,plot,ggplot2,R,Plot,Ggplot2,我有以下资料: Key Date y x1 x2 x3 1 1/10/2018 12:00:00 AM 2 3 2 5 1 1/11/2018 12:00:00 AM 3 5 7 2 1 1/12/2018 12:00:00 AM 5 7 4 7 1 1/13/2018 12:00:00 AM 7 2 7

我有以下资料:

 Key  Date                     y   x1   x2   x3
   1    1/10/2018 12:00:00 AM    2   3    2    5
   1    1/11/2018 12:00:00 AM    3   5    7    2
   1    1/12/2018 12:00:00 AM    5   7    4    7 
   1    1/13/2018 12:00:00 AM    7   2    7    6
   2    1/10/2018 12:00:00 AM    2   6    3    8
   2    1/11/2018 12:00:00 AM    3   7    7    3
   2    1/12/2018 12:00:00 AM    3   2    3    4
   2    1/13/2018 12:00:00 AM    7   6    2    7
我正在尝试使用以下代码:

ggplot(df,aes(date,`x1`,`x2`)) + geom_line() + facet_wrap(~variable, scales = "free_y",ncol=1)
但是我得到了一个错误:

Error in combine_vars(data, params$plot_env, vars, drop = params$drop) : 
  At least one layer must contain all variables used for facetting

非常感谢您提供的任何帮助。

您之所以会出现错误,是因为您没有名为
variable
的变量。我猜您需要使用
tidyr::gather
将数据转换为长格式x1和x2表示什么
aes
通常期望命名参数超过前两个,即假定为x和y值,因此我不确定x2将映射到什么