-1

I have the following dataset:

  Name TOR_A Success_rate_A Realizable_Prod_A Assist_Rate_A Task_Count_A       Date
1 BVG1  2.00             85              4.20          0.44          458 31/01/2014
2 BVG2  3.99             90              3.98          0.51          191 31/01/2014
3 BVG3  4.00             81              8.95          0.35         1260 31/01/2014
4 BVG4  3.50             82              2.44          4.92         6994 31/01/2014
5 BVG1  2.75             85              4.00          2.77         7954 07/02/2014
6 BVG2  4.00             91              3.50          1.50          757 07/02/2014
7 BVG3  3.80             82              7.00          1.67         7898 07/02/2014
8 BVG4  3.60             83              3.50          4.87         7000 07/02/2014

I wish to plot a ggplot line graph with Date on x-axis and TOR_A, Success_rate_A etc. on y-axis. I would also like to see it by the Name column. How can I prepare this dataset to achieve this objective?

I tried reshape in R but couldn't make it work.

UPDATE

Done it using reshape2::recast method as show below:

data_weekly = recast(data_frame_to_be_reshaped,variable+Name~Date,id.var=c(Name,Date))
4

1 回答 1

0

您可以使用 Hadley Wickham 的 tidyr 包。

df_reshaped <- gather(df_original, key = Variable, Value, Tor_A:Success_rate)

在此处输入图像描述

如您所见,gather() 函数中的第一个参数表示原始数据帧。然后你定义你想如何用你的原始变量的名称来命名一个列,然后应该如何用它们的值来命名一个列。最后,您指定要重塑的列。所有未指示的列(在我们的示例中:日期和名称)都保持在原始数据框中的状态。

如果您需要更多信息,B​​rad Boehmke 发布了一个很好的关于 tidyr 的教程。

于 2015-11-13T20:54:11.527 回答