For the first question, you can provide a color vector for the argument col
. In this example I will leave the main line black and the others in gray:
cor = c('black', rep('gray', 4))
For the second question, one option is to work with the function clip()
. It defines a Plot region that will be "plottable":
a <- c(5.8, 9.8, 2.4, 4.4, 4.6, 5.6, 5.6, 7.4, 6.6, 7.6, 7.4, 9.2, 7.4, 4.0, 5.6)
matplot(cbind(a, 6, 6.2, 4, 8), type ='l', col = cor)
# você poderá automatizar essa parte de definir as coordenadas
clip(0, 15, 0, 4)
lines(a, col = 2)
clip(0, 15, 8, 19)
lines(a, col = 2)