Add an axis to a plot with R software

The goal of this article is to show you how to add axis to a plot using R software. For this end, we’ll use the R axis() function. A simplified format of this function is :

axis(side, at=NULL, labels=TRUE)

• side : an integer indicating which side of the plot the axis is to be drawn on; Possible values are :
• 1: below
• 2: left
• 3: above
• 4: right
• at: The points at which tick-marks are to be drawn.
• labels: Texts for tick-mark labels. It can also be logical specifying whether annotations are to be made at the tick-marks.

Example :

x<-1:4; y=x*x
# Example 1
plot(x, y, axes = FALSE)
axis(side=1, at = 1:4, labels=LETTERS[1:4])
axis(2)
# Example 2
plot(x, y, axes = FALSE)
axis(side=1, at=1:4, labels=LETTERS[1:4])
axis(2)
box() #- To make it look like "usual" plot  Another example is :

plot(x, y, pch=18, col="red", type="b",
frame=FALSE, xaxt="n") # Remove x axis
axis(1, 1:4, LETTERS[1:4], col.axis="blue")
axis(3, col = "darkgreen", lty = 2, lwd = 0.5)
axis(4, col = "violet", col.axis = "dark violet", lwd = 2) Note that lty and lwd specify line-type and line-width, respectively.

Infos

This analysis has been performed using R statistical software (ver. 3.1.0).