Using geom_line with multiple groupings

前端 未结 2 909
既然无缘
既然无缘 2021-02-01 17:42

I have a table as follows:

> testsizes
    size value replicate lane
361   16  6898         1   L1
362   17 10707         1   L1
363   18  1786         1   L1         


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 18:40

    As @joran pointed out, if ggplot could do this itself it would simply be concatenating the two groups anyway. So concatenating the two groups myself is the right way to go and gives me the desired result:

    > testlengths$replane <- paste(testlengths$replicate, testlengths$lane, sep="_")
    
    > testlengths
        size value replicate lane replane
    361   16  6898         1   L1    1_L1
    362   17 10707         1   L1    1_L1
    363   18  1786         1   L1    1_L1
    364   19  1721         1   L1    1_L1
    365   20  2454         1   L1    1_L1
    421   16  8486         2   L1    2_L1
    422   17 26691         2   L1    2_L1
    423   18  3241         2   L1    2_L1
    424   19  5068         2   L1    2_L1
    425   20  7579         2   L1    2_L1
    481   16  4152         3   L1    3_L1
    482   17  4452         3   L1    3_L1
    483   18   899         3   L1    3_L1
    484   19  1973         3   L1    3_L1
    485   20  2595         3   L1    3_L1
    571   16  8284         1   L2    1_L2
    572   17  9045         1   L2    1_L2
    573   18  5041         1   L2    1_L2
    574   19  7160         1   L2    1_L2
    575   20  9730         1   L2    1_L2
    631   16  5639         2   L2    2_L2
    632   17  9773         2   L2    2_L2
    633   18  2433         2   L2    2_L2
    634   19  3017         2   L2    2_L2
    635   20  3864         2   L2    2_L2
    691   16 10161         3   L2    3_L2
    692   17 18609         3   L2    3_L2
    693   18  3760         3   L2    3_L2
    694   19  3543         3   L2    3_L2
    695   20  4257         3   L2    3_L2
    
    > ggplot(testlengths, aes(size, value, group=replane, colour=lane)) 
        + geom_line()
    

    enter image description here

    I guess the moral here is to do as much preprocessing of your table as you can before giving it to ggplot.

提交回复
热议问题