title: How to color unequal intervals of a plot line using R
body: <p>I would like to color X-axis intervals of a plot line with different colours between these points:</p>
  
  <p>52660, 106784, 151429, 192098, 233666, 273857, 307933, 343048, 373099, 408960, 441545, 472813, 497822, 518561, 537471, 556747, 571683, 591232, 599519, 616567, 625727, 633745</p>
  
  <p>The intervals represent SNP positions along 22 chromosomes.</p>
  
  <p>The problem is that the intervals are unequal (e.g. 52660 - 106784, 106784 - 151429, ... 472813 - 497822, ...). Y-axis values represent ancestry frequencies. X-axis name is SNP_position</p>
  
  <p>The closest I have found is using "ifelse", but for some reason it doesn't work well for me.</p>
  
  <p>For instance, for the first interval (0 - 52660) I included the "col" variable for "plot" and I tried:</p>
  
  <pre><code>col = ifelse(SNP_position &lt; 52660,'blue', 'green')
  </code></pre>
  
  <p>or</p>
  
  <pre><code>col=ifelse(SNP_position &lt; 52660 &amp; SNP_position &gt; 106784,"blue","green")
  </code></pre>
  
  <p>but when I do this the whole line becomes green.</p>
  
  <p>Here is the plot I want to colour <a href="https://i.stack.imgur.com/Z8nBi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z8nBi.png" alt="SNP_position vs ancestry"></a></p>
  
  <p>Any help would be highly appreciated. </p>