How to change the color of line in xyplot in R?


To change the color of line in xyplot, we can use col argument.

For example, if we have two vectors say X and Y and we want to create a red colored xyplot between X and Y then we can use the following command −

xyplot(x~y,type="l", col="red")

Check out the below example to understand how it works.

Example

To change the color of line in xyplot, use the code given below −

set.seed(123)
library(lattice)
xyplot(1:5~rpois(5,5),type="l",col="blue")

Output

If you execute the above given code, it generates the following output −

Updated on: 22-Nov-2021

334 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements