title: Can gnuplot split data?
body: <p>I have some data in the following format:</p>
  
  <pre><code>10.0 1 a 2
  10.2 2 b 2
  10.4 3 a 2
  10.6 4 b 2
  10.8 4 c 10
  11.0 4 c 20
  </code></pre>
  
  <p>... where the third column basically indicates belonging to a 'separate' dataset; and so I would like to show, say, those samples belonging to 'a' in red, those belonging to 'b' in blue etc (using <code>gnuplot</code> Version 4.4 patchlevel 2).</p>
  
  <p>I managed to somehow get the 'sample' style as a mix between '<code>impulses</code>' and '<code>point</code>' styles; and via <a href="https://stackoverflow.com/questions/2075283/choosing-line-type-and-color-in-gnuplot-4-0">Choosing line type and color in Gnuplot 4.0</a>, managed to employ individual colors - this is how far I got (<a href="http://sdaaubckp.svn.sourceforge.net/viewvc/sdaaubckp/single-scripts/basictest.gnuplot" rel="nofollow noreferrer">basictest.gnuplot</a>): </p>
  
  <pre><code>#!/usr/bin/env gnuplot
  
  print "Generating data..."
  
  # to specify data inline in script:
  # only system can work, as it is quoted;
  # but still have to escape newlines!
  
  system "cat &gt; ./inline.dat &lt;&lt;EOF\n\
  10.0 1 a 2\n\
  10.2 2 b 2\n\
  10.4 3 a 2\n\
  10.6 4 b 2\n\
  10.8 4 c 10\n\
  11.0 4 c 20\n\
  EOF\n"
  
  print "done generating."
  
  
  # set ranges
  set yrange [0:30]
  set xrange [0:4]
  
  # define line styles - can call them up later
  set style line 1 linetype 1 linewidth 3 pointtype 3 linecolor rgb "red"
  set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "green"
  set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
  
  
  # offset the X axis: instead of 1:2, use: ($1-10):2
  # to "mix", use "" for last datset - but must also repeat the "using"!
  # ... and plot:
  
  plot 'inline.dat' using ($1-10):2 with impulses linestyle 1,\
       "" using ($1-10):2 notitle with points linestyle 1,\
       "" using ($1-10):2 notitle with lines linestyle 2,\
       'inline.dat' using ($1-10):4 with impulses linestyle 3,\
       "" using ($1-10):4 notitle with points linestyle 3
  
  # below just for saving file
  #set terminal png
  #set output 'basictest.png'
  #replot
  </code></pre>
  
  <p>... which looks like this: </p>
  
  <p><img src="https://i.stack.imgur.com/CReLr.png" alt="basictest.png"></p>
  
  <p>In other words, instead of the above - say for ($1-10):2, I'd like to see the 1<sup>st</sup> and 3<sup>rd</sup> sample ('a') in blue, 2<sup>nd</sup> and 4<sup>th</sup> sample ('b') in red, and the last two ('c') in green (<em>I left the green line there just to see the effect of the style mixing</em>).  </p>
  
  <p>I'm aware that this could be achieved by writing a script, that will parse the original data, and generate three tables out of that, as in:</p>
  
  <pre><code>10.0 1 a 2
  10.4 3 a 2
  ---
  10.2 2 b 2
  10.6 4 b 2
  ---
  10.8 4 c 10
  11.0 4 c 20
  </code></pre>
  
  <p>... which could then be plotted 'separately' - but I was wandering if <code>gnuplot</code> maybe had some internal facility for something like that? </p>
  
  <p>Thanks in advance for any answers,<br>
  Cheers!</p>
  
  <p>&nbsp; </p>
  
  <p>PS: Some useful links for me: </p>
  
  <ul>
  <li><a href="http://t16web.lanl.gov/Kawano/gnuplot/intro/style-e.html" rel="nofollow noreferrer">gnuplot / intro / style Introduction to gnuplot --- Plot Style</a></li>
  <li><a href="http://t16web.lanl.gov/Kawano/gnuplot/intro/plotexp-e.html" rel="nofollow noreferrer">gnuplot / intro / plotexp (E) Introduction to gnuplot --- Experimental Dat</a></li>
  <li><a href="http://www.gnuplot.info/docs_4.0/gnuplot.html" rel="nofollow noreferrer">Gnuplot: An Interactive Plotting Program</a></li>
  <li><a href="http://gnuplot-tricks.blogspot.com/2010/01/further-new-features-in-gnuplot-44.html" rel="nofollow noreferrer">Gnuplot tricks: Further new features in gnuplot 4.4</a></li>
  </ul>
  
  <p>&nbsp; </p>
  
  <p>EDIT: just wanted to post a <a href="http://sdaaubckp.svn.sourceforge.net/viewvc/sdaaubckp/single-scripts/basic-labels.gnuplot" rel="nofollow noreferrer">link to a script</a> with which I'm getting close to visualizing the data the way I wanted to: </p>
  
  <p><img src="https://i.stack.imgur.com/pmex8.png" alt="basic-labels.png"> </p>
  
  <p>I'm kinda wanting to treat the labels (with the added 'points' as rectagle backgrounds) as <em>nodes</em> in <a href="http://www.netscrap.com/greacen/?post=1196" rel="nofollow noreferrer">graphviz</a> or in <a href="http://www.texample.net/tikz/examples/simple-flow-chart/" rel="nofollow noreferrer">TikZ</a>, and set up those nice connection lines between them - but even this already helps me much :) Note that this is the <code>wxt</code> output - other terminals like <code>png</code> or <code>pdfcairo</code> will have a completely messed up rendering of boxes/labels (and would need to be tuned by hand). </p>