How to plot multiple lines in R

前端 未结 2 1526
夕颜
夕颜 2021-01-11 15:59

I have a data that looks like this:

#d  TRUE    FALSE   Cutoff
4   28198   0   0.1
4   28198   0   0.2
4   28198   0   0.3
4   28198   13  0.4
4   28251   61         


        
2条回答
  •  死守一世寂寞
    2021-01-11 16:24

    Here's a base R method, assuming your data is called dat in this example:

    plot(1:max(dat$false), xlim = c(0,611),ylim =c(19000,28251), type="n")
    
    apply(
    rbind(unique(dat$d),1:2),
    #the 1:2 here are your chosen colours
    2,
    function(x) lines(dat$false[dat$d==x[1]],dat$true[dat$d==x[1]],col=x[2])
    )
    

    Result:

    enter image description here

    edit - while using lowercase true/false for variable names is accepted, it probably still isn't the greatest coding practice.

提交回复
热议问题