Data visualization in R: Colors of titles, axes, points and lines

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

R18_a

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)

R18_b

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)

R18_c

Werbung
Dieser Beitrag wurde unter R veröffentlicht. Setze ein Lesezeichen auf den Permalink.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s