I'm trying to reshape this ranking data into something more graphical.. perhaps something like: ggplot(party2, aes(x=Preference, y=Ranking, colour=id)+geom_line(). First I have to reshape it though.
Here's the data so far:
> head(party)
  Theme Music/DJ Drink deals People Location
3     3        4           5      1        2
4     2        3           5      1        4
5     5        4           3      1        2
6     4        1           5      2        3
The goal is for the data to look like this:
id Preference     Ranking
1    Theme           3
1    Music/DJ        4
1    Drink deals     5
1    People          1
1    Location        2
2    Theme           2
2    Music/DJ        3
2    Drink deals     5
To reshape the data, I used Hadley's code from this link: How to reshape this dataframe with the reshape package, but I'm still having trouble. I think I'm close.
My code so far is:
party.pref<-c("Theme", "Music/DJ", "Drink deals", "People", "Location")
party<-data[,party.pref]
party<-na.omit(party)
party2<-cbind(party, id=seq(1,nrow(party),1)) # Add IDs column
gp<-melt(party2, id="id", measured=party.pref)
dcast(gp, ... ~party.pref)
And it's coming out like this:
  id    variable   Drink deals Location Music/DJ People Theme
  1       Theme        <NA>     <NA>     <NA>   <NA>     3
  1    Music/DJ        <NA>     <NA>     <NA>   <NA>     4
  1 Drink deals        <NA>     <NA>     <NA>   <NA>     5
  1      People        <NA>     <NA>     <NA>   <NA>     1
  1    Location        <NA>     <NA>     <NA>   <NA>     2
  2       Theme        <NA>     <NA>        2   <NA>  <NA>
So as you can see, if all those factored columns just became "Ranking" and I got rid of all the NAs, I'd have my answer, but I'm not sure how to do that. I think I'm doing something wrong on the "dcast" or the "melt", but I'm not sure which.
Any help is greatly appreciated,thanks!