0

I'm trying to use ddply in a data frame (created using melt) as the following:

head(MoP_top50_ftrt_htmp_melt)
                                                                     Taxon variable     value
1                                  K03406; methyl-accepting chemotaxis protein     Coal 0.2748281
2                          K02014; iron complex outermembrane recepter protein     Coal 0.2676633
3 K03296; hydrophobic/amphiphilic exporter-1 (mainly G- bacteria), HAE1 family     Coal 0.2516787
4                         K06147; ATP-binding cassette, subfamily B, bacterial     Coal 0.2592270
5                                                         K00936; [EC:2.7.3.-]     Coal 0.2278227
6                                        K08300; ribonuclease E [EC:3.1.26.12]     Coal 0.2528503

And I'm trying to get it ready to ggplot2 with proportions included.

For that I'm using:

require(plyr)
MoP_top50_ftrt_htmp_melt <- ddply(MoP_top50_ftrt_htmp_melt, .(sample), transform, value=(value/sum(value))*100)

But getting this error:

Error in unique.default(x) : unique() applies only to vectors

Does this have to do with the semicolons and spaces in the Taxon column?

aosmith
  • 34,856
  • 9
  • 84
  • 118
André Soares
  • 309
  • 1
  • 13
  • 1
    Does the same thing happen with other datasets or is it just this one? [One related question](http://stackoverflow.com/questions/28588548/r-error-in-unique-defaultx-unique-applies-only-to-vectors-when-using-ddply) seemed to be related to the OS. You could always switch to using functions from, e.g., dplyr if you can't get plyr to work. – aosmith Oct 04 '16 at 20:22
  • Yeah, I'm using Ubuntu, think that can be a problem? How do I 'translate' this to dplyr? – André Soares Oct 04 '16 at 21:19
  • Using `dat` in place of your long dataset name, the dplyr equivalent would be `dat %>% group_by(sample) %>% mutate(value = 100*value/sum(value))` – aosmith Oct 04 '16 at 21:35
  • @aosmith Now trying to plot this in ggplot2 as such: `ggplot(MoP_top50_ftrt_htmp_melt, aes(x=variable, y=Taxon, fill=value)) + geom_tile(aes(fill=value))` But order is not maintained after melting. Any ideas on how to reorder? No idea on how to reorder a melted table. – André Soares Oct 05 '16 at 10:14
  • Best ask a new question specific to this. Or search SO, often you have to set levels of factor to get desired order. – aosmith Oct 05 '16 at 14:21

0 Answers0