-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))
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
Shery
  • 1,808
  • 5
  • 27
  • 51
  • 2
    Do not post your data as an image, please learn how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) – Jaap Nov 13 '15 at 10:45
  • 1
    You need to melt your data (use `reshape2`-package for this), and then you can create your plot and facet it by name. [This answer](http://stackoverflow.com/questions/33689150/loop-generate-plots-for-variables-in-a-data-frame) from earlier today might be useful (it shows code to melt and create facets). – Heroka Nov 13 '15 at 11:12

1 Answers1

0

You can use the Hadley Wickham's tidyr package.

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

enter image description here

As you can see, the first argument in gather() function indicates the original data frame. Then you define how you would like to name a column with names of your original variables and then how should be named a column with their values. Finally, you specify which columns you want to reshape. All columns that will not be indicated (in our example: Date and Name) remains as they were in the original data frame.

There is a nice tutorial on tidyr published by Brad Boehmke in case you would need more information.

crocodile
  • 129
  • 4