Change colors on the chart

Asked

Viewed 60 times

5

Good afternoon. How do I assign different colors to each line and how to red the part of the chart above the top line and below the bottom line?

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')

1 answer

5

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)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.