1
votes

I have this iris data ...

5.1     3.5     1.4     0.2     Iris-setosa
4.9     3       1.4     0.2     Iris-setosa
7       3.2     4.7     1.4     Iris-versicolor
6.4     3.2     4.5     1.5     Iris-versicolor
7.1     3       5.9     2.1     Iris-virginica
6.3     2.9     5.6     1.8     Iris-virginica
.
.
.

and I got graph using gnuplot (plot 'c:\iris.data')

But I want points with color group by 5th column (iris-setosa, iris-versicolor, iris-virginica)

For example . . .

iris-setosa = color red, iris-versicolor= color green, iris-virginica = color blue

How can I get color graph?

Please answer . . . .

2

2 Answers

1
votes

Replace your colours with numerical indices, e.g., like this:

5.1     3.5     1.4     0.2     0
4.9     3       1.4     0.2     0
7       3.2     4.7     1.4     1
6.4     3.2     4.5     1.5     1
7.1     3       5.9     2.1     2
6.3     2.9     5.6     1.8     2

A simple search-and-replace script should be able to do this for you.

Then you can use Gnuplot’s linecolor palette, e.g. as follows:

plot "iris.data" u 1:2:5 w p lc palette

To adjust the colours used like this:

set palette defined (0 "red", 1 "green", 2 "blue")

Note that while I chose to use the exact indices here, the palette definition is relative and I might as well have used:

set palette defined (-11 "red", -2 "green", 7 "blue")
1
votes

If you want to keep the string values in your data file, you can construct some kind of lookup-table with gnuplot, using the few string functions which gnuplot provides (see also Different coloured bars in gnuplot bar chart? for a similar use case):

IrisColors = 'Iris-setosa Iris-versicolor Iris-virginica'
index(s) = words(substr(IrisColors, 0, strstrt(IrisColors, s)-1)) + 1

set style fill solid noborder
set linetype 1 lc rgb 'red'
set linetype 2 lc rgb 'green'
set linetype 3 lc rgb 'blue'

plot 'iris.data' using 1:2:(index(strcol(5))) linecolor variable

Note, that the string comparison is case-sensitive, and that you cannot use strings with white spaces as single keys.