Do I need to reshape this wide data to effectively use ggplot2?

后端 未结 2 1099
不知归路
不知归路 2020-12-19 02:32

I have a data.frame that looks like

  Year Crustaceans       Cod       Tuna    Herring Scorpion.fishes
1 1950    58578630   2716706   69690537   87161396             


        
相关标签:
2条回答
  • 2020-12-19 02:41

    A simple transformation using melt (from the reshape/2 package) would suffice. I would do

    library(reshape2)
    qplot(Year, value, colour = variable, data = melt(df, 'Year'), geom = 'line')
    
    0 讨论(0)
  • 2020-12-19 02:55

    I found the following link to be extremely helpful to learning reshape. Reshape and plyr are very easy to use functions once you have the format (not necessarily the fastest (data.table package is written using some C so it's much faster) of how they work down. This tutorial pdf is a great resource for learning it. Also I suggest copying the line from example(cast) into a script and running them one at a time to see the result.

    http://had.co.nz/stat405/lectures/19-tables.pdf

    0 讨论(0)
提交回复
热议问题