The colors of the plot elements can be changed by using the col argument. You may use this argument in the according commands, e.g. in the axis command, or you may use it in the plot command and specify the according element.
The following example shows a plot with colors for the lines, points, title, labels and axes.
x <- c(1,2,3,4)
y <- c(9,7,6,8)
plot(x, y, main=’Colors‘, xlab=’x axis‘, ylab = ‚y axis‘, type=’b‘, lwd=2,
col=’red‘, col.main=’darkgreen‘, col.lab=’blue‘, col.axis=’cyan4′)
If you want to set different colors for the lines and points you may use the col argument of the according commands. You have to set the plot type to ’n‘ which does not plot any data and create the lines and points within separated commands.
x <- c(1,2,3,4)
y <- c(9,7,6,8)
plot(x, y, main=’Colors‘, xlab=’x axis‘, ylab = ‚y axis‘, type=’n‘,
col.main=’darkgreen‘, col.lab=’blue‘, col.axis=’cyan4′)
lines(x, y, lwd=2, col=’red‘)
points(x, y, col=’blue‘, pch=15)
You can also generate new colors using the rgb command. The command has three arguments. The arguments define the intensity of red, green and blue. They can vary between 0 and 1.
mygreen <- rgb(.2,.8,.4)
plot(x, y, type=’b‘, lwd=2, col=mygreen)