Plot a line chart with conditional colors depending on values

前端 未结 3 1537
-上瘾入骨i
-上瘾入骨i 2020-11-30 08:09

I want to plot a line chart. Depending on values it should change its color. What I found is:

plot(sin(seq(from=1, to=10,by=0.1)),type=\"p\", 
       col=ife         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 08:31

    Here is a little different approach:

    x <- seq(from=1, to=10, by=0.1)
    plot(x,sin(x), col='red', type='l')
    clip(1,10,-1,.5)
    lines(x,sin(x), col='yellow', type='l')
    

    enter image description here

    Note that with this method the curve changes colors at exactly 0.5.

提交回复
热议问题