title: Change line color during a plot
body: <p>This command draws nice green sine waves from a data file, but the col4 value goes negative periodically.</p>
  
  <pre><code>"" u (myDateSP(1,2)):4 lc rgb "green" lt 1 lw 6 sm cspl notitle,\
  </code></pre>
  
  <p>I'd like to have it draw the line red for negative values of col4 and green for positive values and it seems as if I should be able to use the ternary operator for that but I'm having problems with the grammar:</p>
  
  <pre><code>"" u (myDateSP(1,2)):4:($4&lt;= 0) ? lc rgb "red" lt 1 lw 6 sm cspl notitle,\:lc rgb "green" lt 1 lw 6 sm cspl notitle,\
  </code></pre>
  
  <p>and other variants throw errors. Can someone point out where I have this wrong?</p>
  
  <p>Your table example works nicely, many thanks.</p>
  
  <p>I tried to apply it to a data file like this:</p>
  
  <pre><code>2015-01-03 18:02 01  29.49 feet  High Tide  
  2015-01-04 01:12 01  -2.29 feet  Low Tide  
  2015-01-04 07:02 01  29.09 feet  High Tide  
  2015-01-04 13:22 01   4.54 feet  Low Tide  
  2015-01-04 18:41 01  29.80 feet  High Tide  
  2015-01-04 19:54 01   Full Moon  
  2015-01-05 01:52 01  -1.87 feet  Low Tide  
  2015-01-05 07:36 01  29.30 feet  High Tide  
  2015-01-05 14:00 01   4.51 feet  Low Tide  
  2015-01-05 19:17 01  29.99 feet  High Tide  
  2015-01-06 02:26 01  -1.30 feet  Low Tide 
  </code></pre>
  
  <p>and am not having much luck.</p>
  
  <p>Using this:</p>
  
  <pre><code>set linetype 11 linecolor rgb "green"
  set linetype 12 linecolor rgb "red"
  
  set xdata time
  set timefmt '%Y-%m-%d'
  set format x '%s'
  
  set table 'data-smoothed1.txt'
  set samples 1000
  plot 'data.txt' using 1:4 smooth cspline
  unset table
  
  set timefmt '%s'
  set format x '%Y-%m-%d'
  set xzeroaxis
  plot 'data-smoothed.txt' using 1:4:($4 &lt; 0 ? 12 : 11) linecolor variable with lines no title
  </code></pre>
  
  <p>It complains that the xrange is wrong, so when I add an range with the beginning and ending dates, it still doesn't help. The "01" column is the month number.</p>