I have four very simple example vectors:
a<-c(1,3,5,7,9)
b<-c(1,2,3,4,5)
c<-c(1,1.8,2.6,3.4,4.2)
d<-c(1,1.5,2,2.5,3)
I have plotted the vector a and added the rest of the vectors in with lines()
, like so
plot(a,type="l")
lines(b,type="l")
lines(c,type="l")
lines(d,type="l")
Now I have this basic graph
I wish to alter the coloring of the lines by implementing a color gradient, let's say from light pink to dark red.
I have a matrix with the same samples that were plotted, but with values independent from the plot.
Sample Value
a 634
b 473
c 573
d 124
So my question is: How do I add a color gradient in to the plot so that the value of the sample dictates the hue of the color so that the higher value in the matrix value-column colors the line of the respective sample in a more darker red?
My elementary proficiency in R has led me to a point where I have the plot depicted in the image but I lack the know-how required to get started on the code that would produce the color gradient.
Gradient of n colors ranging from color 1 and color 2 I found this to be of some help, but I don't really know how to apply this knowledge in a way my question dictates.
All help is much appreciated. Thank you in advance.
-Olli J