Data visualization in R: Axis Labels (color, size and rotation)

Remove axis labels and annotations

Sometimes you want to hide an axis or the axis annotations. Maybe you don’t want to show the axis at all or you want to create a customized one and therefore hide the default one.

The following code creates a plot without axes and annotations.

plot(1,2, xaxt=’n‘, yaxt=’n‘, ann=FALSE)

 
Change color and size of axis labels

The following example shows how to change the size and the color of the x-axis labels. At first the plot will be created without the x-axis. Then we add a customized axis with the according style settings.

plot(1,2, xlab = ‚X axis‘, ylab = ‚Y axis‘, xaxt=’n‘)
axis(1, col.axis = ‚Green‘, cex.axis = 1.5)

The value “1” is used to identify the position of the axis. “1” means bottom and “2” means left. The parameter col.axis is used to set the color for the labels and with parameter cex.axis the character expansion factor is defined. A value of “1.5” creates a text which is 50% larger then default.

The above example creates the following plot:

R11_a

 
Rotate axis labels

You can set the orientation of the axis labels by setting the las argument. It supports the following values:

  • 0 : always parallel to the axis (which is the default value)
  • 1 : always horizontal
  • 2 : always perpendicular to the axis
  • 3 : always vertical

 
The following example creates four plots to show all variants of the las argument.

par(mfrow = c(2,2))
plot(1,2, main = ‚parellel (0)‘, xlab = ‚X axis‘, ylab = ‚Y axis‘, las = 0)
plot(1,2, main = ‚horizontal (1)‘, xlab = ‚X axis‘, ylab = ‚Y axis‘, las = 1)
plot(1,2, main = ‚perpendicular (2)‘, xlab = ‚X axis‘, ylab = ‚Y axis‘, las = 2)
plot(1,2, main = ‚vertical (3)‘, xlab = ‚X axis‘, ylab = ‚Y axis‘, las = 3)

R11_b

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 )

Facebook-Foto

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

Verbinde mit %s