# ColorFunction or PlotStyle Based on List

I am plotting the values of a continuous, but complicated function `Energy[x_]` via `ListLinePlot`. Another function `SpinVal[x_]` also gives me values between `-1` and `+1`.

I want the `ListLinePlot` curve of `Energy[x_]` to become blue when `SpinVal[x_]` returns `-1`, red when it returns `+1` and respective colours between blue and red for any values between `-1` and `+1`.

For `ListPlot` the following does the job (with example functions in the P.S.):

``values = {#, Energy[#]} & /@xRange; spins = SpinVal/@xRange;  ListPlot[{#} & /@values, PlotStyle -> Hue /@ (0.7 + 0.3/2*(1 + spins))] ``

(The `(0.7 + 0.3/2*(1 + [...])`-part is necessary for my choice of colours, since `0.7` is blue and `1` is red.)

This method, however, does not work for `ListLinePlot`, as it separates the points (see the (`{#} & /@values`)-part inside the plot function). I have made several attempts, e.g. something like what is recommended here, but since I want my function to be applicable to more plots than just this one, and since I have a terribly large amount of data points, I feel the need of an easier solution.

Ultimately, an elegant way to generate a legend would also be good. However, this legend can be generated easily by hand if no such elegant method exists.

P.S.

My code example above becomes quite illustrative if one just assumes a sine function for both `Energy[x_]` and `SpinVal[x_]`:

``xRange = Range[-4, 4, 0.1]; values = {#, Sin[#]} & /@ xRange; spins = Sin /@ xRange;  ListLinePlot[{#} & /@ values, PlotStyle -> Hue /@ (0.7 + 0.3/2*(1 + spins))] ``

It then looks like the following:

Of course, my actual problem does not have its colour grading matching the actual behaviour of the curve.