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