Plots a line at points specified by inputs x and y, and colored according to factor input z

[p] = c_line(x, y, z, color_vector)% Matlab & Octave
cline(x, y, z, color_vector) #R

Plots a line at points specified by inputs x and y, and colored according to factor input z (with one color for each level of z).

Input var Description Default value
x x positions of points to be plotted N/A
y y positions of points to be plotted N/A
z a factor, the same length as x and y. Line segments in the resulting plot will be colored according to the levels of z. N/A
color_vector a list of colors to use (length should match the number of levels in z). N/A
Output var Description Units
p plot of x and y with the color changes specified by color_vector between levels of z N/A
• This function adds colored line segments to an existing plot.
• The line is plotted at points specified by inputs x and y, and colored according to factor input z (with one color for each level of z).

### Matlab & Octave

c_line(1:5, 1:5, 1:5, {[.1 .2 .3], [.1 .4 .5], [.1 .2 .6] [.1 .8 .9] [.5 .4 .5]})

### R

graphics::plot(NA, xlim = c(0, 30), ylim = c(0, 400))
cline(x=ChickWeight$Time, y=ChickWeight$weight,
z=as.factor(ChickWeight\$Diet),
color_vector=c('black', 'grey20',
'grey50', 'grey70'))